在购物车中的同一个订单项上组合同类产品

alb*_*lbo 7 drupal drupal-7 drupal-hooks drupal-commerce

我遇到了与此处概述的相同问题,但下面的解决方案不起作用.我确实启用了"商品选项".

我也用这个钩子来改变价格,

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);
}
Run Code Online (Sandbox Code Playgroud)

我试过了

$entity->commerce_pricing_attributes[$set_id['set_id']][$field_name] = $price;
Run Code Online (Sandbox Code Playgroud)

与#4一样,但它不起作用.

小智 1

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

使用 hook_commerce_cart_product_comparison_properties_alter() 取消设置“commerce_pricing_attributes”属性。

如果您需要通过此属性来区分您的行项目。我建议您使用规则模块。