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

Remove usage of multiaddress delivery #33264

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
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
28 changes: 16 additions & 12 deletions classes/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ public function update($null_values = false)
}

// Update the cache
// This is probably not correct, because it should be true only if the address is NOT flagged as deleted
static::$addressExists[$this->id] = true;

if (Validate::isUnsignedId($this->id_customer)) {
Expand All @@ -242,28 +243,31 @@ public function delete()
Customer::resetAddressCache($this->id_customer, $this->id);
}

if (!$this->isUsed()) {
$this->deleteCartAddress();

// Update the cache
if (isset(static::$addressExists[$this->id])) {
static::$addressExists[$this->id] = false;
}

return parent::delete();
} else {
// If the address is used in at least one order, we will not delete it, but only mark it and hide it from backoffice
// However, even if this address is used, we should probably unlink it from all NON ORDERED carts
if ($this->isUsed()) {
$this->deleted = true;

return $this->update();
}

// Remove this address from all carts
$this->deleteCartAddress();

// Update the static cache
if (isset(static::$addressExists[$this->id])) {
static::$addressExists[$this->id] = false;
}

return parent::delete();
}

/**
* removes the address from carts using it, to avoid errors on not existing address
* Removes the address from carts using it, to avoid errors on not existing address.
*/
protected function deleteCartAddress()
{
// keep pending carts, but unlink it from current address
// Remove references to this address from all carts
$sql = 'UPDATE ' . _DB_PREFIX_ . 'cart
SET id_address_delivery = 0
WHERE id_address_delivery = ' . $this->id;
Expand Down
684 changes: 175 additions & 509 deletions classes/Cart.php

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion classes/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ public function updateCustomer(Customer $customer)
// If previous logic resolved to some cart to be used, save it and put this information to cookie
if (Validate::isLoadedObject($this->cart)) {
$this->cart->save();
$this->cart->autosetProductAddress();
$this->cookie->id_cart = (int) $this->cart->id;
}

Expand Down
2 changes: 2 additions & 0 deletions classes/Customization.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public static function getCustomizationPrice($idCustomization)
return 0;
}

// For anyone migrating this - not sure why there is a SUM, when there can be only one line
return (float) Db::getInstance()->getValue(
'
SELECT SUM(`price`) FROM `' . _DB_PREFIX_ . 'customized_data`
Expand All @@ -193,6 +194,7 @@ public static function getCustomizationWeight($idCustomization)
return 0;
}

// For anyone migrating this - not sure why there is a SUM, when there can be only one line
return (float) Db::getInstance()->getValue(
'
SELECT SUM(`weight`) FROM `' . _DB_PREFIX_ . 'customized_data`
Expand Down
17 changes: 10 additions & 7 deletions classes/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -6004,6 +6004,9 @@ public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in
return false;
}

// Load cart object to get delivery address ID
$cart = new Cart((int) $id_cart);

if ($id_customization === 0) {
// Backward compatibility: check if there are no products in cart with specific `id_customization` before returning false
$product_customizations = (int) Db::getInstance()->getValue('
Expand All @@ -6023,7 +6026,7 @@ public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in
}

if (!$result = Db::getInstance()->executeS('
SELECT cd.`id_customization`, c.`id_address_delivery`, c.`id_product`, cfl.`id_customization_field`, c.`id_product_attribute`,
SELECT cd.`id_customization`, c.`id_product`, cfl.`id_customization_field`, c.`id_product_attribute`,
cd.`type`, cd.`index`, cd.`value`, cd.`id_module`, cfl.`name`
FROM `' . _DB_PREFIX_ . 'customized_data` cd
NATURAL JOIN `' . _DB_PREFIX_ . 'customization` c
Expand All @@ -6044,11 +6047,11 @@ public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in
// When a module saves a customization programmatically, it should add its ID in the `id_module` column
$row['value'] = Hook::exec('displayCustomization', ['customization' => $row], (int) $row['id_module']);
}
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $row['id_address_delivery']][(int) $row['id_customization']]['datas'][(int) $row['type']][] = $row;
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $cart->id_address_delivery][(int) $row['id_customization']]['datas'][(int) $row['type']][] = $row;
}

