Skip to content

Free Shipping via salesrule occasionally not applied to tablerate shipping method #40131

@attheCube

Description

@attheCube

Preconditions and environment

  • Magento version: 2.4.7-p6
  • Tablerate is the only active Shipping method
  • Free shipping is provided by a salesrule
    • no coupon
    • no uses per Customer limitation
    • Conditions
      • Subtotal incl. Tax equals or is greater than 49.90
      • Shipping Country is Germany
    • Actions
      • No conditions
      • Free Shipping: For matching items only

Steps to reproduce

Occasionally shipping costs will be charged, even if an order fullfills all requirements for the shipment to be free.

Unfortunately this behavior is not easy to reproduce.
Out of 56,760 orders this year which fullfill the conditions, only 29 failed.

By digging deeper into this, I discovered, that in vendor/magento/module-offline-shipping/Model/SalesRule/Calculator.php:47, a FreeShipping flag is set to the order items. But this flag has two different possible data types:
If a discount qty is set at the salesrule, the value is of integer, if not the value is of boolean.

Depending on that value type the tablerate module uses it to limit the rule according to the value in relation to the item qty (integer values)
or only as indicator, that free shipment should be provided (boolean value). (vendor/magento/module-offline-shipping/Model/Carrier/Tablerate.php:143 ff.)

This value will be persisted in database, but there boolean values are stored as integers.
So in some cases it seems to be, that the stored value is loaded and used in tablerate functionality, changing the boolean value into integer and therefore triggering not to provide free shipment.

While testing, this happened once.

But you can see, that these values may be ambiguous for the values 0 and 1 . Therefore using these two value types in the same attribute to trigger a different behaviour does not guarantee the correct outcome.

My quick fix is to remove the functionality to limit by item qty.
A better way to use this functionality may be by using two different item-attributes to secure the correct handling.

Expected result

Shipping costs are 0 when all requirements are fullfilled.

Actual result

Sometimes shipping costs are charged despite fullfilling all requirements

Additional information

No response

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Type

No type

Projects

Status

Ready for Confirmation

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions