magento / magento2

Prior to making any Submission(s), you must sign an Adobe Contributor License Agreement, available here at: https://opensource.adobe.com/cla.html. All Submissions you make to Adobe Inc. and its affiliates, assigns and subsidiaries (collectively “Adobe”) are subject to the terms of the Adobe Contributor License Agreement.
http://www.magento.com
Open Software License 3.0
11.5k stars 9.3k forks source link

Free shipping cart price rule not applied. #16388

Closed quisse closed 2 months ago

quisse commented 6 years ago

When creating a "Cart Price Rule" which has to give free shipping, the free shipping never gets applied on the flatrate method. This is because the first code fragment turned into the 2nd fragment. The tablerates also don't seem to give free shipping at first sight. I wanted to create this on a test env but it seems that the cron's aren't running?

https://github.com/magento/magento2/blob/44791d5a8e2b3fc2b0dacc72300030e2df4398ff/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php#L147-L150

https://github.com/magento/magento2/blob/aa4b734aa9b5595c2026bd565a2f19b58f8b6c60/app/code/Magento/OfflineShipping/Model/Carrier/Flatrate.php#L150

Preconditions

  1. Magento 2.2.4

Steps to reproduce

  1. Create "Shopping Cart Rule" which gives free shipping when ordering more than 10 items

image

2.Place an order with 10 or more items

Expected result

  1. Free shipping

Actual result

  1. No free shipping
magento-engcom-team commented 6 years ago

Hi @quisse. Thank you for your report. To help us process this issue please make sure that you provided the following information:

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento-engcom-team give me {$VERSION} instance

where {$VERSION} is version tags (starting from 2.2.0+) or develop branches (2.2-develop +). For more details, please, review the Magento Contributor Assistant documentation.

@quisse do you confirm that you was able to reproduce the issue on vanilla Magento instance following steps to reproduce?

quisse commented 6 years ago

@magento-engcom-team give me 2.2.4 instance

magento-engcom-team commented 6 years ago

Hi @quisse. Thank you for your request. I'm working on Magento 2.2.4 instance for you

magento-engcom-team commented 6 years ago

Hi @quisse, here is your Magento instance. Admin access: https://i-16388-2-2-4.engcom.dev.magento.com/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

quisse commented 6 years ago

@magento-engcom-team I want to test but my product doesn't show up. Maybe add some demo data to the test instances, would save a lot of time.

quisse commented 6 years ago

14657 & #14722 seem related, only they think that the "Free Shipping" method should be enabled which I think it don't.

LouNik1984 commented 6 years ago

I'm on magento 2.2.2 and I have the same issue: free shipping cart rule is enabled but doesn't show up. I have flat rate as the only shipping method enabled. What I did:

What I expect:

What I see when I add the second product:

As a workaround I could enable free shipping with a minimun order amount but this way when I add the second product I see two shipping options: one is the flat rate, the other is the free shipping. This confuses the customer. There should be only one shipping option which become 0 when minimum order amount is reached.

LouNik1984 commented 6 years ago

edit to add: if I change from "shipment with matching items" to "matching items only" then the rule works as expected. In my case, the two options can be used both it doesn't influence the result (I have subtotal as condition) but there are cases in which I need the other option. Eg: give free shipping on the entire cart if one or more products are from X manufacturer. In this case, using "matcing items only" results in free shipping applied only to the products coming from X manufacturer, while other products in cart are still charged as per flat rate amount. So the free shipping cart rule needs to be working with the second option too (for shipment with matching items).

quisse commented 6 years ago

@LouNik1984 see the first code fragment I've embedded, that is the source of your issue.

quisse commented 6 years ago

@LouNik1984 My quick & dirty fix is to create an around method on the AbstractCarrierInterface which calls the collectRates method and if the $rateRequest->getFreeShipping() method returns true, I reset all prices to 0.

pemann commented 6 years ago

Related to this #8614

ghost commented 6 years ago

@quisse, thank you for your report. We've acknowledged the issue and added to our backlog.

quisse commented 6 years ago

@naydav any idea why this is badly refactored or if i can create a PR which puts the free shipping check back?

markalston commented 6 years ago

My PR #14277 should fix this issue in a more complete way. You can use either shipment or matching items only. With matching items only, any items with free shipping will keep the flat rate price at 0. As soon as you add an item without free shipping you will get the normal flat rate pricing for the order.

Give it a try and let me know if it fixes the issue for you or if you have any other feedback. I am trying to fix some build tests which are failing (because the tests are wrong I believe). Hopefully I can get it merged eventually.

bap14 commented 5 years ago

