Example #1
0
 public function ajaxProcessUpdatePositions()
 {
     if ($this->tabAccess['edit'] === '1') {
         $way = (int) Tools::getValue('way');
         $id_product = (int) Tools::getValue('id_product');
         $id_category = (int) Tools::getValue('id_category');
         $positions = Tools::getValue('product');
         if (is_array($positions)) {
             foreach ($positions as $position => $value) {
                 $pos = explode('_', $value);
                 if (isset($pos[1]) && isset($pos[2]) && ($pos[1] == $id_category && (int) $pos[2] === $id_product)) {
                     if ($product = new Product((int) $pos[2])) {
                         if (isset($position) && $product->updatePosition($way, $position)) {
                             $category = new Category((int) $id_category);
                             if (Validate::isLoadedObject($category)) {
                                 hook::Exec('categoryUpdate', array('category' => $category));
                             }
                             echo 'ok position ' . (int) $position . ' for product ' . (int) $pos[2] . "\r\n";
                         } else {
                             echo '{"hasError" : true, "errors" : "Can not update product ' . (int) $id_product . ' to position ' . (int) $position . ' "}';
                         }
                     } else {
                         echo '{"hasError" : true, "errors" : "This product (' . (int) $id_product . ') can t be loaded"}';
                     }
                     break;
                 }
             }
         }
     }
 }
Example #2
0
        die('{"hasError" : true, "errors" : "This cms can not be loaded"}');
    }
}
/* Modify product position in catalog */
if (array_key_exists('ajaxProductsPositions', $_POST)) {
    $way = (int) Tools::getValue('way');
    $id_product = (int) Tools::getValue('id_product');
    $id_category = (int) Tools::getValue('id_category');
    $positions = Tools::getValue('product');
    if (is_array($positions)) {
        foreach ($positions as $position => $value) {
            // pos[1] = id_categ, pos[2] = id_product, pos[3]=old position
            $pos = explode('_', $value);
            if (isset($pos[1]) and isset($pos[2]) and ($pos[1] == $id_category and (int) $pos[2] === $id_product)) {
                if ($product = new Product((int) $pos[2])) {
                    if (isset($position) && $product->updatePosition($way, $position)) {
                        echo "ok position {$position} for product {$pos['2']}\r\n";
                    } else {
                        echo '{"hasError" : true, "errors" : "Can not update product ' . $id_product . ' to position ' . $position . ' "}';
                    }
                } else {
                    echo '{"hasError" : true, "errors" : "This product (' . $id_product . ') can t be loaded"}';
                }
                break;
            }
        }
    }
}
if (isset($_GET['ajaxProductPackItems'])) {
    $jsonArray = array();
    $products = Db::getInstance()->ExecuteS('