From 679e9d4f711f12fe249afb2229054d3fcb1af53f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 09:31:56 +0000 Subject: [PATCH 1/4] Initial plan From fb20211e6ddba012d174ee3298edabb0a2fc897f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 09:35:50 +0000 Subject: [PATCH 2/4] Fix LengowCart bugs causing order import failure on PS 1.7.8.8 - Replace Attribute::getAttributeMinimalQty() / ProductAttribute::getAttributeMinimalQty() version-check block with new Combination()->minimal_quantity which works on all PS versions - Replace Context::getContext() with LengowContext::getContext() in updateQty() (2 places) to ensure the correct shop context is used during cron import - Add containsProduct() method to LengowCart for explicit control - Add _updateCustomizationQuantity() method to LengowCart for explicit control Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/c3d757de-91f0-4eb2-bd1d-ee0889feed55 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com> --- classes/models/LengowCart.php | 88 +++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/classes/models/LengowCart.php b/classes/models/LengowCart.php index 0382e74f..d8b3c4dd 100755 --- a/classes/models/LengowCart.php +++ b/classes/models/LengowCart.php @@ -118,7 +118,7 @@ public function updateQty( $useOrderPrices = false ) { if (!$shop instanceof Shop) { - $shop = Context::getContext()->shop; + $shop = LengowContext::getContext()->shop; } // this line are useless, but PrestaShop validator require it $autoAddCartRule = $autoAddCartRule; @@ -137,13 +137,8 @@ public function updateQty( } // if we have a product combination, the minimal quantity is set with the one of this combination if (!empty($idProductAttribute)) { - $version = defined('_PS_VERSION_') ? _PS_VERSION_ : ''; - // for PrestaShop 8.0 and higher - if (version_compare($version, '8.0.0.0', '>=') && !isset($skipAvailabilityCheckOutOfStock)) { - $minimalQuantity = (int) ProductAttribute::getAttributeMinimalQty($idProductAttribute); - } else { - $minimalQuantity = (int) Attribute::getAttributeMinimalQty($idProductAttribute); - } + $combination = new Combination((int) $idProductAttribute); + $minimalQuantity = (int) $combination->minimal_quantity; } else { $minimalQuantity = (int) $product->minimal_quantity; } @@ -241,7 +236,7 @@ public function updateQty( // refresh cache of self::_products $this->_products = $this->getProducts(true); $this->update(); - $context = Context::getContext()->cloneContext(); + $context = LengowContext::getContext()->cloneContext(); $context->cart = $this; Cache::clean('getContextualValue_*'); if ($product->customizable) { @@ -321,4 +316,77 @@ public function validateFieldLengow($fieldName, $errorType) $this->{$fieldName} = Context::getContext()->language->id; } } -} + + /** + * Check if a product is already in the cart + * + * @param int $idProduct PrestaShop product id + * @param int $idProductAttribute attribute id + * @param int $idCustomization customization id + * @param int $idAddressDelivery address delivery id + * + * @return array|false + */ + public function containsProduct($idProduct, $idProductAttribute = 0, $idCustomization = 0, $idAddressDelivery = 0) + { + $sql = 'SELECT * + FROM `' . _DB_PREFIX_ . 'cart_product` + WHERE `id_product` = ' . (int) $idProduct . ' + AND `id_product_attribute` = ' . (int) $idProductAttribute . ' + AND `id_cart` = ' . (int) $this->id; + + if (Configuration::get('PS_ALLOW_MULTISHIPPING') && $this->isMultiAddressDelivery()) { + $sql .= ' AND `id_address_delivery` = ' . (int) $idAddressDelivery; + } + + return Db::getInstance()->getRow($sql); + } + + /** + * Update customization quantity + * + * @param int $quantity quantity + * @param int $idCustomization customization id + * @param int $idProduct product id + * @param int $idProductAttribute attribute id + * @param int $idAddressDelivery address delivery id + * @param string $operator up or down + * + * @return bool + */ + protected function _updateCustomizationQuantity($quantity, $idCustomization, $idProduct, $idProductAttribute, $idAddressDelivery, $operator = 'up') + { + $sql = 'SELECT `quantity` + FROM `' . _DB_PREFIX_ . 'customization` + WHERE `id_customization` = ' . (int) $idCustomization . ' + AND `id_cart` = ' . (int) $this->id . ' + AND `id_product` = ' . (int) $idProduct . ' + AND `id_product_attribute` = ' . (int) $idProductAttribute; + + if ($result = Db::getInstance()->getRow($sql)) { + if ($operator == 'down') { + $newQuantity = (int) $result['quantity'] - (int) $quantity; + if ($newQuantity < 0) { + return false; + } + } else { + $newQuantity = (int) $result['quantity'] + (int) $quantity; + } + + if ($newQuantity == 0) { + return Db::getInstance()->execute( + 'DELETE FROM `' . _DB_PREFIX_ . 'customization` + WHERE `id_customization` = ' . (int) $idCustomization + ); + } + + return Db::getInstance()->execute( + 'UPDATE `' . _DB_PREFIX_ . 'customization` + SET `quantity` = ' . (int) $newQuantity . ' + WHERE `id_customization` = ' . (int) $idCustomization + ); + } + + return true; + } +} From 6abab37347cbeb8f12a7f5e85ff42d98a7068859 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 09:46:56 +0000 Subject: [PATCH 3/4] Fix: revert LengowContext to Context::getContext() - LengowContext does not exist on 3.x branch Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/bc2c8168-d6f3-4b59-96b3-8ec2c07bdb42 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com> --- classes/models/LengowCart.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/models/LengowCart.php b/classes/models/LengowCart.php index d8b3c4dd..539d9bb9 100755 --- a/classes/models/LengowCart.php +++ b/classes/models/LengowCart.php @@ -118,7 +118,7 @@ public function updateQty( $useOrderPrices = false ) { if (!$shop instanceof Shop) { - $shop = LengowContext::getContext()->shop; + $shop = Context::getContext()->shop; } // this line are useless, but PrestaShop validator require it $autoAddCartRule = $autoAddCartRule; @@ -236,7 +236,7 @@ public function updateQty( // refresh cache of self::_products $this->_products = $this->getProducts(true); $this->update(); - $context = LengowContext::getContext()->cloneContext(); + $context = Context::getContext()->cloneContext(); $context->cart = $this; Cache::clean('getContextualValue_*'); if ($product->customizable) { From aafcccbe89336caffe81dd9971585e38fb3d527e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 15 Apr 2026 10:11:20 +0000 Subject: [PATCH 4/4] Fix: remove containsProduct and _updateCustomizationQuantity overrides causing parse error on PHP 7.x Agent-Logs-Url: https://github.com/lengow/plugin-prestashop/sessions/2bd12b7d-2251-4035-af96-232578877075 Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com> --- classes/models/LengowCart.php | 73 ----------------------------------- 1 file changed, 73 deletions(-) diff --git a/classes/models/LengowCart.php b/classes/models/LengowCart.php index 539d9bb9..1d5edae1 100755 --- a/classes/models/LengowCart.php +++ b/classes/models/LengowCart.php @@ -316,77 +316,4 @@ public function validateFieldLengow($fieldName, $errorType) $this->{$fieldName} = Context::getContext()->language->id; } } - - /** - * Check if a product is already in the cart - * - * @param int $idProduct PrestaShop product id - * @param int $idProductAttribute attribute id - * @param int $idCustomization customization id - * @param int $idAddressDelivery address delivery id - * - * @return array|false - */ - public function containsProduct($idProduct, $idProductAttribute = 0, $idCustomization = 0, $idAddressDelivery = 0) - { - $sql = 'SELECT * - FROM `' . _DB_PREFIX_ . 'cart_product` - WHERE `id_product` = ' . (int) $idProduct . ' - AND `id_product_attribute` = ' . (int) $idProductAttribute . ' - AND `id_cart` = ' . (int) $this->id; - - if (Configuration::get('PS_ALLOW_MULTISHIPPING') && $this->isMultiAddressDelivery()) { - $sql .= ' AND `id_address_delivery` = ' . (int) $idAddressDelivery; - } - - return Db::getInstance()->getRow($sql); - } - - /** - * Update customization quantity - * - * @param int $quantity quantity - * @param int $idCustomization customization id - * @param int $idProduct product id - * @param int $idProductAttribute attribute id - * @param int $idAddressDelivery address delivery id - * @param string $operator up or down - * - * @return bool - */ - protected function _updateCustomizationQuantity($quantity, $idCustomization, $idProduct, $idProductAttribute, $idAddressDelivery, $operator = 'up') - { - $sql = 'SELECT `quantity` - FROM `' . _DB_PREFIX_ . 'customization` - WHERE `id_customization` = ' . (int) $idCustomization . ' - AND `id_cart` = ' . (int) $this->id . ' - AND `id_product` = ' . (int) $idProduct . ' - AND `id_product_attribute` = ' . (int) $idProductAttribute; - - if ($result = Db::getInstance()->getRow($sql)) { - if ($operator == 'down') { - $newQuantity = (int) $result['quantity'] - (int) $quantity; - if ($newQuantity < 0) { - return false; - } - } else { - $newQuantity = (int) $result['quantity'] + (int) $quantity; - } - - if ($newQuantity == 0) { - return Db::getInstance()->execute( - 'DELETE FROM `' . _DB_PREFIX_ . 'customization` - WHERE `id_customization` = ' . (int) $idCustomization - ); - } - - return Db::getInstance()->execute( - 'UPDATE `' . _DB_PREFIX_ . 'customization` - SET `quantity` = ' . (int) $newQuantity . ' - WHERE `id_customization` = ' . (int) $idCustomization - ); - } - - return true; - } }