Forum

Thread tagged as: Question, Shop

Function: perch_shop_get_cart_property

Hi,

Is there any documentation for how to use this function? I am trying to get the number of items in a cart and use it in a global header, i.e. get a PHP variable from my shopping cart template.

Patricia Neale

Patricia Neale 0 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

I've seen reports that it might not be working correctly. What result are you getting?

Hi Drew,

I am not getting any results because I am not sure how to use it? I am using PHP code as follows:

$count=perch_shop_get_cart_property('item_count'); echo "Count: " . $count;

Is it feasible to get a variable populated with content from the cart html template?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is item_count a property you've set on the cart?

Hi Patricia

If it's any help, I use this function to get the total:

perch_shop_cart_item_count([], true);

Jon

Hi,

Thanks for the replies.

Drew, I am not sure it is a property as such, but the 'item_count' is part of the perch cart template. I was just floundering around trying to get at the content the template puts out and use it in my PHP scripts. That is why I asked about the perch_shop_get_cart_property function. You mentioned it in a recent post but I cannot find any documentation for it.

Jon, thanks very much for your input. It worked. I don't know how I missed it in the documentation. Where do you get the parameters for it? There is no mention of them in the documentation.

Thanks again.

Regards, Patricia

Drew McLellan

Drew McLellan 2638 points
Perch Support

Where do you get the parameters for it?

What parameters are you looking for? I don't think there are any options you can currently use with it, the signature is simply reserving them to be consistent and allow for future options.

Hi Drew

John specified 2 parameters: perch_shop_cart_item_count([], true); ?

"the signature is simply reserving them to be consistent" - no idea what you mean by this.

perch_shop_get_cart_property - is this a valid function?

Drew McLellan

Drew McLellan 2638 points
Perch Support

The first parameter is an options array, the second indicates that the function should return the value rather than echoing it. This is how most page functions in Perch work.

There aren't currently any options you can pass in the array, but there might be in future, hence its presence.

Hi Drew,

Thanks for the clarification.