The free shipping discount doesn't utilize pricing components. I have a project where I was evaluating pricing components to help track what discounts have been applied to line items, etc. So I attempted to work around this by adding a custom action to all of the free shipping rules. I had struggled with why my custom actions were not sticking until I located the culprit.
commerce_discount_commerce_discount_rule_build looks to find any discount offer that uses the commerce_free_shipping field so it can add the shipping service to the commerce_discount_free_shipping_service action. It does this by looping through all actions on the rule, however for each action that is not commerce_discount_free_shipping_service, it deletes it.
// Add missing parameter.
foreach ($rule->actions() as $action) {
if ($action->getElementName() == 'commerce_discount_free_shipping_service') {
$action->settings['shipping_service'] = $shipping_service;
}
else {
$action->delete();
}
}
Is there a reason that every other action is deleted? I couldn't find anything that made this necessary so I've created a patch (coming shortly) to remove the $action->delete().
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | commerce_discount-allow_free_shipping_custom_actions-2363331-1.patch | 481 bytes | caschbre |
Comments
Comment #1
caschbre commentedComment #2
joelpittetI wonder if @bojanz can shed some light on this one. I can't see why it's deleting actions.
Comment #3
joelpittetComment #4
joelpittetTrying to get the automated tests to pick this patch up...
Comment #6
joelpittettestbot is being nice, retest
Comment #8
joelpittetI can't see any reason for this to be, thanks for the patch. I've committed it to dev. If it's needed then I guess someone will pipe up and we can add some comments, tests and likely more conditions around the action removal.
It was committed in this issue #1677628: Provide a "Free Shipping" offer type maybe @jkuma can shed some light?