Код модуля:
<?php
function ajaxcartrefresh_menu(){
$items = array();
$items['updatecart/%/%'] = array(
'page callback' => 'ajaxcartrefresh_updater', // Render HTML
'page arguments' => array(1,2),
'type' => MENU_CALLBACK,
'access arguments' => array('access content'),
);
return $items;
}
function ajaxcartrefresh_updater($order,$cost){
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
commerce_cart_order_refresh($order_wrapper);
$_SESSION['bxbr'] = $cost;
}
print $_SESSION['bxbr'];
function ajaxcartrefresh_commerce_order_presave($order) {
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items_quantity = commerce_line_items_quantity($order_wrapper->commerce_line_items, commerce_product_line_item_types());
$discount_decimal = $_SESSION['bxbr'];
$discount_currency_code = 'RUB';
$order_total = $order_wrapper->commerce_order_total->value();
$discount_amount = commerce_currency_decimal_to_amount($discount_decimal, $discount_currency_code);
$discount_amount = commerce_currency_convert($discount_amount, $discount_currency_code, $order_total['currency_code']);
$order_wrapper->commerce_order_total->amount = $order_total['amount'] + $discount_amount;
$order_wrapper->commerce_order_total->data = commerce_price_component_add($order_total, 'fee', array(
'amount' => $discount_amount,
'currency_code' => $order_total['currency_code'],
'data' => array(),
), TRUE, FALSE);
}