News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Get cart item number

Started by Nicola1008, August 11, 2017, 15:45:30 PM

Previous topic - Next topic

Nicola1008

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:


$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

Quote from: 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:


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



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



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

Nicola1008

Quote from: Milbo on August 11, 2017, 16:07:08 PM
Quote from: 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:


$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


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



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

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

Quote from: 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.

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

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

Quote from: 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.

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
$cart = VirtueMartCart::getCart();
$cart->prepareCartData();


I get blank page

Milbo

#7
For example here,

The first 2 lines already throw an error.
Quote from: Nicola1008 on August 11, 2017, 15:45:30 PM

$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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

Quote from: Milbo on August 15, 2017, 11:26:54 AM
For example here,

The first 2 lines already throw an error.
Quote from: Nicola1008 on August 11, 2017, 15:45:30 PM

$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

Nicola1008

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

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
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Nicola1008

Quote from: 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

GREAT!!! I added your code

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

Quote from: Milbo on August 12, 2017, 10:30:59 AM
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.

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

Nicola1008

Quote from: Milbo on August 20, 2017, 17:00:13 PM
Quote from: Milbo on August 12, 2017, 10:30:59 AM
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.

Quote from: Milbo on August 19, 2017, 19:03:27 PM
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

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.
Quote from: Nicola1008 on August 20, 2017, 15:21:20 PM
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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/