Hello,
I need some help.
I want shopping-cart-teaser to show in menu not total quantity of all units of products but quantity of products themselves.
For example, I have 3 products (red, blue, white) and put into a cart: 2 units of red, 3 units of blue and 1 unit of white. Now the result in teaser block is 6 units, but in my project the correct result should be 3 products.
How can I get the amount of products in the cart-teaser block, not the amount of units?

PS As a temporary solution I replace $quantity in dc_ajax_add_cart.module to this one:

 global $user;
    $order = commerce_cart_order_load($user->uid);
    $counter = 0;
    if(!empty($order->commerce_line_items)){
        foreach($order->commerce_line_items['und'] as $item){
            $counter++;
        }
    }
......
$quantity = $counter;

But I'm not sure this is the right decision.

with respect,
savage

Comments

savage1974 created an issue. See original summary.

savage1974’s picture

Title: Show in teaser quantity of products, not quantity of package units » Show in shopping-cart-teaser quantity of products, not quantity of package units
savage1974’s picture

Issue summary: View changes
savage1974’s picture

Issue summary: View changes
subhojit777’s picture

Status: Active » Closed (won't fix)

You are somewhat going in the right direction. You have loaded the $order for current user. You need to iterate through the commerce line items, and gather them by their product ids, in a separate array. Then just return the count() of the array. That should do it. The current code will just return the total number of products again.

I am closing this issue as this requirement is project specific.