I ended up just adding an afterCollectRates plugin to alter the results for Flatrate (since that's the only one that affected me). Point is, this issue still exists in Magento 2.2.6 and is a deviation from Magento 1 (which we just migrated from) and earlier M2 versions. My plugin is below, in case anyone else is interested:

class FlatratePlugin
{
    /**
     * Check for free shipping and reduce shipping amount
     *
     * @param Flatrate $subject
     * @param Result $result
     * @param $request
     * @return Result
     */
    public function afterCollectRates(Flatrate $subject, Result $result, $request)
    {
        $rate = $result->getRatesByCarrier('flatrate')[0];
        if ($rate->getPrice() && $request->getFreeShipping()) {
            $rate->setPrice(0);
        }
        return $result;
    }
}
lemaryn commented 5 years ago

Hello guys For fix this this issue I created patch for for Magento ver. 2.2.5:

IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- ../vendor/magento/module-quote/Model/Quote/Address.php  (date 1551476934000)
+++ ../vendor/magento/module-quote/Model/Quote/Address.php  (date 1551476934000)
@@ -1032,7 +1032,9 @@
                 if (!$item) {
                     $this->addShippingRate($rate);
                 }
-
+                if ($rate->getPrice() && $request->getFreeShipping()) {
+                    $rate->setPrice(0);
+                }
                 if ($this->getShippingMethod() == $rate->getCode()) {
                     if ($item) {
                         $item->setBaseShippingAmount($rate->getPrice());
devqualwebs commented 5 years ago

Hi @lemaryn, As you created a patch to apply free shipping. Absolutely this is working fine. But when I add a condition to apply free shipping for specific shipping country in my cart rule. Even after adding the condition for shipping country, the rule is applying for all countries. Say for ex. I added the condition that the total item qty should be greater than 5 and the shipping country is Saudi Arabia, Then the rule should apply only when total item qty is greater than 5 and shipping country should be SA. But it's not working like that.

robertbtln commented 4 years ago

The offical magento docs is wrong..... try set For matching items only instead of For shipment with matching items
here is the reason why working like this on flatrate-> https://github.com/magento/magento2/commit/cdefefa948f711daadd6d6ea03ce701aa84fe585#diff-67cd2551c5f3d22c6328e36a4dc0c270

KowsiganAtsayam commented 4 years ago

Log in to Magento Admin, MARKETING > Cart Price Rules and create cart price rules.

Before that, please give some higher number for minimum order amount in configuration -> free shipping.

enter image description here

Then follow the things in the below screenshot.

enter image description here

Then it will work sure.

github-jira-sync-bot commented 3 years ago

:white_check_mark: Jira issue https://jira.corp.magento.com/browse/AC-1033 is successfully created for this GitHub issue.

m2-assistant[bot] commented 3 years ago

:white_check_mark: Confirmed by @engcom-Alfa. Thank you for verifying the issue.
Issue Available: @engcom-Alfa, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

woutersamaey commented 3 years ago

Are you guys taking this issue dark?

quisse commented 3 years ago

@woutersamaey Seems like they will look into this issue (after only 3y 🎉). It's added to the "High Priority Backlog". I'm curious!

Poovarasan-06 commented 1 year ago

@magento-engcom-team give me 2.2.4 instance

magento-deployment-service[bot] commented 1 year ago

Hi @Poovarasan-06. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @Poovarasan-06, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

Poovarasan-06 commented 1 year ago

@magento-engcom-team give me 2.2.4 instance

magento-deployment-service[bot] commented 1 year ago

Hi @Poovarasan-06. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 1 year ago

Hi @Poovarasan-06, unfortunately there is no ability to deploy Magento instance at the moment. Please try again later.

engcom-Bravo commented 6 months ago

@magento give me 2.4-develop instance

magento-deployment-service[bot] commented 6 months ago

Hi @engcom-Bravo. Thank you for your request. I'm working on Magento instance for you.

magento-deployment-service[bot] commented 6 months ago

Hi @engcom-Bravo, here is your Magento Instance: https://13a55a6f05ed50ff72c722c7de8ca97d.instances-prod.magento-community.engineering Admin access: https://13a55a6f05ed50ff72c722c7de8ca97d.instances-prod.magento-community.engineering/admin_921a Login: 059ed370 Password: 174f90559877

engcom-Bravo commented 2 months ago

Hi @quisse,

Thanks for your reporting and collaboration.

We have verified the issue in Latest 2.4-develop instance and the issue is no more reproducible.Kindly refer the screenshots.

Shopping-Cart

Free shipping gets applied.

Hence we are closing this issue.

Thanks.