Commit 83c4d0c7 authored by czigor's avatar czigor Committed by jsacksick

Issue #2913292 by czigor: Fix percentage off shipping discounts.

parent 03efb312
......@@ -191,9 +191,7 @@ function commerce_discount_commerce_cart_order_empty($order) {
* Discount the shipping services for a given order.
*/
function commerce_discount_shipping_services($order) {
rules_invoke_event('commerce_discount_percent_off_shipping', $order);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
commerce_discount_commerce_cart_order_refresh($order_wrapper);
commerce_cart_order_refresh($order);
}
/**
......@@ -615,20 +613,18 @@ function commerce_discount_commerce_discount_offer_type_info() {
if (module_exists('commerce_shipping')) {
$types['free_shipping'] = array(
'label' => t('Free shipping'),
'action' => 'commerce_discount_free_shipping_service',
'action' => 'commerce_discount_shipping_service',
'entity types' => array('commerce_order'),
);
$types['percent_off_shipping'] = array(
'label' => t('% off of shipping'),
'action' => 'commerce_discount_percent_off_shipping_service',
'action' => 'commerce_discount_shipping_service',
'entity types' => array('commerce_order'),
'event' => 'commerce_discount_percent_off_shipping',
);
$types['shipping_upgrade'] = array(
'label' => t('Shipping service upgrade'),
'action' => 'commerce_discount_shipping_upgrade',
'action' => 'commerce_discount_shipping_service',
'entity types' => array('commerce_order'),
'event' => 'commerce_discount_percent_off_shipping',
);
}
......
This diff is collapsed.
......@@ -87,13 +87,18 @@ class CommerceDiscountTestBase extends CommerceBaseTestCase {
* The discount type; Either 'order_discount' or 'product_discount'.
* @param string $offer_type
* The discount offer type; One of 'fixed_amount', 'percentage',
* 'free_products' or 'free_shipping.
* 'free_products', 'free_shipping', 'percent_off_shipping' or
* 'shipping_upgrade'.
* @param int|array $amount
* In case of 'fixed_amount' a number: the discount amount.
* In case of 'percentage' a number: the percentage (a number less than 1).
* In case of 'free_products' an array of the product ids.
* In case of 'free_shipping' an array of strings of the shipping service
* names.
* In case of 'free_shipping' a string of the free shipping service name.
* In case of 'percent_off_shipping' an array with the percentage amount
* (key: 'percent', should be < 100) and the shipping service name string
* (key: 'service').
* In case of 'shipping_upgrade' an array with the source service (key: '
* source') and the target service (key: 'target').
* @param string $name
* Discount name - Optional. If given, CANNOT start with a number.
* @param string $component_title
......@@ -122,12 +127,21 @@ class CommerceDiscountTestBase extends CommerceBaseTestCase {
break;
case 'free_shipping':
// Free shipping service names should be provided for $amount.
foreach ($amount as $free_shipping) {
$offer_wrapper->commerce_free_shipping = $free_shipping;
$offer_wrapper->commerce_free_shipping_strategy = 'only_selected';
$offer_wrapper->commerce_free_shipping = $amount;
$offer_wrapper->commerce_free_shipping_strategy = 'only_selected';
break;
case 'percent_off_shipping':
$offer_wrapper->commerce_percent_off_shipping = $amount['percent'];
if (!empty($amount[1])) {
$offer_wrapper->commerce_percent_off_ship_serv = $amount['service'];
}
break;
case 'shipping_upgrade':
$offer_wrapper->commerce_shipping_upgrade_target = $amount['target'];
$offer_wrapper->commerce_shipping_upgrade_source = $amount['source'];
break;
}
$offer_wrapper->save();
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment