• Resolved Ewout

    (@pomegranate)


    I’m using the eShop session data in my plugin, to read the total value of the cart (stored in $_SESSION['final_price']). It looks like it doesn’t update properly though, because right after I add a product to my cart, the total is just the sum of the single product price of all the products in the cart.

    So if I add
    Product X, 3x €10
    Product Y, 2x €10

    it displays a total of €20, right after I’ve added the product (i.e. when I’m redirected to the cart page). Then, when I browse on, the session final_price value gets the correct value (€50). I’ve worked around that now by manually looping through the cart contents (also stored in the session data), but of course it would be easier to just read the final_price value.

    http://wordpress.org/extend/plugins/eshop/

Viewing 11 replies - 1 through 11 (of 11 total)
  • I’m not sure that you’re asking for. Please understand that we cannot provide free support for eShop hacks. Nor can we help you troubleshoot your hacks. We simply don’t have the time. The plugin is free but we have to spend most of our time trying to earn a living.

    If you are a coder, all we can suggest is that you refer to the code & its comments.

    Thread Starter Ewout

    (@pomegranate)

    I’m not asking for support, at all! Just a heads up for this bug… Thinking my contribution to improving this free plugin would be appreciated. I’m not hacking anything but creating a plugin that makes use of the eShop cart data.

    I’m not convinced that this is a bug.

    What exactly is it that you are trying to do with this new plugin?

    Thread Starter Ewout

    (@pomegranate)

    Expected scenario would be:

    1. Add Product X (€10) to the cart, $_SESSION[‘final_price’] = 10
    2. Add Product X (€10) again, $_SESSION[‘final_price’] = 20
    2a. browse further, $_SESSION[‘final_price’] = 20
    3. Add Product X (€10) again, $_SESSION[‘final_price’] = 30
    3a. browse further, $_SESSION[‘final_price’] = 30
    4. Add Product Y (€10) again, $_SESSION[‘final_price’] = 40
    4a. browse further, $_SESSION[‘final_price’] = 40
    5. Add Product Y (€10) again, $_SESSION[‘final_price’] = 50
    5a. browse further, $_SESSION[‘final_price’] = 50

    currently the following happens (on multiple installs without any previous session issues):

    1. Add Product X (€10) to the cart, $_SESSION[‘final_price’] = 10
    2. Add Product X (€10) again, $_SESSION[‘final_price’] = 10
    2a. browse further, $_SESSION[‘final_price’] = 20
    3. Add Product X (€10) again, $_SESSION[‘final_price’] = 10
    3a. browse further, $_SESSION[‘final_price’] = 30
    4. Add Product Y (€10) again, $_SESSION[‘final_price’] = 20
    4a. browse further, $_SESSION[‘final_price’] = 40
    5. Add Product Y (€10) again, $_SESSION[‘final_price’] = 20
    5a. browse further, $_SESSION[‘final_price’] = 50

    as you can see it’s not that the session is not working, it’s just not multplying the quantities. We are extending the functionality of this plugin to eshop: http://wordpress.org/extend/plugins/woocommerce-menu-bar-cart/

    You still haven’t told me what you are trying to do with the new plugin.

    Thread Starter Ewout

    (@pomegranate)

    (it’s in the last line) We are displaying the contents of the cart in a menu.

    Thread Starter Ewout

    (@pomegranate)

    Thanks! As I said, we have a working solution. I was just pointing out a bug.

    if(isset($_SESSION['eshopcart'.$blog_id])) {
    	$eshopsize=sizeof($_SESSION['eshopcart'.$blog_id]);
    		foreach($_SESSION['eshopcart'.$blog_id] as $eshopdo=>$eshopwop){
    			$eshopqty+=$eshopwop['qty'];
    
    	}
    }
    if(isset($_SESSION['final_price'.$blog_id]) && isset($_SESSION['eshopcart'.$blog_id])) {
    	//should be working but there seems to be an eShop bug in storing the final_price value (doesn't multiply with quantity)
    	//$thetotal=$_SESSION['final_price'.$blog_id];
    	$eshopcart = $_SESSION['eshopcart'.$blog_id];
    	foreach ($eshopcart as $eshopcart_item) {
    		$thetotal += $eshopcart_item['qty'] * $eshopcart_item['price'];
    	}
    
    	$eshoptotal=sprintf( __('%1$s%2$s','eshop'), $currsymbol, number_format_i18n($thetotal,__('2','eshop')));
    }

    It’s not a bug. eShop, by design, doesn’t store the totals in the session. It calculates the total value in its code.

    Thread Starter Ewout

    (@pomegranate)

    ah sorry, I must have misunderstood the function of $_SESSION['final_price'].
    It does contain a value that is the same as the total price. The only moment it doesn’t correspond is the first page after the a product is added to the cart. Browsing further, it always corresponds to the cart totals.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘PHP session data bug’ is closed to new replies.