Hello,

when I create a percentage promotion on shipping costs are not fixed rate, the calculation is not correct.
Catching EXPE0 I posted the price without discount.
Catching EXPE1 you see the configuration for a discount on a fixed rate.
Catching EXPE2 reducing operates on a fixed rate.
Catching EXPE3 you see the configuration for a discount on the price depending on weight.
Catching EXPE4 reduction is not correct.

thank you in advance for your help.

CommentFileSizeAuthor
#33 commerce_discount-shipping_rules_issue-2699345-33.patch15.54 KBsimeon157
#31 interdiff-2699345-22-26.txt2.83 KBsimeon157
#26 commerce_discount-shipping_rules_issue-2699345-26.patch15.54 KBsimeon157
#24 commerce_discount-shipping_rules_issue-2699345-24.patch16.59 KBsimeon157
#22 shipping-discount-2699345-22.patch13.8 KBpotop
#22 shipping-discount-2699345-22.patch13.8 KBpotop
#19 shipping-discount-2699345-19.patch6.82 KBpotop
#18 shipping_discount-2699345-18.patch3.98 KBjoelpittet
#18 interdiff.txt2.56 KBjoelpittet
#16 interdiff.txt1.44 KBjoelpittet
#16 shipping_discount-2699345-16.patch4.13 KBjoelpittet
#13 interdiff.txt1.44 KBjoelpittet
#13 shipping_discount-2699345-13.patch4.13 KBjoelpittet
#10 shipping_discount-2699345-10.patch3.33 KBjoelpittet
#6 commerce_discount-shipping-percentage-discount-multiple-calls-2699345.patch9.61 KBpotop
EXPE4.jpg99.88 KBzenimagine
EXPE3.jpg140.58 KBzenimagine
EXPE2.jpg103.17 KBzenimagine
EXPE1.jpg146.55 KBzenimagine
EXPE0.jpg101.9 KBzenimagine
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

s1biose created an issue. See original summary.

potop’s picture

Version: 7.x-1.0-alpha7 » 7.x-1.0-alpha8

I have the same issue. In our configuration we have 4 different shipping methods and commerce_discount_commerce_shipping_method_collect_rates($method, $order) is being called for every of these methods. And we have shipping price discounted 4 times in a row. So if we set 50% discount we get 93.75% discount (1-0.5^4).
So we probably need to add parameter $method_name to "commerce_discount_percent_off_shipping" event and check it when deciding if we need to apply discount to the shipping rate of the order.

rszrama’s picture

Title: Bad calculates a percentage discount on shipping costs not weight » Shipping discount applied multiple times to the same shipping service
Version: 7.x-1.0-alpha8 » 7.x-1.x-dev

Does this title more accurately reflect the issue?

potop’s picture

Does this title more accurately reflect the issue?

Yes!

rszrama’s picture

Ok, cool - will try to reproduce and resolve this ASAP.

potop’s picture

