Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't delete last item in cart if Minimum Order is Enable #6151

Closed
philipvandebriel opened this issue Aug 13, 2016 · 20 comments
Closed

Can't delete last item in cart if Minimum Order is Enable #6151

philipvandebriel opened this issue Aug 13, 2016 · 20 comments
Labels
bug report Component: Checkout Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1

Comments

@philipvandebriel
Copy link

Preconditions

Update magento 2.0.8 to Magento 2.1
Debian Jessie
Mysql 5.6
Php 5.6

  1. Put item in cart
  2. Try delete item , after popup error

Steps to reproduce

  1. Go to admin -> SALES -> sales
  2. Enable -> Minimum Order Amount
  3. Minimum Amount = 10 or something

Expected result

  1. After remove product from mini cart then the cart need to be empty

Actual result

  1. Last product stay in the cart can't remove
    Try to remove the item then we get this error :

Recoverable Error: Argument 1 passed to Magento\Framework\Exception\InputException::__construct() must be an instance of Magento\Framework\Phrase, string given, called in /var/www/clients/client1/web1/web/vendor/magento/module-quote/Model/ShippingAddressManagement.php on line 121 and defined in /var/www/clients/client1/web1/web/vendor/magento/framework/Exception/InputException.php on line 51

If disable Minimum Order Amount then everything is fine.

@stripcurtains
Copy link

I'm having the exactly same issue with 2.1

@stripcurtains
Copy link

@wert2all Is there a temporary fix for it?

@AVoskoboinikov
Copy link
Contributor

Hi, guys.

Thanks for reporting this, I've created ticket #MAGETWO-57354 in our internal Jira. This issue will be closed after fix.

@andimov andimov added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Aug 22, 2016
@csd-rhuang
Copy link

Hi,

I experienced the same issue. And even worse, I will get a http 500 error when I add the 3rd item to the cart when the minimum order is enabled.

It is Magento 2.1. Bitnami package on AWS.

Thanks

Rex

@vijay-wagento
Copy link

vijay-wagento commented Sep 12, 2016

For my ongoing project in Magento 2.1 I have done below things to come out from this problem,

  1. Create Plugin
 <type name="Magento\Quote\Model\Quote">
        <plugin name="min-orderamount-skip-delete" type="Namespace\ModuleName\Model\QuoteAfter" sortOrder="10"/>
    </type>
  1. in QuoteAfter class
public function afterValidateMinimumAmount()
    {
        $actionName = $this->request->getActionName();
        if($actionName === 'delete') {
            return true;
        }
    }

This solved my problem and I got success to delete item.

@ivankaranjac
Copy link

magento 2.1.2
Problem with deleting, updating and adding to cart once an item is added to the cart

traced the problem to vendor/magento/module-quote/Model/ShippingAddressManagement.php#120

commented out that if and it all seams to work fine now.

Also InputException takes \Magento\Framework\Phrase for first param but in this class string is used, so 500 error.

@ritschi72
Copy link

I also got problems with minimum order amount, cannot delet item from cart anymore, but there is no error message, only blank page. I disabled minimum order amount, and everythin works fine.
Any solution for this?

@chassotl-IFT
Copy link

chassotl-IFT commented Jan 6, 2017

For the one who want it, I did a module, based on the solution of @ivankaranjac , which override the function of the original file : mediafire.com
Put the "BugsFix" folder into "app/code".
Note : tested on Magento 2.1.3

ericrisler added a commit to myntpartners/magento2 that referenced this issue Feb 18, 2017
See magento#6151 for the basics.

When minimum order amount is enabled:
1. add 1 product to the cart; total is below min order amount -> no error.
2. Try to remove that product -> error about minimum amount.
3. Try to add more to the cart with total still below min order -> error about minimum amount
4. Add a product that will bring the total cart amount **over** the min order amount and no errors!

I will request the Magento team takes a look at this line. I don't understand why the minimum amount is being validated here but perhaps it has something to do with multi-shipping checkouts. However, it botches the min order amount logic badly in it's current form.
@ritschi72
Copy link

Still got that issue in 2.1.4, any updates on that?

@hatimeria-artur-jewula
Copy link
Contributor

Fatal error happens if sales/minimum_order/description is provided. This is because Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::getMessage() returns just this string and not a Phrase object.

