Jump to content

[Contribution] Changing product price (currently by manufacturer)


Recommended Posts

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

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

  • 1 year later...
  • 1 year later...
×
×
  • Create New...