Title: PHP session data bug
Last modified: August 21, 2016

---

# PHP session data bug

 *  Resolved [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/)
 * 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/](http://wordpress.org/extend/plugins/eshop/)

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703352)
 * 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](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703356)
 * 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.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703357)
 * I’m not convinced that this is a bug.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703359)
 * What exactly is it that you are trying to do with this new plugin?
 *  Thread Starter [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703360)
 * 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/](http://wordpress.org/extend/plugins/woocommerce-menu-bar-cart/)
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703362)
 * You still haven’t told me what you are trying to do with the new plugin.
 *  Thread Starter [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703363)
 * (it’s in the last line) We are displaying the contents of the cart in a menu.
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703367)
 * Have you reviewed [http://quirm.net/wiki/eshop/additional-plugins-and-code-snippets/display-cart-item-count/](http://quirm.net/wiki/eshop/additional-plugins-and-code-snippets/display-cart-item-count/)
 *  Thread Starter [Ewout](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703370)
 * 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')));
       }
       ```
   
 *  [esmi](https://wordpress.org/support/users/esmi/)
 * (@esmi)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703374)
 * 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](https://wordpress.org/support/users/pomegranate/)
 * (@pomegranate)
 * [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703376)
 * 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.

 * ![](https://s.w.org/plugins/geopattern-icon/eshop_d6e4b8.svg)
 * [eShop](https://wordpress.org/plugins/eshop/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/eshop/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/eshop/)
 * [Active Topics](https://wordpress.org/support/plugin/eshop/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/eshop/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/eshop/reviews/)

 * 11 replies
 * 2 participants
 * Last reply from: [Ewout](https://wordpress.org/support/users/pomegranate/)
 * Last activity: [13 years, 1 month ago](https://wordpress.org/support/topic/php-session-data-bug/#post-3703376)
 * Status: resolved