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.56k stars 9.32k forks source link

"Invalid address id" when adding product to basket Magento2 #7570

Closed sma09sjb closed 7 years ago

sma09sjb commented 7 years ago

Steps to reproduce

  1. Login
  2. Add a product to your basket (remember which product you added)
  3. Go to checkout and select a delivery address (do not process a transaction)

The database now has a quote_address entity which has a customer_address_id untitled

  1. Remove the product from basket
  2. Delete the address you selected from your account
  3. add the same product as before to your basket
  4. try and remove the product

Expected result

  1. You should be able to remove the product from your basket without an error being thrown.

Actual result

image When you add the same product to your basket the code looks for an existing quote for that user, and it finds one in the above scenario but because the address associated to is now no longer in existence it throws this error.

What needs to happen is when an address is deleted the quotes should be checked for any quote_addresses with that customer_address_id referenced, and then it should be deleted.

veloraven commented 7 years ago

@sma09sjb thank you for your report. Please, also identify which version of Magento you are running.

sma09sjb commented 7 years ago

@veloraven apologies, the magento version is 2.1.2

SerhiyShkolyarenko commented 7 years ago

@sma09sjb thank you for very clear bug report! Created internal issue MAGETWO-61551.

sma09sjb commented 7 years ago

Can i have an update on this please?

SerhiyShkolyarenko commented 7 years ago

The ticket is in queue for fixing. It's marked as high priority.

mgomma commented 7 years ago

Does there exist a patch for that issue as it blocks going live, It happens with me after failed payment operation.

causes add to cart to fail and reload the page. and when doing reorder.

davidstillson commented 7 years ago

We are also experiencing this bug in 2.1.3.

I will say that when I replicate this issue, it doesn't matter if I try to add the same product to cart or a different one. If I've created a quote from an address in the account, and that address get's deleted after quote creation, it produces the error when trying to add products.

So once I remove the items from cart, then delete the address used from the account, I can't add any products to cart. If I manually delete the records from the quote_address table, I am able to add items to cart again.

Flipmediaco commented 7 years ago

I believe this issue is created as the address id stored in customer_entity for default_shipping has been removed from customer_address_entity.

mgomma commented 7 years ago

@Flipmediaco I totally agree with you as that error disappear when the customer set default shipping and billing address

cherreman commented 7 years ago

We are experiencing the same issue when removing an item from the basket. (We are running 2.1.2)

Is there any update on this?

cherreman commented 7 years ago

This Gist fixes this issue by setting the billing and shipping addresses to the customers defaults: https://gist.github.com/cherreman/e35590981bf8a53a086a66c8a4f86fad

sdzhepa commented 7 years ago

@sma09sjb, @davidstillson, @cherreman This bug has already fixed in scope of MAGETWO-62044 for the latest version(develop branch)

eInyzant commented 7 years ago

is it really fixed already ? I still have this issue on magento 2.1.6

sammarcus commented 7 years ago

I am also (still) experiencing this on 2.1.7 CE

fronke commented 7 years ago

I am also still experiencing this on 2.1.7 CE

AlexanderHuyghebaert commented 7 years ago

Also can confirm that this issue still exists in 2.1.7 CE

germaike commented 7 years ago

Hi, i'm still having this problem. I can not clear customers shopping cart. error : Invalid customer address id 7494 version : ce 2.1.4

Is it possible to delete the cart at database Level? Please reopen ticket!

rijadhusic commented 7 years ago

I am also (still) experiencing this on 2.1.8 EE

conflicker commented 7 years ago

I'm getting this issue on 2.1.7 CE, any solution?

conflicker commented 7 years ago

@magento-engcom-team what is G1 Failed label means?

magento-engcom-team commented 7 years ago

Hi @conflicker G1 Failed (Gate 1 Failed) means the issue description did not pass automatic verification of the issue description. We will publish more details soon about Gates system.

spraxis commented 7 years ago

A quick and dirty solution could be to create a Plugin and clear the customer_address_id from the quote_address table everytime an address is deleted.

di.xml

<type name="\Magento\Customer\Model\ResourceModel\Address">
    <plugin name="mycompany_quote_address_fix_plugin"
            type="MyCompany\QuoteAddressFix\Plugin\AddressPlugin"
            sortOrder="1"
            disabled="false"/>
</type>

app/code/MyCompany/QuoteAddressFix/Plugin/AddressPlugin.php

<?php
namespace MyCompany\QuoteAddressFix\Plugin;

use Magento\Framework\App\ResourceConnection;
use Psr\Log\LoggerInterface;
use Magento\Customer\Model\ResourceModel\Address;

/**
 * Class AddressPlugin
 * @package MyCompany\QuoteAddressFix\Plugin
 */
class AddressPlugin
{
    /**
     * @var \Magento\Framework\App\ResourceConnection
     */
    protected $resourceConnection;

    /**
     * @var \Psr\Log\LoggerInterface
     */
    protected $logger;

    /**
     * @param ResourceConnection $resourceConnection
     * @param LoggerInterface $logger
     */
    public function __construct(
        ResourceConnection $resourceConnection,
        LoggerInterface $logger
    ) {
        $this->resourceConnection = $resourceConnection;
        $this->logger = $logger;
    }

    /**
     * Clear customer addresses from the quote_address table
     * M2 Bug: https://github.com/magento/magento2/issues/7570
     *
     * @param Address $subject
     * @param \Closure $proceed
     * @param object $address
     * @return mixed
     */
    public function aroundDelete(Address $subject, \Closure $proceed, $address)
    {
        try {
            $this->resourceConnection->getConnection()->fetchRow("
                UPDATE quote_address
                SET customer_address_id = NULL
                WHERE customer_address_id = '" . $address->getId() . "'
            ");
        } catch (\Exception $e) {
            $this->logger->critical($e->getMessage());
        }
        return $proceed($address);
    }
}
benyanke commented 6 years ago

Any update on this, @magento? Still a breaking issue for us.

williankeller commented 6 years ago

Hey guys, do we have any updated on this? We still facing this issue

benyanke commented 6 years ago

Hi Willian, did you try the plugin three posts up? We installed it on our site, and we haven't seen it since.

williankeller commented 6 years ago

Hi @benyanke, no, is it working to EE as well?

benyanke commented 6 years ago

Yes, we're EE.

Rita-ti commented 5 years ago

For a quick solution, please go through this below link: https://magento.stackexchange.com/a/196149/52030

Adr79 commented 5 years ago

We have same issue on magento 2.3.1. Is this issue being investigated?

apaolino commented 5 years ago

Still have it on 2.3.1 CE

TheLaughingThird commented 5 years ago

Still have it on 2.3.2 great this magento 2 platform, first the incredible 2.2 version and also the constant changes makes it real ease to work with... NOT !

m2-assistant[bot] commented 5 years ago

Hi @engcom-Bravo. 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:

engcom-Charlie commented 5 years ago

I can't reproduce this issue on fresh Magento 2.3-develop and 2.3.2 branches.

Manual testing scenario:
1.Login to admin 2.Create a simple product

  1. Go to customer view 4.Login to customer account 5.Add a product to your basket (remember which product you added) 6.Go to checkout and select a delivery address (do not process a transaction) 7.Back to the cart 8.Remove the product from basket 9.Go to the My Account-->Address Book 10.Add new address and select it as default(because you can't delete current address if you doesn't have another one) 11.Delete the previous address you selected from your account 12.Add the same product as before to your basket 13.try to remove the product from a cart

Actual result: Product deleted from cart


Hi, @b2bdokter ! Can you provide me your steps to reproduce this issue?

TheLaughingThird commented 5 years ago

Yesterday my customer reported after I told him to order a item:

It says costumer invalid adress id 3832, when i try

At the moment , I am not be able to login to the magento backend ( out of the blue) so my first 2 hours I need to solve that again... But it is such a buggy platform I can't believe it seriously considering to start using another CMS system in the future, Tons of bugs, a lot of them are not even solved ... Only one benefiting from M2 are the developers with their expensive extensions you need to renew...

Just insert a new password, try to login and it wont let me , its such a good platform for E-Concerns

So I am sorry it seems like I wont be able to help to reproduce because loggin into magento 2.3.2 seems difficult enough

engcom-Charlie commented 5 years ago

@b2bdokter , you can try to reproduce it on fresh 2.3-develop instance. I will request instance for you.

engcom-Charlie commented 5 years ago

@magento give me 2.3-develop instance

magento-engcom-team commented 5 years ago

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

magento-engcom-team commented 5 years ago

Hi @engcom-Charlie, here is your Magento instance. Admin access: https://i-7570-2-3-develop.instances.magento-community.engineering/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

TheLaughingThird commented 5 years ago

Okay @magento-engcom-team Give me one please thank you

engcom-Charlie commented 5 years ago

@b2bdokter use it: Admin access: https://i-7570-2-3-develop.instances.magento-community.engineering/admin Login: admin Password: 123123q Instance will be terminated in up to 3 hours.

TheLaughingThird commented 5 years ago

Tried to reproduce on that installation , cant reproduce.

But since it happens on our own installation. Whats more important to me and others still experiencing this... What can we do to solve this ?

customer invalid adress id 3832

I see no decent solution anywere...

Flipmediaco commented 5 years ago

@b2bdokter This is a data issue...

The table customer_address_entity has a foreign key named customer_address_id of 3832 which is the primary key entity_id of customer_address_entity... If you review these two tables, I suspect you will find the address identified byentity_id 3832 is no longer present, yet a reference in another table remains. The exact specifics of this will likely be unique to your instance.

This thread is closed as the original issue was resolved and update applied that changed the customer_entity so it did not store an address foreign key of customer_address_entity in default_shipping.

If you can recreate the steps that has caused the data inconsistency, then open a new ticket detailing this 👍

Good luck and I guess you will find the solution in the data and once the reference to 3832 is removed, the issue will go away.

Hope this helps, have a great day

TheLaughingThird commented 5 years ago

Thank you @Flipmediaco for your time ,have a great day too

fm-cl commented 2 years ago

im having this issue on magento 2.4.2p2, only with certain customers

vipin1211987 commented 5 months ago

$connection->query("update customer_entity ce set default_billing = null where default_billing is not null and default_billing != 0 and default_billing not in (select entity_id from customer_address_entity where parent_id = ce.entity_id);");

$connection->query("update customer_entity ce set default_shipping = null where default_shipping is not null and default_shipping != 0 and default_shipping not in (select entity_id from customer_address_entity where parent_id = ce.entity_id);");

vandark25 commented 4 months ago

Solved in https://github.com/magento/magento2/issues/23618