if (!$result = Db::getInstance()->executeS(
'SELECT `id_product`, `id_product_attribute`, `id_customization`, `id_address_delivery`, `quantity`, `quantity_refunded`, `quantity_returned`
'SELECT `id_product`, `id_product_attribute`, `id_customization`, `quantity`, `quantity_refunded`, `quantity_returned`
FROM `' . _DB_PREFIX_ . 'customization`
WHERE `id_cart` = ' . (int) $id_cart .
((int) $id_customization ? ' AND `id_customization` = ' . (int) $id_customization : '') .
Expand All @@ -6058,10 +6061,10 @@ public static function getAllCustomizedDatas($id_cart, $id_lang = null, $only_in
}

foreach ($result as $row) {
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $row['id_address_delivery']][(int) $row['id_customization']]['quantity'] = (int) $row['quantity'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $row['id_address_delivery']][(int) $row['id_customization']]['quantity_refunded'] = (int) $row['quantity_refunded'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $row['id_address_delivery']][(int) $row['id_customization']]['quantity_returned'] = (int) $row['quantity_returned'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $row['id_address_delivery']][(int) $row['id_customization']]['id_customization'] = (int) $row['id_customization'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $cart->id_address_delivery][(int) $row['id_customization']]['quantity'] = (int) $row['quantity'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $cart->id_address_delivery][(int) $row['id_customization']]['quantity_refunded'] = (int) $row['quantity_refunded'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $cart->id_address_delivery][(int) $row['id_customization']]['quantity_returned'] = (int) $row['quantity_returned'];
$customized_datas[(int) $row['id_product']][(int) $row['id_product_attribute']][(int) $cart->id_address_delivery][(int) $row['id_customization']]['id_customization'] = (int) $row['id_customization'];
}

return $customized_datas;
Expand Down
2 changes: 1 addition & 1 deletion classes/order/OrderReturn.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public static function getReturnedCustomizedProducts($id_order)
$return['product_attribute_id'] = (int) $products[(int) $return['id_order_detail']]['product_attribute_id'];
$return['name'] = $products[(int) $return['id_order_detail']]['product_name'];
$return['reference'] = $products[(int) $return['id_order_detail']]['product_reference'];
$return['id_address_delivery'] = $products[(int) $return['id_order_detail']]['id_address_delivery'];
$return['id_address_delivery'] = (int) $order->id_address_delivery;
}

