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
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 ;