fburn Posted October 31, 2008 Share Posted October 31, 2008 re: Changing the price of products not through the product page.Our catalog has over 1000 products in it sourced from around 20 vendors and manufacturers. We received periodic price updates from those vendors due to currency and raw material spot market changes. (Our vendors are primarily located in Peru, China, India and the US.)It becomes very unwieldy to alter the prices through the product interface when you are changing 100+ products at once. Obviously it is possible to do it through the database, but if the changes are going to be made by someone without programmatic experience it becomes impossible.Most often we get blanket increases, say 10%. To resolve this I've created an admin tab, AdminPriceChange that is a sub-tab of AdminCategory. This allows you to specify any price change as a percent by manufacturer. I've shared it here if anyone is interested in using it.You will have to add the tab using the tab control interface under the tools tab. include_once(realpath(PS_ADMIN_DIR.'/../').'/classes/AdminTab.php'); /** * admin tab for the purpose of changing the price of a series of product by manufacturer * * @author: Finnian F Burn * @copyright Criterion Athletic 2008 **/ class AdminPriceChange extends AdminTab { public function postProcess() { //$val = Tools::getValue('price_change'); if (isset($_POST['price_change'])) { $manufacturer = Tools::getValue('id_manufacturer'); $change = Tools::getValue('change'); $sql = 'UPDATE '._DB_PREFIX_.'product SET price=price+price*'.($change/100).' WHERE id_manufacturer='.$manufacturer; $result = Db::getInstance()->Execute($sql); } // if parent::postProcess(true); } // postProcess() public function displayForm() { global $currentIndex; $val = Tools::getValue('price_change'); if (isset($_POST['price_change']) AND !sizeof($this->_errors)) echo ''.$this->l('The price has been changed').''; echo ' <form id="preview_import" action="'.$currentIndex.'&token;='.$this->token.'" method="post" class="width2" enctype="multipart/form-data" style="clear: both;"> '.$this->l('Change Prices').' '.$this->l('Manufacturer:').' '; $manufacturers = Manufacturer::getManufacturers(); if ($manufacturers) foreach ($manufacturers AS $manufacturer) echo 'getFieldValue($obj, 'id_manufacturer') == $manufacturer['id_manufacturer']) ? ' selected="selected"' : '').'> '.stripslashes($manufacturer['name']).''; echo ' '.$this->l('Price Change (%):').' <input name="change" type="text" value="0" size="2" /> <input name="price_change" type="submit" value="'.$this->l('Change Prices').'" class="button" /> </form>'; } public function display() { $this->displayForm(); } // display() } // class AdminPrice Link to comment Share on other sites More sharing options...
Matthieu Biart Posted November 3, 2008 Share Posted November 3, 2008 Hi again fburn!And thank you again for that contribution! You're :coolsmirk:Just two comments:1. You can do what you want (I mean update all product prices by one time) by using our CSV import tool which update product informations (including price) when products already exist.2. Attaching your php file to the topic we'll be easier "readable", put source code inside a post only when it concerns few lines ;-P Link to comment Share on other sites More sharing options...
adammontague Posted March 30, 2010 Share Posted March 30, 2010 This is brilliant and I really want to use it! However, when I input the price change I get the following error "Invalid security token"Any help appreciated.... Link to comment Share on other sites More sharing options...
Yogurtinsh Posted May 18, 2011 Share Posted May 18, 2011 maybe its possible update prices with xml file? Link to comment Share on other sites More sharing options...
Recommended Posts