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

Move Cart secure_key setter at the right place #14352

Merged
merged 2 commits into from Jul 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion classes/Context.php
Expand Up @@ -332,12 +332,13 @@ public function updateCustomer(Customer $customer)
$customer->logged = 1;
$this->cookie->email = $customer->email;
$this->cookie->is_guest = $customer->isGuest();
$this->cart->secure_key = $customer->secure_key;

if (Configuration::get('PS_CART_FOLLOWING') && (empty($this->cookie->id_cart) || Cart::getNbProducts($this->cookie->id_cart) == 0) && $idCart = (int) Cart::lastNoneOrderedCart($this->customer->id)) {
$this->cart = new Cart($idCart);
$this->cart->secure_key = $customer->secure_key;
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add another validation layer by adding something like if ($this->cart !== null) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, new Cart() should always return a cart, or throw an Exception

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was targeting the else case 😄 but the github UI makes it look like I show the if

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that before but Travis was failing so I try with this approach, perhaps the upcoming function calls need the secure key

$idCarrier = (int) $this->cart->id_carrier;
$this->cart->secure_key = $customer->secure_key;
$this->cart->id_carrier = 0;
$this->cart->setDeliveryOption(null);
$this->cart->updateAddressId($this->cart->id_address_delivery, (int) Address::getFirstCustomerAddressId((int) ($customer->id)));
Expand Down