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

When customer is set for quote order is still a guest order #38540

Open Genaker opened 6 months ago

Genaker commented 6 months ago

https://github.com/magento/magento2/blob/a98a64a73a72b7bb7bf297d3aba5f9920c8a2b70/app/code/Magento/Quote/Model/Quote.php#L859-L861

if ($this->_customer) { $this->setCustomerId($this->_customer->getId()); }

You need to change it to

if ($this->_customer) { $this->setCustomerId($this->_customer->getId()); $this->setCustomerIsGuest(0); }

or incapsulate this logic into setCustomerId() method

Additional Information: This issue is caused when checking out from a guest cart programmatically, when you assign a customer to the cart before submitting it to place the order, the quote remains as guest even though a customer has been assigned.

m2-assistant[bot] commented 6 months ago

Hi @Genaker. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:

Genaker commented 6 months ago

there is test cases:

$customer = $this->customerRepository->getById($customerId);

        $output->writeln('is order for guest : ' . $quote->getCustomerIsGuest());
        $output->writeln("Customer ID:" . $customer->getId());
        // Assign the customer to the quote
        $quote->assignCustomer($customer);
        $quote->setCustomerId($customer->getId());
        $output->writeln('is order for guest after assign customer and set customer ID : ' . $quote->getCustomerIsGuest());

        $output->writeln('is order for guest after set setCustomerIsGuest : ' . $quote->getCustomerIsGuest());

output 👍

image

the same issue for quote/cart or for order doesn't matte. please fix this issue in the core.

m2-assistant[bot] commented 6 months ago

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


m2-assistant[bot] commented 6 months ago

Hi @engcom-November. 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-November commented 6 months ago

Hello @Genaker,

Thank you for the report and contribution!

Tried to verify this issue on 2.4-develop, but in our case it is not reproducible. Signed in as a customer, and added the product to cart, but customer_is_guest was 0.

Please take a look at the screenshot below:

image

Please let us know if any preconditions are required for the issue to be reproduced, and also if we are missing anything.

Thank you.

Genaker commented 6 months ago

You should submit an order not through the front but by code: it is not a front issue

        $quoteMaskedHash = //Real cart with the items mask 
        $quoteId = $this->getQuoteIdFromMaskedHash($quoteMaskedHash);

        $customerId = //SomeCustomerID
        $quote = $this->quoteRepository->get($quoteId);
        $customer = $this->customerRepository->getById($customerId);

        // Assign the customer to the quote there quote must be not guest 
        $quote->assignCustomer($customer);

        $billingAddress = [
            'firstname' => 'John',
            'lastname' => 'Doe',
            'email' => 'test@test.com',
            'street' => '123 Main St',
            'city' => 'Anytown',
            'country_id' => 'US',
            'region' => 'NY',
            'postcode' => '12345',
            'telephone' => '1234567890',
            'save_in_address_book' => 0
        ];

        $quote->getBillingAddress()->addData($billingAddress);

        $shippingAddress = [
            'firstname' => 'John',
            'lastname' => 'Doe',
            'email' => 'test@test.com',
            'street' => '123 Main St',
            'city' => 'Anytown',
            'country_id' => 'US',
            'region' => 'NY',
            'postcode' => '12345',
            'telephone' => '1234567890',
            'save_in_address_book' => 0
        ];

        $quote->getShippingAddress()->addData($shippingAddress);

        $shippingAddress = $quote->getShippingAddress();
        $shippingAddress->setCollectShippingRates(true)
            ->collectShippingRates()
            ->setShippingMethod('freeshipping_freeshipping'); // For Free Shipping

        $quote->setPaymentMethod('checkmo'); // For Check / Money order
        $quote->setInventoryProcessed(false); // Prevents inventory decrement

        $quote->getPayment()->importData(['method' => 'checkmo']);

        // Attempt to save the quote and create an order from it
        $quote->collectTotals()->save();

        ///Quote is still guest 
engcom-November commented 6 months ago

Hello @Genaker,

Thank you for the quick response!

Verified this issue on 2.4-develop. When checking out from a guest quote programmatically, after assigning a customer to the quote, customer_is_guest remains 1.

Please take a look at the screenshot below:

image

The value of customer_is_guest should have been 0, but it remains 1. Hence confirming this issue.

Please find the custom module used to reproduce this issue. I38540V.zip

Thank you.

github-jira-sync-bot commented 6 months ago

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

m2-assistant[bot] commented 6 months ago

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

github-jira-sync-bot commented 6 months ago

:x: You don't have permission to export this issue.

shmVan commented 2 months ago

@magento I am working on this