Assign position in category on products import
new

By Reto von Rickenbach, 2 years ago

Hello. How is it possible to assign the position of a product in the category on products import (related records). There is no field mapping configuration available.

I found this in the products schema:

   public function beforeAssocCategory(&$values, $factory)
   {
       if (!isset($values['position'])) {
           $conn = $factory->getConnection();
           $idCategory = (int)$values['id_category'];
           $sql = "select IFNULL(MAX(position), 0) + 1 from " . _DB_PREFIX_ . "category_product where id_category = $idCategory";
           $position = (int)$conn->singleSelect($sql);
           $values['position'] = $position;
       }
   }

This resets the positions for the products in the categories, if position is not set. So I need to set it, otherwise the positions are wrong after importing products