tig-nl / gls-magento2

Integrate GLS shipping services into Magento 2. Add GLS shipping and parcelshops to your checkout. Create your labels with Track and Trace functionality from the Magento backend.
5 stars 8 forks source link

[BUG] Condition value is always package weight and never subtotal (except if package has no weight) #28

Open paul-stolk-webdiensten opened 2 years ago

paul-stolk-webdiensten commented 2 years ago

To Reproduce Steps to reproduce the behavior:

  1. Go to the admin, set condition = "Prices vs. Destination" and use table rates for handling fees calculation, with (for example) two prices: 3.95 euro for subtotal 0 and above, 0 euro for subtotal 32.2314 (ex VAT, which is 39 incl VAT) and above
  2. Add one or more products with weight (for example a weight of 1) to the cart, resulting in a subtotal of 32.2314+ (which should trigger the free shipping)

Expected result The shipping costs is 0

Actual result The shipping costs is 3.95

Workaround Change \TIG\GLS\Model\ResourceModel\Carrier\bindings, line 152: Old: $bindings[':condition_value'] = $request->getPackageWeight(); New: $bindings[':condition_value'] = $this->getConditionValue($request->getAllItems());

Note: Because of the following line: if ($bindings[':condition_name'] == null && $bindings[':condition_value'] == 0.0) It does seem to work when no weight is set for the product.

Screenshots Shipping rates: image

Settings: image

paul-stolk-webdiensten commented 2 years ago

The following patch can be used to quick-fix this:

https://github.com/tig-nl/gls-magento2/issues/28
===================================================================
diff --git a/vendor/tig/gls-magento2/Model/ResourceModel/Carrier/GLS.php b/vendor/tig/gls-magento2/Model/ResourceModel/Carrier/GLS.php
--- a/vendor/tig/gls-magento2/Model/ResourceModel/Carrier/GLS.php
+++ b/vendor/tig/gls-magento2/Model/ResourceModel/Carrier/GLS.php   (date 1638787288081)
@@ -149,7 +149,7 @@

         $rateQuery->prepareSelect($select);
         $bindings = $rateQuery->getBindings();
-        $bindings[':condition_value'] = $request->getPackageWeight();
+        $bindings[':condition_value'] = $bindings[':condition_value'] = $this->getConditionValue($request->getAllItems());

         // If quote is lost these values are empty, causing table rates to return the wrong shipping rate.
         if ($bindings[':condition_name'] == null && $bindings[':condition_value'] == 0.0) {

Add it to Composer:

        "patches": {
            "tig/gls-magento2": {
                "ISSUE-28: Condition value is always package weight and never subtotal": "patches/composer/GLS-28-incorrect-condition-value.patch"
            }
        }
tig-jeffreybranderhorst commented 2 years ago

Hi @paul-stolk-webdiensten,

Thank you for submitting this fix, we will investigate this further and make adjustments where needed. My colleague looked at your fix and said the following, a small adjustment you can make is: $bindings[':condition_value'] = $bindings[':condition_value'] = $this->getConditionValue($request->getAllItems()); Change it to $bindings[':condition_value'] = $this->getConditionValue($request->getAllItems());

Thank you again for bringing this to our attention we will investigate the issue!

Have a great day, Jeffrey

vandijkstef commented 2 years ago

Same issue on Mage 2.4.3-p1. Fix worked wonders, thanks!

tig-jeffreybranderhorst commented 2 years ago

Hi @vandijkstef,

Thank you for your confirmation!

Have a great day, Jeffrey