Thursday, February 25, 2016

Prestashop Affectation tous les produits à un entrepot | Warehouse product affectation

In prestashop if we want to affect all products to one warehouse automatically, we ca use this little snippet.
Note that you have to backup warehouse_product_location table before any data modification.
You have to change id_warehouse=> XXX with the new warehouse id
The script is launches two instructions : 1- Affect simple product to warehouse then 2- Affect products with combinations to warehouse
 
<?php
/* 
 * Wassim JIED
 * coderspirit.blogspot.com (2016)
 * Well made in 619
 */ header("Cache-Control: no-cache, must-revalidate");
     require_once(dirname(__FILE__).'/config/config.inc.php');
  function processMoveToWareHouse()
 {      
  
   Logger::addLog('Affecting warehouses',1);
   $sql = 'SELECT id_product FROM '._DB_PREFIX_.'product';
   echo 'running : '.$sql .'
';
   if ($results = Db::getInstance()->ExecuteS($sql))
   foreach ($results as $row){
    Db::getInstance()->insert('warehouse_product_location', array(
    'id_product' => (int)$row['id_product'],
    'id_product_attribute' => 0,
    'id_warehouse'=> 2
    ));
   }
   Logger::addLog('Done with products without combinations ... gonna continue',1);
   
   
   $sql = 'SELECT id_product,id_product_attribute FROM '._DB_PREFIX_.'product_attribute';
   echo 'running : '.$sql .'
';
   if ($results = Db::getInstance()->ExecuteS($sql))
   foreach ($results as $row){
    Db::getInstance()->insert('warehouse_product_location', array(
    'id_product' => (int)$row['id_product'],
    'id_product_attribute' => (int)$row['id_product_attribute'],
    'id_warehouse'=> 2
    ));
   }
   Logger::addLog('Done with warehouses... going to die',1);


  
  die('OK');
     }
  processMoveToWareHouse();
  
Note lase that this script can be run on mysql script window using this command:
 
  insert into `ps_warehouse_product` (`id_product`,`id_product_attribute`,`id_warehouse`) 
    select p.id_product,0,2 from ps_product_attribute p;
insert into `ps_warehouse_product_location` (`id_product`,`id_product_attribute`,`id_warehouse`) select pa.id_product,pa.id_product_attribute,2 from ps_product_attribute pa ;

1 comment:

  1. I was curious if you ever thought of changing the structure of your website?

    Its very well written; I love what youve got to say.
    But maybe you could a little more in the way of content so people could connect with it better.
    Youve got an awful lot of text for only having 1 or two pictures.

    Maybe you could space it out better?

    ReplyDelete