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

Nicola1008

  • Beginner
  • *
  • Posts: 30
  • 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: 9175
  • 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: 30
  • 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: 9175
  • 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: 30
  • 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: 9175
  • 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: 30
  • 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: 9175
  • 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){ ?>
[/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 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: 30
  • 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