Skip to content

Commit

Permalink
Remove usage of multiaddress delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
Hlavtox committed Aug 2, 2023
1 parent 1170ba7 commit 1187e89
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 527 deletions.
629 changes: 135 additions & 494 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
13 changes: 8 additions & 5 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 Down Expand Up @@ -6044,7 +6047,7 @@ 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(
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
1 change: 0 additions & 1 deletion controllers/admin/AdminCartsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,6 @@ public function ajaxPreProcess()
} elseif ($id_address_delivery) {
$this->context->cart->id_address_delivery = (int) $id_address_delivery;
}
$this->context->cart->setNoMultishipping();
$this->context->cart->save();
$currency = new Currency((int) $this->context->cart->id_currency);
$this->context->currency = $currency;
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
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

0 comments on commit 1187e89

Please sign in to comment.