Luigi Donato Posted August 12, 2017 Share Posted August 12, 2017 Hi, I want to know where is located the function that update the quantity of products.. I need this because I have developed a management software and I want a sincronization of quantity by PrestaShop to my management software (PHP). Link to comment Share on other sites More sharing options...
Scully Posted August 12, 2017 Share Posted August 12, 2017 (edited) If we don't know a prestashop version it's always difficult to help. I would look at the files Order.php and OrderHistory.php located in the order path of the classes directory if V 1.6. is in question. Search for "stock" and you'll find the methods and classes used. Edited August 12, 2017 by Scully (see edit history) Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 13, 2017 Author Share Posted August 13, 2017 (edited) Yes, is version 1.6I've find this id Order.php, but I suppose that is to get the quantity.. Is correct?: $this->setProductCurrentStock($row); protected function setProductCurrentStock(&$product) { if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1 && (int)$product['id_warehouse'] > 0) { $product['current_stock'] = StockManagerFactory::getManager()->getProductPhysicalQuantities($product['product_id'], $product['product_attribute_id'], (int)$product['id_warehouse'], true); } else { $product['current_stock'] = StockAvailable::getQuantityAvailableByProduct($product['product_id'], $product['product_attribute_id'], (int)$this->id_shop); } } Edited August 13, 2017 by LuigiD (see edit history) 1 Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 13, 2017 Author Share Posted August 13, 2017 Where's the function updateQuantity..? This is used when the users take an order and when the admin update a product quantity..? Link to comment Share on other sites More sharing options...
Scully Posted August 13, 2017 Share Posted August 13, 2017 (edited) Have you looked in OrderHistory. There you see this commands: StockAvailable::updateQuantity Class: StockAvailable, method called: updateQuantity. Edited August 13, 2017 by Scully (see edit history) 1 Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 13, 2017 Author Share Posted August 13, 2017 Have you looked in OrderHistory. There you see this commands: StockAvailable::updateQuantity Class: StockAvailable, method called: updateQuantity. But is used when the users take an order and when the admin update a product quantity..? Link to comment Share on other sites More sharing options...
Scully Posted August 13, 2017 Share Posted August 13, 2017 This is used when a new order is placed. However I'd guess the exact same function is used when updating quantities manually by an admin. Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 13, 2017 Author Share Posted August 13, 2017 This is used when a new order is placed. However I'd guess the exact same function is used when updating quantities manually by an admin. Perfect ... I try to change it and try it .. After I let you know if it works .. In the meantime thank you :-) Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 14, 2017 Author Share Posted August 14, 2017 I've try to insert my code in function setQuantity and in function updateQuantity but this not work when modified from the ACP whenever I take an order as a customer.. :-( Link to comment Share on other sites More sharing options...
Scully Posted August 14, 2017 Share Posted August 14, 2017 I don't know what ACP is. Furthermore we cannot guess how you implemented changes and what exactely the should do. You can try to write debug messages to your logfile. The method PrestaShopLogger::addLog Would be the one to write logfiles to the prestashop database. You can see them from backoffice - advanced - log. Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 14, 2017 Author Share Posted August 14, 2017 (edited) I don't know what ACP is. Furthermore we cannot guess how you implemented changes and what exactely the should do. You can try to write debug messages to your logfile. The method PrestaShopLogger::addLog Would be the one to write logfiles to the prestashop database. You can see them from backoffice - advanced - log. Admin Control Panel.. I've try to insert a simple fwrite into this 2 funtions but not work..! Edited August 14, 2017 by LuigiD (see edit history) Link to comment Share on other sites More sharing options...
Scully Posted August 15, 2017 Share Posted August 15, 2017 If you put the code into your OrderHistory.php it won't work in the meaning of updating products. The order history was meant as hint to how finde the method used. Link to comment Share on other sites More sharing options...
musicmaster Posted August 15, 2017 Share Posted August 15, 2017 Admin Control Panel.. I've try to insert a simple fwrite into this 2 funtions but not work..! I get the impression that you don't use the classes correctly. So it should help if you showed some code that shows how you handle this. I would almost never use fwrite for debug. You never know in which directory it will write something. In 99% of the case an echo will work much better. Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 16, 2017 Author Share Posted August 16, 2017 I get the impression that you don't use the classes correctly. So it should help if you showed some code that shows how you handle this. I would almost never use fwrite for debug. You never know in which directory it will write something. In 99% of the case an echo will work much better. I've tried with echo but don't work.. Example: public static function updateQuantity($id_product, $id_product_attribute, $delta_quantity, $id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } $product = new Product((int)$id_product); if (!Validate::isLoadedObject($product)) { return false; } $stockManager = Adapter_ServiceLocator::get('Core_Business_Stock_StockManager'); $stockManager->updateQuantity($product, $id_product_attribute, $delta_quantity, $id_shop); return true; echo "dsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsa"; } And this: public static function setQuantity($id_product, $id_product_attribute, $quantity, $id_shop = null) { if (!Validate::isUnsignedId($id_product)) { return false; } $context = Context::getContext(); // if there is no $id_shop, gets the context one if ($id_shop === null && Shop::getContext() != Shop::CONTEXT_GROUP) { $id_shop = (int)$context->shop->id; } $depends_on_stock = StockAvailable::dependsOnStock($id_product); //Try to set available quantity if product does not depend on physical stock if (!$depends_on_stock) { $id_stock_available = (int)StockAvailable::getStockAvailableIdByProductId($id_product, $id_product_attribute, $id_shop); if ($id_stock_available) { $stock_available = new StockAvailable($id_stock_available); $stock_available->quantity = (int)$quantity; $stock_available->update(); } else { $out_of_stock = StockAvailable::outOfStock($id_product, $id_shop); $stock_available = new StockAvailable(); $stock_available->out_of_stock = (int)$out_of_stock; $stock_available->id_product = (int)$id_product; $stock_available->id_product_attribute = (int)$id_product_attribute; $stock_available->quantity = (int)$quantity; if ($id_shop === null) { $shop_group = Shop::getContextShopGroup(); } else { $shop_group = new ShopGroup((int)Shop::getGroupFromShop((int)$id_shop)); } // if quantities are shared between shops of the group if ($shop_group->share_stock) { $stock_available->id_shop = 0; $stock_available->id_shop_group = (int)$shop_group->id; } else { $stock_available->id_shop = (int)$id_shop; $stock_available->id_shop_group = 0; } $stock_available->add(); } Hook::exec('actionUpdateQuantity', array( 'id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $stock_available->quantity ) ); } Cache::clean('StockAvailable::getQuantityAvailableByProduct_'.(int)$id_product.'*'); echo "dsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsadsafdsafffdsdsdafsadffsa"; } Link to comment Share on other sites More sharing options...
Scully Posted August 16, 2017 Share Posted August 16, 2017 (edited) Everybody roll back a bit. In my very early post I stated that I have guessed the mentionned method StockAvailable::updateQuantity is used. Why: The very first post gave only little information on what was intended. Only some posts later we got the information that the update should be triggered by the backoffice edit product / update quantity function. So by using the normal order flow with order states and quantity management enabled, the changes should work. However I still wouldn't use neither echo nor fwrite. Some functions reload pages after processing. If the do so, you loose your debug information. In terms of cross checking the update mechanisms from update products I recommend to investigate the controller AdminProductsController.php and also the Products.php class. Edited August 16, 2017 by Scully (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted August 16, 2017 Share Posted August 16, 2017 I've tried with echo but don't work.. Example: Looks like the code never comes there. Try the die() function to be sure. Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 17, 2017 Author Share Posted August 17, 2017 (edited) Everybody roll back a bit. In my very early post I stated that I have guessed the mentionned method StockAvailable::updateQuantity is used. Why: The very first post gave only little information on what was intended. Only some posts later we got the information that the update should be triggered by the backoffice edit product / update quantity function. So by using the normal order flow with order states and quantity management enabled, the changes should work. However I still wouldn't use neither echo nor fwrite. Some functions reload pages after processing. If the do so, you loose your debug information. In terms of cross checking the update mechanisms from update products I recommend to investigate the controller AdminProductsController.php and also the Products.php class. In the AdminProductsController.php I've find the StockAvailable::setQuantity function.. Nothing else caught my attention. Please help me Edited August 17, 2017 by LuigiD (see edit history) Link to comment Share on other sites More sharing options...
musicmaster Posted August 17, 2017 Share Posted August 17, 2017 I still have no idea what you are doing. I asked you for the code that you wrote and instead you gave me the code that is in PS source code. Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 18, 2017 Author Share Posted August 18, 2017 Sorry but unfortunately I do not understand English to perfection, as I do not write it to perfection. What I need is to find the function that takes care of updating product quantities when they are modified or when a sale is made. This is why I have external software to manage the warehouse and I would like to keep the quantities synchronized, so that if a product is sold on the e-commerce then it is not resold to the counter Link to comment Share on other sites More sharing options...
Scully Posted August 18, 2017 Share Posted August 18, 2017 (edited) You english is good enough - don't worry about that. You should rather worry about your development skills an approaches. I opend the class file StockAvailable.php which I mentionned in my very first post. I then quickly determined that there are two functions coming into question. StockAvailable::updateQuantity and StockAvailable::setQuantity I then added very simple debugs to database commands to both functions right after their init. It turned out that setQuantity is triggered from products quantity manual update by back end and updateQuantity is triggered by placing or cancelling orders. Why don't you simply follow the advices you have been given ?? If you need a debug statements - they are for free because it's friday: For the Update: PrestaShopLogger::addLog("DEBUG updateQuantity : $id_product : $delta_quantity : ", 1, null); For the Set: PrestaShopLogger::addLog("DEBUG setQuantity : $id_product : $id_product_attribute : $quantity : ", 1, null); Edited August 18, 2017 by Scully (see edit history) 1 Link to comment Share on other sites More sharing options...
Luigi Donato Posted August 18, 2017 Author Share Posted August 18, 2017 Ok.. Problem solved..!Thank you to all Link to comment Share on other sites More sharing options...
Scully Posted August 18, 2017 Share Posted August 18, 2017 finally it came to an end. Please mark the topic as solved. 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