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.

Home Page:http://www.magento.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shopping cart sales rule not removed when applicable product removed from cart

JesseEnd opened this issue · comments

A sales rule for free shipping when a product is added to the cart is not removed when that product is removed from the cart.

Preconditions

  1. Magento 2.1.2

Steps to reproduce

  1. Create yes/no product attribute named 'Free Shipping', 'Use for Promo Rule Conditions' enabled
  2. Add Free Shipping attribute to all attribute sets
  3. Enable Free Shipping method with 100,000 minimum order amount (configuration -> sales -> shipping methods)
  4. Create Cart Price Rule 'Free Shipping', no coupon, with the following conditions

If ALL of these conditions are TRUE :

If an item is FOUND  in the cart with ALL  of these conditions true:
    Free Shipping  is  Yes
  1. Add action: Free Shipping 'For shipment with matching items'
  2. Create 2 products: one with free shipping set to no (product 1), and one with free shipping set to yes (product 2)
  3. Add product 1 to cart
  4. Add product 2 to cart
  5. Remove product 2 from cart

Expected result

  1. Free shipping method should appear after product 2 is added to cart
  2. Free shipping method should disappear after product 2 is removed from cart

Actual result

  1. Free shipping method appears after product 2 is added to cart
  2. Free shipping method stays after product 2 is removed from cart
  3. Free shipping method stays after all products removed from cart and even when only product 1 is readded to cart

@JesseEnd thank you for the report.
I tried and didn't reproduce the issue. Please, add some details:
Is value of 100,000 minimum order amount just a way to ensure we work with cart rule?
What are you products prices?
Which shipping methods are enabled?
Where do you check free shipping availability: on the cart page or on the checkout?
Please, add screenshots of the cart rule settings.

Is value of 100,000 minimum order amount just a way to ensure we work with cart rule? That's correct
What are you products prices? Both are $500
Which shipping methods are enabled? Free Shipping and Fedex (Fedex's free method disabled)
Where do you check free shipping availability: on the cart page or on the checkout? Both the cart and checkout pages include the free shipping option when they shouldn't. However, creating an order in the backend works as expected.

Here is the install command I'm using (with my own details removed):
bin/magento setup:install --admin-firstname=***** --admin-lastname=***** --admin-email=***** --admin-user=***** --admin-password=***** --base-url=***** --backend-frontname=admin --db-host=localhost --db-name=***** --db-user=***** --db-password=***** --language=en_US --currency=CAD --timezone=America/Edmonton --use-rewrites=1 --use-secure=0 --base-url-secure=0 --use-secure-admin=0 --session-save=files -vvv

I just created a fresh install of Magento using the above command, added a subcategory, the attribute and sales rule, the 2 products, and set the shipping methods, and the issue still exists for me.

The only way I can get the free shipping option to disappear from the cart/checkout is to clear my browser's cookies. After clearing cookies, I can again reproduce the issue. I'm getting the same results in Firefox version 49.0.2 and Chrome version 54.0.2840.71

I've attached screenshots of Product 2 and the Cart Rule. Product 1 is identical to Product 2 except with 'Free Shipping' set to No.

product 2
cart rule - free shipping

Reproduced the issue on 2.1.2
@JesseEnd is it reproducible for you on latest develop branch?

On the latest develop branch cloned from github (2.2.0-dev), free shipping doesn't become an option in the cart at any point, even while Product 2 is in the cart.

Created MAGETWO-60993 for 2.2.0 branch as blocker for this flow.

Similar to #5332.

Reproducible on develop branch too. Created internal issue MAGETWO-60996.

This issue still exists in v2.1.3

commit 1db9cef is fixing the issue for me on versions 2.1.2 and 2.1.3 as well.

This issue is still present in 2.1.4

I tried implementing the fix listed above.
My cart rule does not work with attributes. The action has Free Shipping set.
When I change the cart subtotal back below the threshold by removing an item, the rule becomes false, however the "Free Shipping" flag stays True.

My testing also shows that this is retained if the customer is registered. Once the customer has had the Shopping Cart rule true once, and received free shipping, they will receive free shipping the next time they login.

Any ideas ?

Found the same thing, the problem seems to be with 3rd party shipping modules like Amasty, so I'm guessing that's why they still have not sorted it out. The fix I made was to add the following code to the execute() function of the following 2 files. This clears the freeshipping flag when they go to the cart of checkout pages. Thanks to @srbarba for the pointer.

vendor\magento\module-checkout\Controller\Cart\Index.php

public function execute()
    {
		// THELETTUCE FIX FOR COUPON CODE FREE SHIPPING
		$address = $this->cart->getQuote()->getShippingAddress();
		$address = $address->setFreeShipping(false)->save();

vendor\magento\module-checkout\Controller\Index\Index.php

public function execute()
    {
		// THELETTUCE FIX FOR COUPON CODE FREE SHIPPING
		$address = $this->getOnepage()->getQuote()->getShippingAddress();
		$address = $address->setFreeShipping(false)->save();

This fix also fixed my issues with carts with items qualifying for free shipping combined with items that don't qualify. Until this fix I could either get free shipping or full price shipping but not shipping cost for non-qualifying items.
Thanks!

What worked for me was a combination of @thelettuce's suggestion along with the commit that is currently in develop 1db9cef

The @thelettuce's suggested changes fixed the price display for me on the shipping selection step of the one page checkout, but when you proceeded to the payment area and viewed the shipping summary within the sidebar the pricing was still free for me.

In my case I am using in 2.1.7, I added

	    $shippingAddress = $quote->getShippingAddress();
	    $shippingAddress->setFreeShipping(0);

Around line 50 app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php again see 1db9cef
for an example. Develop branch has some pretty large changes so I didn't merge the whole file into my testing only the lines above and it appeared to work as expected.

Weel, in my case it didn't fix the issue. I decided to give 100% discount on shipping using a cart rule and another rule giving 75% of shipping discount. The problem is when the first rule is applied, the second rule doesn't work anymore. It does work when I reload the page. Do you have any idea on how to solve that? I'm using 2.1.6

@JesseEnd, thank you for your report.
The issue is already fixed in 2.2.0

The solution @thelettuce provided above worked for us as well. Any chance it will be ported back to 2.1.x, @magento-engcom-team?