-
-
Notifications
You must be signed in to change notification settings - Fork 157
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
StoreBasedCartContext: Wrong Address Type if Adress Identifier is available #1627
Comments
Same goes or CoreShop/src/CoreShop/Bundle/CoreBundle/EventListener/CartBlamerListener.php Lines 96 to 102 in 8a89697
|
any idea how to solve this? |
Overwrites in my project: # CartBlameListener.php
private function blame(CustomerInterface $user)
{
/**
* @todo remove this class after #1627 has been fixed
* @see https://github.com/coreshop/CoreShop/issues/1627
*/
$cart = $this->getCart();
if ($cart === null) {
return;
}
$cart->setCustomer($user);
$defaultAddress = $user->getDefaultAddress();
$shippingAddress = $user->getDefaultAddress();
$invoiceAddress = $user->getDefaultAddress();
if ($defaultAddress instanceof AddressInterface) {
if ($defaultAddress->getAddressIdentifier() instanceof AddressIdentifierInterface) {
if ($defaultAddress->getAddressIdentifier()->getName() === 'invoice') {
$shippingAddress = null;
$invoiceAddress = $user->getDefaultAddress();
} elseif ($defaultAddress->getAddressIdentifier()->getName() === 'shipping') {
$shippingAddress = $user->getDefaultAddress();
$invoiceAddress = null;
}
}
}
if ($cart->getShippingAddress() === null) {
$cart->setShippingAddress($shippingAddress);
}
if ($cart->getInvoiceAddress() === null) {
$cart->setInvoiceAddress($invoiceAddress);
}
$this->cartProcessor->process($cart);
if ($cart->getId()) {
$this->cartManager->persistCart($cart);
return;
}
$this->cartProcessor->process($cart);
} # StoreBasedCartContext.php
public function getCart()
{
/**
* @todo remove this class after #1627 has been fixed
* @see https://github.com/coreshop/CoreShop/issues/1627
*/
$cart = $this->cartContext->getCart();
if (!$cart instanceof CartInterface) {
throw new CartNotFoundException();
}
if ($cart->getInvoiceAddress() instanceof AddressInterface) {
if ($cart->getInvoiceAddress()->getAddressIdentifier() instanceof AddressIdentifierInterface) {
if ($cart->getInvoiceAddress()->getAddressIdentifier()->getName() !== 'invoice') {
$cart->setInvoiceAddress(null);
}
}
}
if ($cart->getShippingAddress() instanceof AddressInterface) {
if ($cart->getShippingAddress()->getAddressIdentifier() instanceof AddressIdentifierInterface) {
if ($cart->getShippingAddress()->getAddressIdentifier()->getName() !== 'shipping') {
$cart->setShippingAddress(null);
}
}
}
return $cart;
} |
I think we should separate the address allocation into a separate service and call that from the Blamer and the Context, WDYT? |
that would be a indeed a better way, especially if one wants to override this 'default' behaviour of initial cart address assignments. Btw, the overrides of the cart context turn out to be more difficult than it could be, bc of
and private methods
Maybe I should address this in another issue. |
CoreShop/src/CoreShop/Component/Core/Context/StoreBasedCartContext.php
Lines 95 to 99 in 8a89697
Here the
StoreBasedCartContext
class assumes, that the default address always fits as shipping / invoice address, which is not always true. In some setups we need to follow EU laws (invoice => allow all countries, shipping => allow specific countries) and therefor we don't have "simple" addresses.In this case, the default address identifier could be either
shipping
orinvoice
but nevernull
. This needs to be checked first!The text was updated successfully, but these errors were encountered: