Magento2: Magento 2.2.5 - Shopping Cart Remove Product ( PHP Fatal error )

Created on 11 Oct 2018  路  10Comments  路  Source: magento/magento2

Preconditions

  1. Magento EE 2.2.5 without sample data is installed.
  2. PHP 7.1.20

Steps to reproduce

  1. Navigate to storefront as a logged in customer.
  2. Click "Add to Cart" on the any Product.
  3. Open mini shopping cart and click to "view and edit cart" link.
  4. Open mini shopping cart click on delete icon next to product.
  5. Click on delete icon next to product in shopping cart page.

Expected result

  1. Page should reload with appropriate message eg. "Item has been already removed from cart. "

Actual result

  1. Error log: PHP Fatal error: Uncaught Error: Call to a member function getQty() on boolean in /var/www/html/shop2dev_deployer/releases/289/vendor/magento/module-google-tag-manager/Model/Plugin/Quote/SetGoogleAnalyticsOnCartRemove.php:47
Clear Description Format is valid

Most helpful comment

@magento-engcom-team The issue here is that Magento\GoogleTagManager\Model\Plugin\Quote\SetGoogleAnalyticsOnCartRemove::afterRemoveItem does not add a conditional to check whether the $item exists before calling $item->getQty(), something like the following would fix:

public function afterRemoveItem(\Magento\Quote\Model\Quote $subject, $result, $itemId)
{
    $item = $subject->getItemById($itemId);

    if (!$item) {
        return $result;
    }

    $this->setItemForTriggerRemoveEvent($this->helper, $this->registry, $item, $item->getQty());

    return $result;
}

All 10 comments

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

  • [ ] Summary of the issue
  • [ ] Information on your environment
  • [ ] Steps to reproduce
  • [ ] Expected and actual results

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 (for example: 2.3-develop).
For more details, please, review the Magento Contributor Assistant documentation.

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

  • [ ] yes
  • [ ] no

@magento-engcom-team give me 2.2.5 instance

Hi @kapil-infobeans. Thank you for your request. I'm working on Magento 2.2.5 instance for you

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

@magento-engcom-team Is it EE 2.2.5 instance? It's only reproducible on EE 2.2.5.

I am able to reproduce this on Magento 2.2.1. Not consistently, but it is occurring under the same scenario.

@magento-engcom-team The issue here is that Magento\GoogleTagManager\Model\Plugin\Quote\SetGoogleAnalyticsOnCartRemove::afterRemoveItem does not add a conditional to check whether the $item exists before calling $item->getQty(), something like the following would fix:

public function afterRemoveItem(\Magento\Quote\Model\Quote $subject, $result, $itemId)
{
    $item = $subject->getItemById($itemId);

    if (!$item) {
        return $result;
    }

    $this->setItemForTriggerRemoveEvent($this->helper, $this->registry, $item, $item->getQty());

    return $result;
}

Hi @engcom-backlog-nazar. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [x] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.
  • [x] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • [ ] 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • [ ] 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento-engcom-team give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and _stop verification process here_!

  • [ ] 5. Verify that the issue is reproducible on 2.2-develop branch.

    Details- Add the comment @magento-engcom-team give me 2.2-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.2-develop branch, please add the label Reproduced on 2.2.x

  • [ ] 6. Add label Issue: Confirmed once verification is complete.

  • [ ] 7. Make sure that automatic system confirms that report has been added to the backlog.

HI @kapil-infobeans I'm not able to reproduce following steps your described, because google-tag-manager exist only in ee version, Please follow these guidelines for proper tracking of your issue. You can report Commerce-related issues in one of two ways:
You can use the Support portal associated with your account
or
If you are a Partner reporting on behalf of a merchant, use the Partner portal.

GitHub is intended for Magento Open Source users to report on issues related to Open Source only. There are no account management services associated with GitHub.

I came across this issue and made a module to fix it.

The use of a preference was due to the use of private for a lot of variables.

https://github.com/WeareJH/m2-module-google-tag-manager-fixes

For further clarification on replication steps.

We have found it is reproducable if you:

  1. Navigate to storefront as guest or logged in user.
  2. Click "Add to Cart" on the any Product.
  3. Open mini shopping cart and click to "view and edit cart" link.
  4. Click on delete item link next to the product in shopping cart page twice.

or

  1. Navigate to storefront as Guest.
  2. Click "Add to Cart" on the any Product.
  3. Open mini shopping cart and click to "view and edit cart" link.
  4. Leave the cart tab open and let the session expire.
  5. Click on delete item link next to the product in shopping cart page.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

salelsol picture salelsol  路  3Comments

denis-g picture denis-g  路  3Comments

xi-ao picture xi-ao  路  3Comments

kirashet666 picture kirashet666  路  3Comments

MauroNigrele picture MauroNigrele  路  3Comments