ezakimak Posted January 25, 2011 Share Posted January 25, 2011 Hi,I am starting to modify /classes/product.php in order to accomplish this, the reason.we have products with stock zero and the "allow orders when not available" preference to Yes.The thing is that product quantity is always zero in those cases, I need to give the possibility to have them negative in case there are more orders of a product X than products X available. that way when I update my stock (I have a script for that ) I would simply add the quantity to that product stock attribute, lets say, a product X would have quantity = -7 , then with my script I add 10 to it, the final stock should be 3. Currently I would have product X quantity = 0 , so to update it accurately I have to take into account the products already sold since the time the quantity became zero.So far , I changed tha tables ps_product and ps_product_attribute quantity to accpet negative values and modified the /classes/product.php fieldsvalidation quantity from isUnsignedInt to isInt. after that what would be necessary to do to make prestashop work with negative stockthanks for any helpHugh Link to comment Share on other sites More sharing options...
ezakimak Posted January 25, 2011 Author Share Posted January 25, 2011 Hi, me again I think I found the answer but I would like to have some input from you .I changed this method Product::updateQuantity I have commented what I think is preventing from allowing negative stock public static function updateQuantity($product) { if (!is_array($product)) die (Tools::displayError()); if (Pack::isPack(intval($product['id_product']))) { $products_pack = Pack::getItems(intval($product['id_product']), intval(Configuration::get('PS_LANG_DEFAULT'))); foreach($products_pack AS $product_pack) { $tab_product_pack['id_product'] = intval($product_pack->id); $tab_product_pack['id_product_attribute'] = self::getDefaultAttribute($tab_product_pack['id_product'], 1); $tab_product_pack['cart_quantity'] = intval($product_pack->pack_quantity * $product['cart_quantity']); self::updateQuantity($tab_product_pack); } } $result = Db::getInstance()->getRow(' SELECT `quantity` FROM `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'` WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : '')); if (!Configuration::get('PS_STOCK_MANAGEMENT')) return true; //if (self::isAvailableWhenOutOfStock($product['out_of_stock']) AND intval($result['quantity']) == 0) // return -1; // //if ($result['quantity'] < $product['cart_quantity']) //{ // Db::getInstance()->Execute(' // UPDATE `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'` // SET `quantity` = 0 // WHERE `id_product` = '.intval($product['id_product']).($product['id_product_attribute'] ? // ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : '')); // return false; //} Db::getInstance()->Execute(' UPDATE `'._DB_PREFIX_.'product'.($product['id_product_attribute'] ? '_attribute' : '').'` SET `quantity` = `quantity`-'.intval($product['cart_quantity']).' WHERE `id_product` = '.intval($product['id_product']). ($product['id_product_attribute'] ? ' AND `id_product_attribute` = '.intval($product['id_product_attribute']) : '')); return true; } Link to comment Share on other sites More sharing options...
ezakimak Posted January 25, 2011 Author Share Posted January 25, 2011 So far, negative values are allowed, but now I am facing the problem when a product is canceled from the order in BO, the stock is not updated properly. Link to comment Share on other sites More sharing options...
ezakimak Posted January 25, 2011 Author Share Posted January 25, 2011 I think changing /admin/tabs/adminorders.php , would solve the problem I mentioned above, but any feedback would be nice.I am checking if these changes work.in line around 211 from // Reinject product if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Tools::isSubmit('reinjectQuantities'))) { $reinjectableQuantity = intval($orderDetail->product_quantity_in_stock) - intval($orderDetail->product_quantity_reinjected); $quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct; to // Reinject product if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Tools::isSubmit('reinjectQuantities'))) { $reinjectableQuantity = intval($orderDetail->product_quantity) - intval($orderDetail->product_quantity_reinjected); $quantityToReinject = $qtyCancelProduct > $reinjectableQuantity ? $reinjectableQuantity : $qtyCancelProduct; Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now