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

shippingAddressId is null, while shippingAddress.id has an actual number. #922

Closed
nathanchicken opened this issue Jun 26, 2019 · 2 comments

Comments

@nathanchicken
Copy link

nathanchicken commented Jun 26, 2019

Description

Making a post to commerce/cart/update-cart and posting a new shippingAddress address and billingAddress. The cart response is shown in the screenshot, but there seems to be some oddity between cart.shippingAddress and cart.shippingAddressId:

cart.shippingAddress has various fields, firstName etc, and cart.shippingAddress.id has a value. But cart.shippingAddressId is null.

This is a bit frustrating as we're using the shippingAddressId to check that there is a shipping address added, and that the user can continue on with checkout. Except with a null value, it's saying that the address isn't complete. So I can obviously check the shippingAddress object, but this seems inconsistent and confusing, is it a bug?

commerce-bug

Steps to reproduce

  1. Post a shipping Address and Billing Address to the cart controller via AJAX. They're posted without shippingAddressSameAsBilling or vice versa, as in shippingAddress[firstName] is posted, so too is billingAddress[firstName] is posted. Due to the way my Vue is set up, it's often the same values for each.
  2. This seems the same for guest checkout, or for logged in user

Additional info

  • Craft version: 3.1.31
  • PHP version: 7.1.29
  • Database driver & version:
  • Plugins & versions:
    • Commerce Version: 2.1.7
@johndwells
Copy link

I've dug into this and I think the problem lies in craft\commerce\elements\Order::afterSave(). Essentially, once a new address is saved, the order's record is updated, but the element model isn't updated with the new ID.

So at line 942:

$orderRecord->shippingAddressId = $shippingAddress->id;

There should also be:

$this->setShippingAddress($shippingAddress);

And then similarly at line 954:

$orderRecord->billingAddressId = $billingAddress->id;

There should also be:

$this->setBillingAddress($billingAddress);

HTH.

@lukeholder
Copy link
Member

Thanks for getting to the bottom of this. Fixed for the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants