WordPress.org

Ready to get started?Download WordPress

Forums

eShop
[resolved] PHP session data bug (12 posts)

  1. Ewout
    Member
    Posted 1 year ago #

    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/

  2. esmi
    Forum Moderator
    Posted 1 year ago #

    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.

  3. Ewout
    Member
    Posted 1 year ago #

    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.

  4. esmi
    Forum Moderator
    Posted 1 year ago #

    I'm not convinced that this is a bug.

  5. esmi
    Forum Moderator
    Posted 1 year ago #

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

  6. Ewout
    Member
    Posted 1 year ago #

    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/

  7. esmi
    Forum Moderator
    Posted 1 year ago #

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

  8. Ewout
    Member
    Posted 1 year ago #

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

  9. esmi
    Forum Moderator
    Posted 1 year ago #

  10. Ewout
    Member
    Posted 1 year ago #

    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')));
    }
  11. esmi
    Forum Moderator
    Posted 1 year ago #

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

  12. Ewout
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.