VirtueMart Forum

VirtueMart 2 + 3 => Virtuemart Development and bug reports => Coding Central => Topic started by: Nicola1008 on August 11, 2017, 15:45:30 pm

Title: Get cart item number
Post by: Nicola1008 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!!
Title: Re: Get cart item number
Post by: Milbo 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
Title: Re: Get cart item number
Post by: Nicola1008 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
Title: Re: Get cart item number
Post by: Milbo 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.
Title: Re: Get cart item number
Post by: Nicola1008 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
Title: Re: Get cart item number
Post by: Milbo 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.
Title: Re: Get cart item number
Post by: Nicola1008 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
Title: Re: Get cart item number
Post by: Milbo 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.
Title: Re: Get cart item number
Post by: Nicola1008 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 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 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
Title: Re: Get cart item number
Post by: Nicola1008 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.
Title: Re: Get cart item number
Post by: Milbo 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
Title: Re: Get cart item number
Post by: Nicola1008 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!
Title: Re: Get cart item number
Post by: Milbo 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
Title: Re: Get cart item number
Post by: Nicola1008 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  :-[
Title: Re: Get cart item number
Post by: Milbo 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.
Title: Re: Get cart item number
Post by: Nicola1008 on August 21, 2017, 13:26:22 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.

OK, I'll try to enable error reporting (but... I don't know how to do it without compromise user experience)
Title: Re: Get cart item number
Post by: Milbo on August 21, 2017, 17:32:02 pm
I wrote many times how todo it. Just use the virtuemart config, first tab.
Title: Re: Get cart item number
Post by: Nicola1008 on August 23, 2017, 16:48:10 pm
I wrote many times how todo it. Just use the virtuemart config, first tab.

Ok, I've done it (as you can see in the attached image)... BUT I don't see any error of cart that ca help me solve the problem.