Added test for this case.
Unfortunately couldn't find any tests for shipping neither in Discount module nor in Shipping module.
So this test is a first of a kind and needs review anyway (for example we can assert directly shipping_rate's prices but it would look more synthetic)

joelpittet’s picture

Status: Active » Needs review

Setting the status to "needs review" see what the testbot will say. Thanks for writing tests @potop

Status: Needs review » Needs work
joelpittet’s picture

Just a quick review and it looks like it may not have been created against the right branch.

  1. +++ b/tests/commerce_discount.test
    @@ -452,4 +452,4 @@ class CommerceDiscountTest extends CommerceDiscountTestBase {
    -}
    +  }
    

    This looks like an accidental change?

  2. +++ b/tests/commerce_discount_base.test
    @@ -54,9 +54,10 @@ class CommerceDiscountTestBase extends CommerceBaseTestCase {
    +    // Enable all commerce modules + commerce_shipping + commerce_discount.
    ...
    +    $modules[] = 'commerce_shipping';
    

    This should be probably done in your new commerce_discount_shipping.test

joelpittet’s picture

Status: Needs work » Needs review
FileSize
3.33 KB

Let's see if this works.

Status: Needs review » Needs work

The last submitted patch, 10: shipping_discount-2699345-10.patch, failed testing.

potop’s picture

1. This looks like an accidental change?

Yes. You are right.

2. This should be probably done in your new commerce_discount_shipping.test

Commerce Shipping module should be enabled before Discount module otherwise no shipping-related offers are initialized and cannot be tested. So we need to modify CommerceDiscountTestBase::setUp() to be able to do it.
I just made it the easiest way without adding a parameter to pass more modules to it. And as Discount has so many offers related to Shipping it just seemed ok to me.

This test is supposed to fail now as the reported issue exists, but without exception. The only its' assertion should fail.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4.13 KB
1.44 KB

Ah interesting, well let's make that more possible, and I made a typo and enabled commerce_discount twice with a bad copy/paste.

Status: Needs review » Needs work

The last submitted patch, 13: shipping_discount-2699345-13.patch, failed testing.

joelpittet’s picture

I made a mistake on the last posting with my array_merge(). But where does 'commerce_shipping_dummy' come from? There is an example one maybe it should have been 'commerce_shipping_example'?

joelpittet’s picture

Status: Needs work » Needs review
FileSize
4.13 KB
1.44 KB

Running the code locally seems to confirm example is correct, but I could be wrong still, LMK.

This passes locally, the assertion didn't fail. Maybe there is something else in the scenario that causes this to fail. Always good to have more tests though, feel free to iterate.

Status: Needs review » Needs work

The last submitted patch, 16: shipping_discount-2699345-16.patch, failed testing.

joelpittet’s picture

And of course I post the wrong files.

potop’s picture

But where does 'commerce_shipping_dummy' come from? There is an example one maybe it should have been 'commerce_shipping_example'?

Shipping Example contains only one shipping method while we need two to reproduce the issue so another module was added for testing purposes only.
And I managed to miss it in my patch.

Status: Needs review » Needs work

The last submitted patch, 19: shipping-discount-2699345-19.patch, failed testing.

potop’s picture

Status: Needs work » Needs review

Now it seems to fail as expected!

potop’s picture

This new patch contains fix to the issue so tests should pass this time.

The fix also needs review.
It contains following changes:

  • 'Shipping method' parameter added to '% off of a shipping service' event
  • Unused (?) parameter 'Shipping service' changed to 'Shipping method' in '% off of shipping' action
  • parameter 'shipping_method' added to commerce_discount_percent_off_shipping_service() and shipping services are checked for it before applying the discount
potop’s picture

simeon157’s picture

Patch #22 works for the case where you do not select a shipping service. In the case that we have a shipping service selected in the discount, that shipping service gets discounted by the rule multiple times. I've added a check to prevent this. Please review.

Status: Needs review » Needs work

The last submitted patch, 24: commerce_discount-shipping_rules_issue-2699345-24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

simeon157’s picture

It seems I've used a wrong patch as my base for the patch in the previous commit. This should hopefully work now.

simeon157’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 26: commerce_discount-shipping_rules_issue-2699345-26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

simeon157’s picture

Status: Needs work » Needs review
joelpittet’s picture

Status: Needs review » Needs work

Could you create an interdiff with your changes and try again with the patch?
https://www.drupal.org/documentation/git/interdiff

simeon157’s picture

FileSize
2.83 KB

This is the interdiff, between the patch from #22 and #26, it adds a check if the shipping service exists, to prevent any fatal errors.

simeon157’s picture

Status: Needs work » Needs review
simeon157’s picture

Sorry for the late reply. Re-uploading the patch. No idea what happened with the last one.

jsacksick’s picture

@simeon157: Important changes related to free shipping & % off shipping will soon be committed to the codebase.
Could you confirm the bug still occurs with the patch from #2910160: Fix the "free shipping" offer type? This patch is supposed to fix various issues related to free shipping.