storbahn added a commit to teamneusta/magento2 that referenced this issue May 20, 2017
…ng, editing or deleting products from quote
storbahn added a commit to teamneusta/magento2 that referenced this issue May 21, 2017
magento-team pushed a commit that referenced this issue May 27, 2017
…ble #6151 #9714

 - Merge Pull Request #9714 from teamneusta/magento2:issue-6151
magento-team pushed a commit that referenced this issue May 27, 2017
[EngCom] Public Pull Requests
 - MAGETWO-69379 use payment method name to make checkbox of agreements more unique #6207 #9717
 - MAGETWO-69378 #4272: v2.0.4 Credit memos with adjustment fees cannot be fully refunded with a second credit memo #9715
 - MAGETWO-69375 Can't delete last item in cart if Minimum Order is Enable #6151 #9714
 - MAGETWO-69230 #7279 bill-to name and ship-to name truncated to 20 chars #9654
 - MAGETWO-69155 Fix coding standard in Magento AdminNotification module #9627
@ishakhsuvarov
Copy link
Contributor

Closing as issue is fixed in the develop branch with the linked commits.

@ishakhsuvarov
Copy link
Contributor

Reopening, as 2.1 fix is not available yet.

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-69375

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-64899

@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-71761

@magento-engcom-team magento-engcom-team added Release Line: 2.1 Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Checkout develop Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Fixed in 2.2.x The issue has been fixed in 2.2 release line labels Sep 11, 2017
@coachdesign
Copy link

I've updated Magento to version 2.2 the problem is still there

@DavaGordon
Copy link

DavaGordon commented Nov 2, 2017

Simply modify vendor/magento/module-quote/Model/ShippingAddressManagement.php to include the RequestInterface and check to see if the update_cart_action was posted, my code is below and seems to work fine tested on 2.1.8 and 2.2.0 RC3

<?php
/**
 * Copyright © 2013-2017 Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Quote\Model;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\NoSuchEntityException;
use Psr\Log\LoggerInterface as Logger;

/**
 * Quote shipping address write service object.
 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
 */
class ShippingAddressManagement implements \Magento\Quote\Model\ShippingAddressManagementInterface
{
    /**
     * Quote repository.
     *
     * @var \Magento\Quote\Api\CartRepositoryInterface
     */
    protected $quoteRepository;

    /**
     * Logger.
     *
     * @var Logger
     */
    protected $logger;

    /**
     * Validator.
     *
     * @var QuoteAddressValidator
     */
    protected $addressValidator;

    /**
     * @var \Magento\Customer\Api\AddressRepositoryInterface
     */
    protected $addressRepository;

    /**
     * @var \Magento\Framework\App\Config\ScopeConfigInterface
     */
    protected $scopeConfig;

    /**
     * @var Quote\TotalsCollector
     */
    protected $totalsCollector;

    /**
     * @var \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
     */
    private $minimumAmountErrorMessage;

    /**
     * @var \Magento\Framework\App\RequestInterface
     */
    protected $requestInterface;

    /**
     * @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
     * @param QuoteAddressValidator $addressValidator
     * @param Logger $logger
     * @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepository
     * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
     * @param Quote\TotalsCollector $totalsCollector
     *
     */
    public function __construct(
        \Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
        QuoteAddressValidator $addressValidator,
        Logger $logger,
        \Magento\Customer\Api\AddressRepositoryInterface $addressRepository,
        \Magento\Framework\App\RequestInterface $requestInterface,
        \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
        \Magento\Quote\Model\Quote\TotalsCollector $totalsCollector
    ) {
        $this->quoteRepository = $quoteRepository;
        $this->addressValidator = $addressValidator;
        $this->logger = $logger;
        $this->addressRepository = $addressRepository;
        $this->request = $requestInterface;
        $this->scopeConfig = $scopeConfig;
        $this->totalsCollector = $totalsCollector;
    }