return $returns;
Expand Down
5 changes: 2 additions & 3 deletions controllers/front/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ protected function processDeleteProductInCart()
if ($this->context->cart->deleteProduct(
$this->id_product,
$this->id_product_attribute,
$this->customization_id,
$this->id_address_delivery
$this->customization_id
)) {
Hook::exec('actionObjectProductInCartDeleteAfter', $data);

Expand Down Expand Up @@ -495,7 +494,7 @@ protected function processChangeProductInCart()
$this->id_product_attribute,
$this->customization_id,
Tools::getValue('op', 'up'),
$this->id_address_delivery,
0,
null,
true,
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ private function createEmptyCustomerCart(Customer $customer): Cart
$cart->id_address_delivery = $addressId;
$cart->id_address_invoice = $addressId;

$cart->setNoMultishipping();
$cart->save();

return $cart;
Expand Down
4 changes: 0 additions & 4 deletions src/Adapter/Order/GeneralConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class GeneralConfiguration extends AbstractMultistoreConfiguration
'disable_reordering_option',
'purchase_minimum_value',
'recalculate_shipping_cost',
'allow_multishipping',
'allow_delayed_shipping',
'enable_tos',
'tos_cms_id',
Expand All @@ -63,7 +62,6 @@ public function getConfiguration()
'disable_reordering_option' => (bool) $this->configuration->get('PS_DISALLOW_HISTORY_REORDERING', false, $shopConstraint),
'purchase_minimum_value' => (float) $this->configuration->get('PS_PURCHASE_MINIMUM', 0, $shopConstraint),
'recalculate_shipping_cost' => (bool) $this->configuration->get('PS_ORDER_RECALCULATE_SHIPPING', false, $shopConstraint),
'allow_multishipping' => (bool) $this->configuration->get('PS_ALLOW_MULTISHIPPING', false, $shopConstraint),
'allow_delayed_shipping' => (bool) $this->configuration->get('PS_SHIP_WHEN_AVAILABLE', false, $shopConstraint),
'enable_tos' => (bool) $this->configuration->get('PS_CONDITIONS', false, $shopConstraint),
'tos_cms_id' => (int) $this->configuration->get('PS_CONDITIONS_CMS_ID', 0, $shopConstraint),
Expand All @@ -84,7 +82,6 @@ public function updateConfiguration(array $configuration)
$this->updateConfigurationValue('PS_DISALLOW_HISTORY_REORDERING', 'disable_reordering_option', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_PURCHASE_MINIMUM', 'purchase_minimum_value', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_ORDER_RECALCULATE_SHIPPING', 'recalculate_shipping_cost', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_ALLOW_MULTISHIPPING', 'allow_multishipping', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_SHIP_WHEN_AVAILABLE', 'allow_delayed_shipping', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_CONDITIONS', 'enable_tos', $configuration, $shopConstraint);
$this->updateConfigurationValue('PS_CONDITIONS_CMS_ID', 'tos_cms_id', $configuration, $shopConstraint);
Expand All @@ -106,7 +103,6 @@ protected function buildResolver(): OptionsResolver
->setAllowedTypes('disable_reordering_option', 'bool')
->setAllowedTypes('purchase_minimum_value', 'float')
->setAllowedTypes('recalculate_shipping_cost', 'bool')
->setAllowedTypes('allow_multishipping', 'bool')
->setAllowedTypes('allow_delayed_shipping', 'bool')
->setAllowedTypes('enable_tos', 'bool')
->setAllowedTypes('tos_cms_id', 'int')
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Cart/CartRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ protected function getProductPrice(CartCore $cart, $rowData)
$productId = (int) $rowData['id_product'];
$quantity = (int) $rowData['cart_quantity'];

$addressId = $cart->getProductAddressId($rowData);
$addressId = $cart->getProductAddressId();
if (!$addressId) {
$addressId = $cart->getTaxAddressId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function indexAction(Request $request)
'help_link' => $this->generateSidebarLink($legacyController),
'generalForm' => $generalForm->createView(),
'giftOptionsForm' => $giftOptionsForm->createView(),
'isMultishippingEnabled' => $this->getConfiguration()->getBoolean('PS_ALLOW_MULTISHIPPING'),
'isAtcpShipWrapEnabled' => $this->getConfiguration()->getBoolean('PS_ATCP_SHIPWRAP'),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public function __construct(
public function buildForm(FormBuilderInterface $builder, array $options)
{
$configuration = $this->configuration;
$isMultishippingEnabled = (bool) $configuration->get('PS_ALLOW_MULTISHIPPING');
$currencyIsoCode = $this->currencyDataProvider->getDefaultCurrencyIsoCode();

$builder
Expand Down Expand Up @@ -115,15 +114,6 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'multistore_configuration_key' => 'PS_ORDER_RECALCULATE_SHIPPING',
]);

if ($isMultishippingEnabled) {
$builder->add('allow_multishipping', SwitchType::class, [
'required' => false,
'label' => $this->trans('Allow multishipping', 'Admin.Shopparameters.Feature'),
'help' => $this->trans('Allow the customer to ship orders to multiple addresses. This option will convert the customer\'s cart into one or more orders.', 'Admin.Shopparameters.Help'),
'multistore_configuration_key' => 'PS_ALLOW_MULTISHIPPING',
]);
}

$builder
->add('allow_delayed_shipping', SwitchType::class, [
'required' => false,
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/Utility/CartOld.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function getOrderTotalV1(
$virtual_context->shop = new Shop((int) $product['id_shop']);
}

$id_address = $this->getProductAddressId($product);
$id_address = $this->getProductAddressId();

// The $null variable below is not used,
// but it is necessary to pass it to getProductPrice because
Expand Down Expand Up @@ -257,7 +257,7 @@ public function getOrderTotalV1(

$package = [
'id_carrier' => $id_carrier,
'id_address' => $this->getDeliveryAddressId($products),
'id_address' => $this->id_address_delivery,
'products' => $products,
];

Expand Down
9 changes: 0 additions & 9 deletions tests/Resources/modules_tests/override/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@ public function updateAddressId($id_address, $id_address_new)
if ($to_update) {
$this->update();
}
$sql = 'UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);
$sql = 'UPDATE `' . _DB_PREFIX_ . 'customization`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,6 @@ public function updateAddressId($id_address, $id_address_new)
$this->update();
}

$sql = 'UPDATE `' . _DB_PREFIX_ . 'cart_product`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);

$sql = 'UPDATE `' . _DB_PREFIX_ . 'customization`
SET `id_address_delivery` = ' . (int) $id_address_new . '
WHERE `id_cart` = ' . (int) $this->id . '
AND `id_address_delivery` = ' . (int) $id_address;
Db::getInstance()->execute($sql);
}

Expand Down
3 changes: 0 additions & 3 deletions tests/Unit/Adapter/Order/GeneralConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class GeneralConfigurationTest extends AbstractConfigurationTestCase
'disable_reordering_option' => true,
'purchase_minimum_value' => 3.0,
'recalculate_shipping_cost' => true,
'allow_multishipping' => true,
'allow_delayed_shipping' => true,
'enable_tos' => true,
'tos_cms_id' => 3,
Expand Down Expand Up @@ -77,7 +76,6 @@ public function testGetConfiguration(ShopConstraint $shopConstraint): void
['PS_DISALLOW_HISTORY_REORDERING', false, $shopConstraint, true],
['PS_PURCHASE_MINIMUM', 0, $shopConstraint, 3.0],
['PS_ORDER_RECALCULATE_SHIPPING', false, $shopConstraint, true],
['PS_ALLOW_MULTISHIPPING', false, $shopConstraint, true],
['PS_SHIP_WHEN_AVAILABLE', false, $shopConstraint, true],
['PS_CONDITIONS', false, $shopConstraint, true],
['PS_CONDITIONS_CMS_ID', 0, $shopConstraint, 3],
Expand Down Expand Up @@ -119,7 +117,6 @@ public function provideInvalidConfiguration(): array
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['disable_reordering_option' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['purchase_minimum_value' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['recalculate_shipping_cost' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['allow_multishipping' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['allow_delayed_shipping' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['enable_tos' => 'wrong_type'])],
[InvalidOptionsException::class, array_merge(self::VALID_CONFIGURATION, ['tos_cms_id' => 'wrong_type'])],
Expand Down