改变商务车中的订单总额

时间:2016-09-24 10:23:13

标签: cart price commerce

我正在尝试更改购物车中的价格:

    function mymodule_commerce_cart_line_item_refresh($line_item, $order_wrapper){
    if($line_item->type == 'product') {

        $line_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);
        $entity = $commerce_product = $line_wrapper->commerce_product->value();
       $product_wrapper = entity_metadata_wrapper('commerce_product', $entity);

         $cprice = $product_wrapper->field_totalprice->value();
         $cprice *=100;

         $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['amount'] = $cprice;

         // Alter the base_price component.
         $line_item->commerce_unit_price[LANGUAGE_NONE]['0']['data']['components']['0']['price']['amount'] = $cprice;
         $line_wrapper->save();


         }
}

在“添加到购物车”后,购物车总金额=基本价格,然后在第二次刷新后,admin / commerce / orders / carts价格变为= field_totalprice,并且在页面中第三次刷新购物车总数变为field_totalprice后。

如何使用“添加到购物车”按钮更改价格?

0 个答案:

没有答案