Author Topic: Get cart item number  (Read 513 times)

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Get cart item number
« on: August 11, 2017, 15:45:30 pm »
Hi,

I want to hide the cart if there's no item inside it. So I've modified my template index.php and I've add this code:

Code: [Select]
$cart = VirtueMartCart::getCart();
<?php if (sizeof($cart->products) > 0){ ?>
        <style>
             .cart{display: block;}
        </style>

        <?php
    
}
else 
{
    
?>

    <style>
         .cart{display: none;}
    </style>
<?php 
?>


The problem is that with this code I have a blank page. I think the error is  $cart = VirtueMartCart::getCart();

How can I get cart number of item?

VM Version: VirtueMart 3.0.9 (I know is an old version but before update it I have to solve some error in my site)

Thanks!!

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #1 on: August 11, 2017, 16:07:08 pm »
Hi,

I want to hide the cart if there's no item inside it. So I've modified my template index.php and I've add this code:

Code: [Select]
$cart = VirtueMartCart::getCart();
<?php if (sizeof($cart->products) > 0){ ?>

Code: [Select]
<?php
$cart 
VirtueMartCart::getCart();
$cart->prepareCartData();
if (!empty(
$cart->totalProduct)){ ?>


Search https://forum.virtuemart.net/index.php?topic=133713.0
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #2 on: August 11, 2017, 16:17:44 pm »
Hi,

I want to hide the cart if there's no item inside it. So I've modified my template index.php and I've add this code:

Code: [Select]
$cart = VirtueMartCart::getCart();
<?php if (sizeof($cart->products) > 0){ ?>

Hi, first sorry if I have post in a wrong forum section.

I've tried to insert the code you suggested me but... I have the same error (complete white page).

Any other idea? Thank you

Code: [Select]
<?php
$cart 
VirtueMartCart::getCart();
$cart->prepareCartData();
if (!empty(
$cart->totalProduct)){ ?>


Search https://forum.virtuemart.net/index.php?topic=133713.0

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #3 on: August 12, 2017, 10:30:59 am »
wrong section, not a big deal, np.

You should first learn how to enable error reporting http://forum.virtuemart.net/index.php?topic=117042.0

But I just notice that the FAQ misses the most important information:

Go to the vm config and enable there the php error reporting. You can set it to nonse, admin or all. Just use all for development.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #4 on: August 13, 2017, 17:58:00 pm »
wrong section, not a big deal, np.

You should first learn how to enable error reporting http://forum.virtuemart.net/index.php?topic=117042.0

But I just notice that the FAQ misses the most important information:

Go to the vm config and enable there the php error reporting. You can set it to nonse, admin or all. Just use all for development.

I've do what you told me but the only error that I see is "Strict Standards: Only variables should be assigned by reference in /home/parastinch/domains/parastinchi.pro/public_html/plugins/system/vm_search_ac/vm_search_ac.php on line 177"

I don't know what is it but still not about the file I modified to hide the cart module if no items are into it.

So I don't know how to solve. I want to hide cart module if no items are into it so I tried to add the code in the first post (and add what have you told me $cart->prepareCartData()) in the index.php of my template but with this cose I have a blank page whe I open my site.

Other solution?

Thank you

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #5 on: August 13, 2017, 22:05:08 pm »
the line I wrote is the solution for your problem to get knowledge about the total of products.

But the rest of your code has here and there errors. Yuo nknow e330rs like this. oS ew humans 5an r3ad, but not the php interpreter.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #6 on: August 14, 2017, 15:02:16 pm »
the line I wrote is the solution for your problem to get knowledge about the total of products.

But the rest of your code has here and there errors. Yuo nknow e330rs like this. oS ew humans 5an r3ad, but not the php interpreter.

Ehmm... sorry but I can't understand (I'm a very beginner in virtuemart code).

I don't know how to do to solve this problem and learn...  :(

Also if I write only your code
Code: [Select]
$cart = VirtueMartCart::getCart();
$cart->prepareCartData();

I get blank page

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #7 on: August 15, 2017, 11:26:54 am »
For example here,

The first 2 lines already throw an error.
Code: [Select]
$cart = VirtueMartCart::getCart();
<?php if (sizeof($cart->products) > 0){ ?>
You write a php command in the first line, but the second line opens the php interpreter with <?php.

Sooo either the first line throws an error, or the second one. And I am sure there are more errors like this. That means your code is "correcT" by idea, content, but the grammar has errors. You must first learn to use a correct editor (for example http://www.flos-freeware.ch/notepad2.html) and so on.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #8 on: August 15, 2017, 15:31:28 pm »
For example here,

The first 2 lines already throw an error.
Code: [Select]
$cart = VirtueMartCart::getCart();
<?php if (sizeof($cart->products) > 0){ ?>
[/quote]
You write a php command in the first line, but the second line opens the php interpreter with <?php.

Sooo either the first line throws an error, or the second one. And I am sure there are more errors like thisThat means your code is "correcT" by ideacontentbut the grammar has errorsYou must first learn to use a correct editor (for example http://www.flos-freeware.ch/notepad2.html) and so on.

I use (http://brackets.io/) or Dreamweaver to write code. I'm sure that there's no "grammar" error in my code.

Check the attached screenshot, please

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #9 on: August 19, 2017, 18:53:44 pm »
Any news about this problem?

I don't know how to do. I did some attempts but I have not yet managed to make my code work.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #10 on: August 19, 2017, 19:03:27 pm »
Maybe you just need to require the cart class?

if (!class_exists('VirtueMartCart')) require(VMPATH_SITE .'/helpers/cart.php');

But really, you should learn how to activate the php error reporting. vm config, first tab, there you can enable it
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #11 on: August 20, 2017, 15:21:20 pm »
Maybe you just need to require the cart class?

if (!class_exists('VirtueMartCart')) require(VMPATH_SITE .'/helpers/cart.php');

But really, you should learn how to activate the php error reporting. vm config, first tab, there you can enable it

GREAT!!! I added your code
Code: [Select]
if (!class_exists('VirtueMartCart'))
   require(VMPATH_SITE .'/helpers/cart.php');

and NOW IT WORKS. Thank you.

So now the cart is visible only if is not empty but... there's a little problem... when user add a product, next click on "continue shopping", the page reload but the cart is not visible. The cart is visible only if I change the page, and once you do this the cart is visible.

Is there a solution for this little problem too?

Thank you!

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #12 on: August 20, 2017, 17:00:13 pm »
You should first learn how to enable error reporting http://forum.virtuemart.net/index.php?topic=117042.0

But I just notice that the FAQ misses the most important information:

Go to the vm config and enable there the php error reporting. You can set it to nonse, admin or all. Just use all for development.

But really, you should learn how to activate the php error reporting. vm config, first tab, there you can enable it
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

  • Beginner
  • *
  • Posts: 38
  • A beginner
Re: Get cart item number
« Reply #13 on: August 20, 2017, 17:12:35 pm »
You should first learn how to enable error reporting http://forum.virtuemart.net/index.php?topic=117042.0

But I just notice that the FAQ misses the most important information:

Go to the vm config and enable there the php error reporting. You can set it to nonse, admin or all. Just use all for development.

But really, you should learn how to activate the php error reporting. vm config, first tab, there you can enable it

Ehm... sorry but my last request is not an error, so "php error reporting" is not useful  :-[

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9336
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Get cart item number
« Reply #14 on: August 21, 2017, 12:38:08 pm »
lol,

without error reporting, you will always just guess. Without error reporting, you cant learn how to code. With error reporting, you would have seen, that a class is missing.
but... there's a little problem... when user add a product, next click on "continue shopping", the page reload but the cart is not visible. The cart is visible only if I change the page, and once you do this the cart is visible.

So, there is a problem, sounds like a bug. So enable the error reporting and tell us the error.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/