Results 1 to 6 of 6

Thread: Right way to get nr of products in cart

  1. #1
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Right way to get nr of products in cart

    Inside a custom navigation module I'm hiding the cart and checkout pages as long as the cart is empty. I'm having two questions about that:

    1. This is the code I'm using to detect the number of products, inside a template file. Is this the best way to do this?
      Code:
      $this->import('Isotope');
      	if (count($this->Isotope->Cart->getProducts()))
      	{
      		$carthasproducts = 1;
      	}
      [/*:m:3o2youjt]
    2. Every so many minutes I reload the page manually (because I was writing the CSS) and when I have been away for a short time and reloaded twice, the cart is empty. this may very well be because of my custom code. Any idea why this is happening?[/*:m:3o2youjt]

    I'm using the latest version in the ER.

  2. #2
    User winanscreative's Avatar
    Join Date
    06-21-09.
    Location
    Massachusetts, United States
    Posts
    261

    Default Re: Right way to get nr of products in cart

    I would recommend not doing that in the Template file... Why can't you do it in your custom module?

  3. #3
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: Right way to get nr of products in cart

    I suppose I could do it in a custom module, I'll try that. The reason I put it in the template is for ease of use.

  4. #4
    User
    Join Date
    04-10-11.
    Posts
    162

    Default Re: Right way to get nr of products in cart

    This is happening to me too.

    Refreshing the cart seems to empty it. Did you ever find out what was causing it?

    I've made a modification to the cart module:

    Code:
    //if (!count($arrProducts))
    		//{
    		//	$this->Template->empty = true;
    		//	$this->Template->message = $this->iso_emptyMessage ? $this->iso_noProducts : $GLOBALS['TL_LANG']['MSC']['noItemsInCart'];
    		//	return;
    		//}
    As you can see i've commented out the code that checks if the cart is empty. I've done this so that I can have the mini cart display even when it's empty, showing 0 items. This shouldn't cause the cart to empty though, it just detects if it's empty or not. This is the only modification I've made.

    I'm using Isotope 1.3.0 rc1 with Contao 2.10.1.

  5. #5
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: Right way to get nr of products in cart

    I'll try again soon, I want to see if a new session is started...

  6. #6
    Experienced user
    Join Date
    01-12-10.
    Posts
    814

    Default Re: Right way to get nr of products in cart

    Quote Originally Posted by winanscreative
    I would recommend not doing that in the Template file... Why can't you do it in your custom module?
    I moved the code into a module that has no output. It does work, why is this better?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •