Jump to content

Need a more specific method for counting cart quantity. Combinations & Customizations


Recommended Posts

$quantity += $product['cart_quantity'];

I'm updating some code for a client, related to an Order Fee module that has been extended to handle fee quantities. 

Counting the cart quantity of each product isn't quite what we're after. 

 

I need a solution for counting the total number of products instances - accounting for multiple combinations and any instances of those combinations that might have customization attached. 

 

I tried a number of methods, and won't include any of my botched attempts. I also looked at the order controller php and shopping cart tpl logic and architecture for clues, and still couldn't quite get it. 

 

Attached is a screenshot, just to perfectly illustrate our needs.

post-1290471-0-33732500-1482490107_thumb.jpg

We would like this particular cart to reflect 4 fees. One fee per customization instance. 

In the screenshot I incremented the counter using a foreach statement to step thru a value found with getProductCustomization. I had limited success counting the number of customizations, but couldn't account for multiple combinations properly. 

Hopefully someone can illuminate the situation. Thank you.

Edited by heliumdream (see edit history)
Link to comment
Share on other sites

$customization = $context->cart->getProductCustomization($product_key)

more or less i already had what was needed.

iterating thru each product, multiple combinations would cause the customization count to trigger more than once...so i added a catch to stop things if the loop already ran on a particular product_id.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...