Fix forceProduct not bypassing availability and stock checks in LengowCart::updateQty#77
Fix forceProduct not bypassing availability and stock checks in LengowCart::updateQty#77
forceProduct not bypassing availability and stock checks in LengowCart::updateQty#77Conversation
Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
forceProduct not bypassing stock check when product already in cart
|
Ton fix n'est pas pertinent la commande qui cause le probleme: product 1274 could not be added to cart. Make sure it is available to order or that there is enough in stock La commande en question n'a qu'un seule produit avec une quantité de 1: amazon_es17025ES408-0890382-7307518Unshippedwaiting_shipment52026-03-10T12:22:06Z4.950.000.00.00.00EUR€EuroEUR€Euro4.950.000.00.00.00376209Other: Standard122650161228408377642B01HMK60D6id1274101926Unshipped2026-03-11T22:59:59Zwaiting_shipmentWTF GEO-04 - Etiqueta engomada con Logos, diseño GeometríaInicio > Gadget > Accesorios Smartphonehttps://www.crosstalk.es/oferta/750-large_default/smart-sticker-adheunigeo4.jpgSecondDay2026-03-13T22:59:59ZFalse4.950.000.004.950.000.0011802825deliveryCARDENAL SILICEO 22 - MAGNETRON28002MADRIDES675899873675899873ANDRES HENNEQUETs06rbc4pngjycsp@marketplace.amazon.esa34c97944162d04701276409a9617c05MADRIDSecondDayFalse612284083776421802826billingCARDENAL SILICEO 22 - MAGNETRON28002MADRIDES675899873675899873ANDRES HENNEQUETs06rbc4pngjycsp@marketplace.amazon.esa34c97944162d04701276409a9617c05MADRID2026-03-10T13:19:51.434972Z2026-03-10T13:19:51.434972Z57fb59e86935b70c621d3a6c8f593964True2026-03-10T23:00:00ZTrue2026-03-12T23:00:00ZFalseFalseTrueFalseFalseTrueTrueFalse |
…eQty Co-authored-by: michaelmaslengow <147600733+michaelmaslengow@users.noreply.github.com>
Tu as raison, mon premier fix ne couvrait pas ce cas. Le vrai problème est dans la condition Avant (bugué) : if ((!$product->available_for_order && !$this->forceProduct)
|| (Configuration::get('PS_CATALOG_MODE') && !defined('_PS_ADMIN_DIR_'))
) {La vérification Après (corrigé, aligné avec l'original if ((!$product->available_for_order || (Configuration::get('PS_CATALOG_MODE') && !defined('_PS_ADMIN_DIR_')))
&& !$this->forceProduct
) {Fix dans le commit |
forceProduct not bypassing stock check when product already in cartforceProduct not bypassing availability and stock checks in LengowCart::updateQty
|
@copilot |
Oui et non. La configuration |
|
@copilot |
Ce bug n'affecte que les marchands qui ont Concrètement, voici ce qui se passe côté PrestaShop pour ce marchand lors d'un import Lengow :
Résultat : 100% des imports échouent pour ce marchand, quelle que soit la disponibilité du stock. |
|
DOnc je repete: le marchand peut corriger du coté Prestashop? |
Oui, le marchand peut contourner le problème en désactivant le mode catalogue dans son BO PrestaShop (Préférences > Produits > Mode catalogue = Non). Cela débloquerait immédiatement les imports. Cependant, ce n'est pas la bonne solution si le marchand utilise intentionnellement ce mode (ex : boutique en vitrine). Le fix dans ce PR est la correction appropriée : le plugin Lengow doit pouvoir importer des commandes indépendamment de cette configuration, c'est précisément l'objet du flag |
|
@copilot |
La vérification Le problème est que lors de la création de En résumé : la vérification a du sens dans le contexte PrestaShop pur, mais elle aurait dû être adaptée au contexte Lengow dès l'origine, ce que le fix dans ce PR corrige. |
|
@copilot |
Dans ce contexte, le marchand utilise ce mode pour désactiver les achats sur sa boutique front-office, mais ses commandes Amazon continuent d'arriver via Lengow. Le plugin doit pouvoir importer ces commandes indépendamment de ce paramètre, d'où l'existence du flag |
Order imports fail with "product could not be added to cart" even when stock is available in the back office.
Root Cause
Two bugs were found in
LengowCart::updateQty()whereforceProduct = true(set by default for Lengow imports) was not properly bypassing availability/stock checks:1.
PS_CATALOG_MODEnot bypassed byforceProduct(primary cause)The condition checking
available_for_orderandPS_CATALOG_MODEdid not guard the catalog mode check withforceProduct:When
PS_CATALOG_MODE = 1is enabled in the PrestaShop back office and the import runs in a cron/webhook context (where_PS_ADMIN_DIR_is not defined), this always returnedfalsefor every product — regardless offorceProduct = true. This matches the reported case: a single product with quantity 1 that has stock but cannot be added to cart.2. Stock check not bypassed when product already in cart
In the branch where the product already exists in the cart, the out-of-stock guard was incorrectly computed:
When
forceProduct = true,!$this->forceProductcollapses tofalse, makingisAvailableWhenOutOfStock(0)always returnfalse, which enforces stock unconditionally.Fix
Both conditions are now aligned with the original PrestaShop
Cart::updateQty()behavior, whereforceProduct = truebypasses all availability and stock checks:When
forceProduct = true, both conditions short-circuit immediately and all checks are skipped as intended.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.