/**
  * @desc Update category and items position.
  * @param Category $category
  * @param int $id_parent
  * @param int $position
  */
 public function update_position(Category $category, $id_parent, $position)
 {
     $id = $category->get_id();
     if ($this->get_categories_cache()->category_exists($id) && $this->get_categories_cache()->category_exists($id_parent) && !($category->get_id_parent() == $id_parent && $category->get_order() == $position)) {
         $options = new SearchCategoryChildrensOptions();
         $childrens = $this->get_childrens($id, $options);
         $childrens[$id] = $category;
         if (!array_key_exists($id_parent, $childrens)) {
             $max_order = $this->db_querier->get_column_value($this->table_name, 'MAX(c_order)', 'WHERE id_parent=:id_parent', array('id_parent' => $id_parent));
             $max_order = NumberHelper::numeric($max_order);
             if ($position <= 0 || $position > $max_order) {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $max_order + 1), 'WHERE id=:id', array('id' => $id));
             } else {
                 $this->db_querier->update($this->table_name, array('id_parent' => $id_parent, 'c_order' => $position), 'WHERE id=:id', array('id' => $id));
             }
             $this->regenerate_cache();
         }
     }
 }