Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combine like products on the same line item in the cart

I am having the same issue as outlined here but the solutions below do not work. I do have "Commerce Product Option" enabled.

I also alter the price using this hook,

function mectronic_get_amount_qty($price, $length) {
    //print '<pre>P ' . print_r($price, 1) . '</pre>';
    //print '<pre>L ' . print_r($length, 1) . '</pre>';

    if ($length >= 1 && $length <= 5) return $price;
    elseif ($length >= 6 && $length <= 10) return $price * (1 - 0.166666667);
    elseif ($length > 10) return $price * (1 - 0.285714286);
}

I have tried

$entity->commerce_pricing_attributes[$set_id['set_id']][$field_name] = $price;

As in #4 but it does not work.

like image 240
Alex Borsody Avatar asked Jul 13 '15 15:07

Alex Borsody


1 Answers

https://www.drupal.org/node/2056711#comment-9474069

Use hook_commerce_cart_product_comparison_properties_alter() to unset 'commerce_pricing_attributes' property.

In case, your need your line-items to be distinguished by this property. I suggest you to utilise Rules module.

like image 122
Sujith Nara Avatar answered Sep 29 '22 09:09

Sujith Nara