Example #1
0
function reorderpositions()
{
    $cat = Category::getCategories(1, false, false);
    foreach ($cat as $i => $categ) {
        Product::cleanPositions(intval($categ['id_category']));
    }
}
function reorderpositions()
{
    /* Clean products positions */
    if ($cat = Category::getCategories(1, false, false)) {
        foreach ($cat as $i => $categ) {
            Product::cleanPositions((int) $categ['id_category']);
        }
    }
    //clean Category position and delete old position system
    Language::loadLanguages();
    $language = Language::getLanguages();
    $cat_parent = Db::getInstance()->ExecuteS('SELECT DISTINCT c.id_parent FROM `' . _DB_PREFIX_ . 'category` c WHERE id_category != 1');
    foreach ($cat_parent as $parent) {
        $result = Db::getInstance()->ExecuteS('
							SELECT DISTINCT c.*, cl.*
							FROM `' . _DB_PREFIX_ . 'category` c 
							LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . (int) Configuration::get('PS_LANG_DEFAULT') . ')
							WHERE c.id_parent = ' . (int) $parent['id_parent'] . '
							ORDER BY name ASC');
        foreach ($result as $i => $categ) {
            Db::getInstance()->Execute('
			UPDATE `' . _DB_PREFIX_ . 'category`
			SET `position` = ' . (int) $i . '
			WHERE `id_parent` = ' . (int) $categ['id_parent'] . '
			AND `id_category` = ' . (int) $categ['id_category']);
        }
        $result = Db::getInstance()->ExecuteS('
							SELECT DISTINCT c.*, cl.*
							FROM `' . _DB_PREFIX_ . 'category` c 
							LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category`)
							WHERE c.id_parent = ' . (int) $parent['id_parent'] . '
							ORDER BY name ASC');
        // Remove number from category name
        foreach ($result as $i => $categ) {
            Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'category` c 
			LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category`)
			SET `name` = \'' . preg_replace('/^[0-9]+\\./', '', $categ['name']) . '\' 
			WHERE c.id_category = ' . (int) $categ['id_category'] . ' AND id_lang = \'' . (int) $categ['id_lang'] . '\'');
        }
    }
    /* Clean CMS positions */
    if ($cms_cat = CMSCategory::getCategories(1, false, false)) {
        foreach ($cms_cat as $i => $categ) {
            CMS::cleanPositions((int) $categ['id_cms_category']);
        }
    }
}
Example #3
0
 public function cleanPositions($table, $shopList = null)
 {
     if ($table == 'category') {
         //clean category position
         $cat = Category::getCategories(1, false, false);
         foreach ($cat as $i => $categ) {
             Category::cleanPositions((int) $categ['id_category']);
         }
     }
     if ($table == 'product') {
         //clean products position
         $cat = Category::getCategories(1, false, false);
         foreach ($cat as $i => $categ) {
             Product::cleanPositions((int) $categ['id_category']);
         }
     }
 }
Example #4
0
 public function delete()
 {
     /*
      * @since 1.5.0
      * It is NOT possible to delete a product if there are currently:
      * - physical stock for this product
      * - supply order(s) for this product
      */
     if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $this->advanced_stock_management) {
         $stock_manager = StockManagerFactory::getManager();
         $physical_quantity = $stock_manager->getProductPhysicalQuantities($this->id, 0);
         $real_quantity = $stock_manager->getProductRealQuantities($this->id, 0);
         if ($physical_quantity > 0) {
             return false;
         }
         if ($real_quantity > $physical_quantity) {
             return false;
         }
     }
     $result = parent::delete();
     // Removes the product from StockAvailable, for the current shop
     StockAvailable::removeProductFromStockAvailable($this->id);
     $result &= $this->deleteProductAttributes() && $this->deleteImages() && $this->deleteSceneProducts();
     // If there are still entries in product_shop, don't remove completly the product
     if ($this->hasMultishopEntries()) {
         return true;
     }
     Product::cleanPositions($this->id);
     Hook::exec('actionProductDelete', array('product' => $this));
     if (!$result || !GroupReduction::deleteProductReduction($this->id) || !$this->deleteCategories(true) || !$this->deleteProductFeatures() || !$this->deleteTags() || !$this->deleteCartProducts() || !$this->deleteAttributesImpacts() || !$this->deleteAttachments() || !$this->deleteCustomization() || !SpecificPrice::deleteByProductId((int) $this->id) || !$this->deletePack() || !$this->deleteProductSale() || !$this->deleteSearchIndexes() || !$this->deleteAccessories() || !$this->deleteFromAccessories() || !$this->deleteFromSupplier() || !$this->deleteDownload() || !$this->deleteFromCartRules()) {
         return false;
     }
     return true;
 }