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 lase that this script can be run on mysql script window using this command:
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | <?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(); |
1 2 3 4 5 | insert into `ps_warehouse_product` (`id_product`,`id_product_attribute`,`id_warehouse`) select p.id_product,0,2 from ps_product_attribute p;<br> 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 ; |