    /**
     * {@inheritDoc}
     * @SuppressWarnings(PHPMD.NPathComplexity)
     */
    public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address)
    {
        /** @var \Magento\Quote\Model\Quote $quote */
        $quote = $this->quoteRepository->getActive($cartId);
        if ($quote->isVirtual()) {
            throw new NoSuchEntityException(
                __('Cart contains virtual product(s) only. Shipping address is not applicable.')
            );
        }

        $saveInAddressBook = $address->getSaveInAddressBook() ? 1 : 0;
        $sameAsBilling = $address->getSameAsBilling() ? 1 : 0;
        $customerAddressId = $address->getCustomerAddressId();
        $this->addressValidator->validate($address);
        $quote->setShippingAddress($address);
        $address = $quote->getShippingAddress();

        if ($customerAddressId === null) {
            $address->setCustomerAddressId(null);
        }

        if ($customerAddressId) {
            $addressData = $this->addressRepository->getById($customerAddressId);
            $address = $quote->getShippingAddress()->importCustomerAddressData($addressData);
        } elseif ($quote->getCustomerId()) {
            $address->setEmail($quote->getCustomerEmail());
        }
        $address->setSameAsBilling($sameAsBilling);
        $address->setSaveInAddressBook($saveInAddressBook);
        $address->setCollectShippingRates(true);

        $postData = $this->request->getParam('update_cart_action');
        if(!$postData) {
            if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
                throw new InputException(__($this->getMinimumAmountErrorMessage()->getMessage()));
            }
        }

        try {
            $address->save();
        } catch (\Exception $e) {
            $this->logger->critical($e);
            throw new InputException(__('Unable to save address. Please check input data.'));
        }
        return $quote->getShippingAddress()->getId();
    }

    /**
     * {@inheritDoc}
     */
    public function get($cartId)
    {
        /** @var \Magento\Quote\Model\Quote $quote */
        $quote = $this->quoteRepository->getActive($cartId);
        if ($quote->isVirtual()) {
            throw new NoSuchEntityException(
                __('Cart contains virtual product(s) only. Shipping address is not applicable.')
            );
        }
        /** @var \Magento\Quote\Model\Quote\Address $address */
        return $quote->getShippingAddress();
    }

    /**
     * @return \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage
     * @deprecated
     */
    private function getMinimumAmountErrorMessage()
    {
        if ($this->minimumAmountErrorMessage === null) {
            $objectManager = ObjectManager::getInstance();
            $this->minimumAmountErrorMessage = $objectManager->get(
                \Magento\Quote\Model\Quote\Validator\MinimumOrderAmount\ValidationMessage::class
            );
        }
        return $this->minimumAmountErrorMessage;
    }
}

@erlisdhima
Copy link

erlisdhima commented Mar 1, 2018

I am having the same issue with 2.1.10. To verify if this was fixed, I setup a clean Magento 2.1.12 instance, and the issue is still there.
When I try to remove an item from the cart:

screenshot from 2018-03-01 10-17-03

When updating the QTY:

screenshot from 2018-03-01 10-17-17

The only way it updates is when the price x qty equals the minimum amount.

I commented line 120-122 (as mentioned also by @ivankaranjac ) to get this work:

if (!$quote->validateMinimumAmount($quote->getIsMultiShipping())) {
    throw new InputException($this->getMinimumAmountErrorMessage()->getMessage());
}

EDIT: I tried @DavaGordon's solution but that fixes only cart update or clear cart. It does not fix deleting individual items in the cart, adding products from the category/product page, deleting or updating items from the minicart.

@bgronek
Copy link

bgronek commented Apr 26, 2018

It doesn't look like this is fixed. Will you be re-opening it?

@teokolo
Copy link

teokolo commented Apr 3, 2019

Bug still present in Magento 2.1.17.

Here is the error log:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Magento\\Framework\\Exception\\InputException::__construct() must be an instance of Magento\\Framework\\Phrase, string given, called in PATH/vendor/magento/module-quote/Model/ShippingAddressManagement.php on line 121 and defined in PATH/vendor/magento/framework/Exception/InputException.php:51, referer: https://www.elioworld.com/checkout/cart/

Stack trace:, referer: https://www.elioworld.com/checkout/cart/

#0 PATH/vendor/magento/module-quote/Model/ShippingAddressManagement.php(121): Magento\\Framework\\Exception\\InputException->__construct('Attenzione: l'o...'), referer: https://www.elioworld.com/checkout/cart/

#1 PATH/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingProcessor.php(66): Magento\\Quote\\Model\\ShippingAddressManagement->assign('22', Object(Magento\\Quote\\Model\\Quote\\Address)), referer: https://www.elioworld.com/checkout/cart/

#2 PATH/vendor/magento/module-quote/Model/Quote/ShippingAssignment/ShippingAssignmentProcessor.php(110): Magento\\Quote\\Model\\Quote\\ShippingAssignment\\ShippingProcessor->save(Object(Magento\\Quot in PATH/vendor/magento/framework/Exception/InputException.php on line 51, referer: https://www.elioworld.com/checkout/cart/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Checkout Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development Release Line: 2.1
Projects
None yet
Development

No branches or pull requests