Пример #1
0
 public function update($null_values = false)
 {
     if (Tools::isSubmit('submitAddcategoryAndBackToParent')) {
         $checked_artists_id = array();
         foreach ($_POST as $key => $val) {
             $hasString = strpos($key, 'related_artists');
             if ($hasString !== false) {
                 $checked_artists_id[] = $val;
             }
         }
         $serialize_artists = serialize($checked_artists_id);
         $this->related_artists[1] = $serialize_artists;
     }
     if ($this->id_parent == $this->id) {
         throw new PrestaShopException('a category cannot be its own parent');
     }
     if ($this->is_root_category && $this->id_parent != (int) Configuration::get('PS_ROOT_CATEGORY')) {
         $this->is_root_category = 0;
     }
     // Update group selection
     $this->updateGroup($this->groupBox);
     $this->level_depth = $this->calcLevelDepth();
     // If the parent category was changed, we don't want to have 2 categories with the same position
     $changed = $this->getDuplicatePosition();
     if ($changed) {
         if (Tools::isSubmit('checkBoxShopAsso_category')) {
             foreach (Tools::getValue('checkBoxShopAsso_category') as $id_asso_object => $row) {
                 foreach ($row as $id_shop => $value) {
                     $this->addPosition(Category::getLastPosition((int) $this->id_parent, (int) $id_shop), (int) $id_shop);
                 }
             }
         } else {
             foreach (Shop::getShops(true) as $shop) {
                 $this->addPosition(max(1, Category::getLastPosition((int) $this->id_parent, $shop['id_shop'])), $shop['id_shop']);
             }
         }
     }
     $ret = parent::update($null_values);
     if ($changed && (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree)) {
         $this->cleanPositions((int) $this->id_parent);
         Category::regenerateEntireNtree();
         $this->recalculateLevelDepth($this->id);
     }
     Hook::exec('actionCategoryUpdate', array('category' => $this));
     return $ret;
 }
Пример #2
0
 public function initContent()
 {
     if (!$this->errors) {
         $lampStart = 0;
         $lampLimit = 5;
         $lampOrderBy = 'id_product';
         $lampOrderWay = 'ASC';
         $lampOnlyActive = true;
         $lampIdCategory = 42;
         $id_lang = (int) $this->context->language->id;
         $lampIdCategories = CategoryCore::getChildren($lampIdCategory, $id_lang);
         Product::getProducts($id_lang, $lampStart, $lampLimit, $lampOrderBy, $lampOrderWay, $lampIdCategory, $lampOnlyActive);
         $prod = $this->product;
         $this->context->smarty->assign(array('HOOK_LAMP_ACCESSORIES' => Hook::exec('lampAccessories')));
     }
     parent::initContent();
     $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
 }
Пример #3
0
    public static function getNestedCategories($root_category = null, $id_lang = false, $active = true, $groups = null, $use_shop_restriction = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')
    {
        global $cookie;
        if (!Module::isInstalled('agilemultipleseller')) {
            return parent::getNestedCategories($root_category, $id_lang, $active, $groups, $use_shop_restriction, $sql_filter, $sql_sort, $sql_limit);
        }
        if (isset($root_category) && !Validate::isInt($root_category)) {
            die(Tools::displayError());
        }
        if (!Validate::isBool($active)) {
            die(Tools::displayError());
        }
        if (isset($groups) && Group::isFeatureActive() && !is_array($groups)) {
            $groups = (array) $groups;
        }
        if (intval($cookie->profile) == 0) {
            $cache_id = 'Category::getNestedCategories_' . md5((int) $root_category . (int) $id_lang . (int) $active . (int) $active . (isset($groups) && Group::isFeatureActive() ? implode('', $groups) : ''));
        } else {
            $cache_id = 'Category::getNestedCategories_' . md5((int) $cookie->id_customer . (int) $root_category . (int) $id_lang . (int) $active . (int) $active . (isset($groups) && Group::isFeatureActive() ? implode('', $groups) : ''));
        }
        if (!Cache::isStored($cache_id)) {
            $result = Db::getInstance()->executeS('
				SELECT c.*, cl.*
				FROM `' . _DB_PREFIX_ . 'category` c
				' . ($use_shop_restriction ? Shop::addSqlAssociation('category', 'c') : '') . '
				LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON c.`id_category` = cl.`id_category`' . Shop::addSqlRestrictionOnLang('cl') . '
				' . (isset($groups) && Group::isFeatureActive() ? 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON c.`id_category` = cg.`id_category`' : '') . '
				' . (isset($root_category) ? 'RIGHT JOIN `' . _DB_PREFIX_ . 'category` c2 ON c2.`id_category` = ' . (int) $root_category . ' AND c.`nleft` >= c2.`nleft` AND c.`nright` <= c2.`nright`' : '') . '
				WHERE 1 ' . $sql_filter . ' ' . ($id_lang ? 'AND `id_lang` = ' . (int) $id_lang : '') . '
				' . ($active ? ' AND c.`active` = 1' : '') . '
				' . (isset($groups) && Group::isFeatureActive() ? ' AND cg.`id_group` IN (' . implode(',', $groups) . ')' : '') . '
				' . (!$id_lang || isset($groups) && Group::isFeatureActive() ? ' GROUP BY c.`id_category`' : '') . '
				' . ($sql_sort != '' ? $sql_sort : ' ORDER BY c.`level_depth` ASC') . '
				' . ($sql_sort == '' && $use_shop_restriction ? ', category_shop.`position` ASC' : '') . '
				' . ($sql_limit != '' ? $sql_limit : ''));
            $categories = array();
            $buff = array();
            if (!isset($root_category)) {
                $root_category = 1;
            }
            foreach ($result as $row) {
                $current =& $buff[$row['id_category']];
                $current = $row;
                if ($row['id_category'] == $root_category) {
                    $categories[$row['id_category']] =& $current;
                } else {
                    $buff[$row['id_parent']]['children'][$row['id_category']] =& $current;
                }
            }
            Cache::store($cache_id, $categories);
        }
        return Cache::retrieve($cache_id);
    }
Пример #4
0
 
 //Update an existing product or Create a new one 
 $resources->reference = $product_xml->ItemNumber;
 $resources->price = floatval($product_xml->BasePrice);
 $resources->wholesale_price = floatval($product_xml->LowestPrice);
 $category = CategoryCore::searchByName(1, $product_xml->Category);
 
 if(!isset($category[0]['id_category'])){
     $category_id = add_new_category($product_xml->Category,34);
 }
 else{
     $category_id = $category[0]['id_category'];
 }
 
 if($product_xml->Category != $product_xml->SubCategory){
      $sub_category = CategoryCore::searchByName(1, $product_xml->SubCategory);
     if(!isset($sub_category[0]['id_category'])){
         $sub_category_id = add_new_category($product_xml->SubCategory,$category_id);
     }
     else{
         $sub_category_id = $sub_category[0]['id_category'];
     }
     $resources->associations->categories->addChild('categories')->addChild('id',intval($sub_category_id));
     $resources->id_category_default = intval($sub_category_id);        
 }
 else{
     $resources->id_category_default = intval($category_id);
 }
 $resources->associations->categories->addChild('categories')->addChild('id',intval($category_id));
     
 
Пример #5
0
 public function duplicateProduct($productId, $namePattern = 'copy of %s')
 {
     //TODO : use the $namePattern var to input translated version of 'copy of %s', if translation requested.
     $product = new \ProductCore($productId);
     if (!\ValidateCore::isLoadedObject($product)) {
         throw new \Exception('AdminProductDataUpdater->duplicateProduct() received an unknown ID.', 5005);
     }
     $id_product_old = $product->id;
     if (empty($product->price) && \ShopCore::getContext() == \ShopCore::CONTEXT_GROUP) {
         $shops = \ShopGroupCore::getShopsFromGroup(\ShopCore::getContextShopGroupID());
         foreach ($shops as $shop) {
             if ($product->isAssociatedToShop($shop['id_shop'])) {
                 $product_price = new \ProductCore($id_product_old, false, null, $shop['id_shop']);
                 $product->price = $product_price->price;
             }
         }
     }
     unset($product->id);
     unset($product->id_product);
     $product->indexed = 0;
     $product->active = 0;
     // change product name to prefix it
     foreach ($product->name as $langKey => $oldName) {
         if (!preg_match('/^' . str_replace('%s', '.*', preg_quote($namePattern, '/') . '$/'), $oldName)) {
             $newName = sprintf($namePattern, $oldName);
             if (mb_strlen($newName, 'UTF-8') <= 127) {
                 $product->name[$langKey] = $newName;
             }
         }
     }
     if ($product->add() && \CategoryCore::duplicateProductCategories($id_product_old, $product->id) && \ProductCore::duplicateSuppliers($id_product_old, $product->id) && ($combination_images = \ProductCore::duplicateAttributes($id_product_old, $product->id)) !== false && \GroupReductionCore::duplicateReduction($id_product_old, $product->id) && \ProductCore::duplicateAccessories($id_product_old, $product->id) && \ProductCore::duplicateFeatures($id_product_old, $product->id) && \ProductCore::duplicateSpecificPrices($id_product_old, $product->id) && \PackCore::duplicate($id_product_old, $product->id) && \ProductCore::duplicateCustomizationFields($id_product_old, $product->id) && \ProductCore::duplicateTags($id_product_old, $product->id) && \ProductCore::duplicateDownload($id_product_old, $product->id)) {
         if ($product->hasAttributes()) {
             \ProductCore::updateDefaultAttribute($product->id);
         }
         if (!\Image::duplicateProductImages($id_product_old, $product->id, $combination_images)) {
             throw new DataUpdateException('product', $id_product_old, 'An error occurred while copying images.', 5008);
         } else {
             $this->hookDispatcher->dispatchForParameters('actionProductAdd', array('id_product' => (int) $product->id, 'product' => $product));
             if (in_array($product->visibility, array('both', 'search')) && \Configuration::get('PS_SEARCH_INDEXATION')) {
                 \SearchCore::indexation(false, $product->id);
             }
             return $product->id;
         }
     } else {
         throw new \Exception('An error occurred while creating an object.', 5009);
     }
 }
Пример #6
0
        $prdID=(int)ProductCore::getProductIdByReference($product_xml->ItemNumber);
		if($prdID<477)
			continue;
        //Update an existing product or Create a new one 
        $resources->reference = $product_xml->ItemNumber;
        $resources->price = floatval($product_xml->BasePrice);
        $resources->wholesale_price = floatval($product_xml->LowestPrice);
        $category = CategoryCore::searchByNameAndParentCategoryId(1, $product_xml->Category,12);
        if(!isset($category['id_category'])){
            $category_id = add_new_category($product_xml->Category,12);
        }
        else{
            $category_id = $category['id_category'];
        }
        
        $sub_category = CategoryCore::searchByNameAndParentCategoryId(1, $product_xml->SubCategory,$category_id);
        if(!isset($sub_category['id_category'])){
           $sub_category_id = add_new_category($product_xml->SubCategory,$category_id);
       }
       else{
           $sub_category_id = $sub_category['id_category'];
       }
       $resources->associations->categories->addChild('categories')->addChild('id',intval($sub_category_id));
       $resources->id_category_default = intval($sub_category_id);        

        $resources->associations->categories->addChild('categories')->addChild('id',intval($category_id));
            
        //var_dump($sub_category_id,$category_id);
        $resources->item_number = $product_xml->ItemNumber;
        $parameter = array("ItemNumber"=>$product_xml->ItemNumber,
			"key"=>"8770471727");
Пример #7
0
 /**
  * Return available categories Names - excluding Root category
  *
  * @param int|null $root_category
  * @param bool|int $id_lang
  * @param bool $active return only active categories
  * @param $groups
  * @param bool $use_shop_restriction
  * @param string $sql_filter
  * @param string $sql_sort
  * @param string $sql_limit
  * @return array Categories
  */
 public function getAllCategoriesName($root_category = null, $id_lang = false, $active = true, $groups = null, $use_shop_restriction = true, $sql_filter = '', $sql_sort = '', $sql_limit = '')
 {
     $categories = \CategoryCore::getAllCategoriesName($root_category, $id_lang, $active, $groups, $use_shop_restriction, $sql_filter, $sql_sort, $sql_limit);
     array_shift($categories);
     return $categories;
 }
Пример #8
0
    public function hookOrderConfirmation($params)
    {
        $context = Context::getContext();
        $id_card = $context->cart->id;
        $id_order = Order::getOrderByCartId(intval($id_cart));
        $order = $params['objOrder'];
        $products = $order->getProducts();
        $dl = '<script>
   		$(window).load(function() {
	window.dataLayer.push({
	    "ecommerce": {
	        "purchase": {
	            "actionField": {
	                "id" : "' . $order->id . '",
	            },
	            "products": [';
        foreach ($products as $product) {
            //id_manufacturer
            //id_category_default
            //product_attribute_id
            $price = $product['total_price'];
            $revenue = $price / 100 * 20;
            $brand = ManufacturerCore::getNameById($product['id_manufacturer']);
            $name = ProductCore::getProductName($product['product_id']);
            $category = CategoryCore::getUrlRewriteInformations($product['id_category_default']);
            $variant = $this->getAttributeName($product['product_attribute_id']);
            $dl .= '{
	                    "id": "' . $product['product_id'] . '",
	                    "name": "' . $name . '",
	                    "price": ' . $price . ',
	                    "brand": "' . $brand . '",
	                    "category": "' . $category[0]['link_rewrite'] . '",
	                    "variant": "' . $variant . '",
	                    "quantity": ' . $product['product_quantity'] . ',
	                    "revenue": ' . $revenue . ',
	                    "shipping": ' . $order->total_shipping . '
	                },';
        }
        $dl .= ']
	        }
	    }
	});
	';
        foreach ($products as $product) {
            $price = $product['total_price'];
            $revenue = $price / 100 * 20;
            $name = ProductCore::getProductName($product['product_id']);
            $category = CategoryCore::getUrlRewriteInformations($product['id_category_default']);
            $brand = ManufacturerCore::getNameById($product['id_manufacturer']);
            $variant = $this->getAttributeName($product['product_attribute_id']);
            $dl .= '/* ga("ec:addProduct", {
				  "id": "' . $product['product_id'] . '",
				  "name": "' . $name . '",
				  "category": "' . $category[0]['link_rewrite'] . '",
				  "brand": "' . $brand . '",
				  "variant": "' . $variant . '",
				  "price": "' . $price . '",
				  "quantity": ' . $product['product_quantity'] . '
				});
				';
        }
        $dl .= 'ga("ec:setAction", "purchase", {
		  "id" : "' . $order->id . '",
		  "affiliation": location.hosts,
		  "revenue": "' . $order->total_paid_real . '",
		  "shipping": "' . $order->total_shipping . '"
		});

		ga("send", "pageview");
   		})*/; 
   		</script>';
        return $dl;
    }
Пример #9
0
 public function deleteLite()
 {
     // Directly call the parent of delete, in order to avoid recursion
     return parent::delete();
 }
Пример #10
0
 /**
  * Generate preview URL
  *
  * @param object $product
  * @param bool $preview
  *
  * @return string preview url
  */
 public function getPreviewUrl($product, $preview = true)
 {
     $context = \ContextCore::getContext();
     $id_lang = \ConfigurationCore::get('PS_LANG_DEFAULT', null, null, $context->shop->id);
     if (!\ShopUrlCore::getMainShopDomain()) {
         return false;
     }
     $is_rewrite_active = (bool) \ConfigurationCore::get('PS_REWRITING_SETTINGS');
     $preview_url = $context->link->getProductLink($product, $product->link_rewrite[$context->language->id], \CategoryCore::getLinkRewrite($product->id_category_default, $context->language->id), null, $id_lang, (int) $context->shop->id, 0, $is_rewrite_active);
     if (!$product->active && $preview) {
         $preview_url = $this->getPreviewUrlDeactivate($preview_url);
     }
     return $preview_url;
 }
Пример #11
0
 public function hookLampAccessories(&$params)
 {
     $la_itemcount = Configuration::get('LAMPACCESSORIES_ITEMCOUNT');
     if (empty($la_itemcount)) {
         $la_itemcount = 4;
         Configuration::set('LAMPACCESSORIES_ITEMCOUNT', 4);
     }
     $la_tabcount = Configuration::get('LAMPACCESSORIES_TABCOUNT');
     if (empty($la_tabcount)) {
         $la_tabcount = 4;
         Configuration::set('LAMPACCESSORIES_TABCOUNT', 4);
     }
     $context = Context::getContext();
     $controller = $context->controller;
     $id_lang = (int) $context->language->id;
     /**
      * @var $prod Product
      */
     $prod = $controller->getProduct();
     if (empty($prod)) {
         return '';
     }
     $features = $prod->getFeatures($id_lang);
     $id_feature_value = null;
     $id_feature_values = array();
     $power_ids = array(152, 28, 87, 7, 183, 64, 270, 22, 247, 253, 267, 217, 298, 231, 209);
     $sql = "SELECT v.*, l.*, l_n.id_feature_value AS id_feature_value_n, v_n.id_feature AS id_feature2\nFROM `ps_feature_value` v\nJOIN ps_feature_value_lang l\n\tON l.`id_feature_value` = v.`id_feature_value`\nAND l.id_lang = 1\nAND id_feature = 15\nJOIN ps_feature_value_lang l_n\n  ON l_n.value = l.value\nJOIN ps_feature_value v_n\n  ON v_n.id_feature_value = l_n.id_feature_value\n  AND v_n.id_feature IN (41, 42, 40)\n      ";
     $lampTypeFVs = Db::getInstance()->executeS($sql);
     $lampTypeN_Values = array();
     //id_feature для тип лампочки 1,2,3 (id_feature 40-42) => id_feature для тип лампы (id_feature 15)
     foreach ($lampTypeFVs as $ltfv) {
         $lampTypeN_Values[$ltfv['id_feature_value_n']][] = $ltfv['id_feature_value'];
     }
     foreach ($features as $feature) {
         if ($feature['id_feature'] == 16) {
             //Тип цоколя
             $id_feature_value = $feature['id_feature_value'];
             $id_feature_values[] = $feature['id_feature_value'];
         }
         if (in_array($feature['id_feature'], array(40, 41, 42))) {
             //Тип лампы 1,2,3
             if (!isset($id_feature_values[15])) {
                 $id_feature_values[15] = array();
             }
             $id_feature_value = $lampTypeN_Values[$feature['id_feature_value']];
             $id_feature_values[15] = array_merge($id_feature_values[15], $lampTypeN_Values[$feature['id_feature_value']]);
             //15 - Тип лампы
         }
         if ($feature['id_feature'] == 14) {
             //Мощность лампы
             $power_ind = array_search($feature['id_feature_value'], $power_ids);
             if ($power_ind === false) {
                 $id_feature_values[] = $feature['id_feature_value'];
             } else {
                 $id_feature_values[] = array_slice($power_ids, $power_ind);
             }
         }
         //      if($feature['id_feature'] == 38) { //Класс лампы
         //        $id_feature_values[] = $feature['id_feature_value'];
         //      }
         if ($feature['id_feature'] == 43) {
             //Код лампочек
             $id_feature_values[] = $feature['id_feature_value'];
         }
     }
     if (empty($id_feature_value)) {
         return '';
     }
     $lampIdCategory = 42;
     $lampIdCategories = array($lampIdCategory);
     $lampCategories = CategoryCore::getChildren($lampIdCategory, $id_lang);
     foreach ($lampCategories as $lampCategory) {
         $lampIdCategories[] = $lampCategory['id_category'];
     }
     $sCatIds = join(', ', $lampIdCategories);
     // $sCatIds=$prod->id_category_default;
     $sIdFeatureValues = join(', ', $id_feature_values);
     $sIdFeatureValues = '';
     $id_feature_values_count = count($id_feature_values);
     $i = 0;
     foreach ($id_feature_values as $id_fv) {
         //      $id_fv = $id_feature_values[$i];
         $sIdFeatureValues .= "\n      JOIN ps_feature_product f{$i}\n        ON f{$i}.id_product = p.id_product\n          AND f{$i}.id_feature_value " . (is_array($id_fv) ? " IN (" . join(', ', $id_fv) . ") " : " = {$id_fv}") . "\n";
         $i++;
     }
     //    $sql = "SELECT p.*, pl.*, cl.name AS category, f.*, i.id_image
     $sql = "SELECT p.*, pl.*, cl.name AS category, i.id_image\n      FROM ps_product p\n      JOIN ps_product_lang pl ON pl.id_product = p.id_product AND pl.id_lang={$id_lang}\n      JOIN ps_category_lang cl ON cl.id_category=p.id_category_default AND cl.id_lang={$id_lang}\n      {$sIdFeatureValues}\n      LEFT JOIN ps_image i\n        ON i.id_product = p.id_product\n          AND i.cover=1\n      WHERE p.id_category_default IN ({$sCatIds}) AND p.active=1\n      ORDER BY  p.price DESC\n      ";
     if ($_REQUEST['debug'] == 2) {
         echo $sql;
         print_r($lampTypeN_Values);
         print_r($id_feature_values);
         echo "\nsIdFeatureValues = {$sIdFeatureValues}";
     }
     //    $sql = "SELECT p.*, pl.*, cl.name AS category, i.id_image
     //      FROM ps_product p
     //      JOIN ps_product_lang pl ON pl.id_product = p.id_product AND pl.id_lang={$id_lang}
     //      JOIN ps_category_lang cl ON cl.id_category=p.id_category_default AND cl.id_lang={$id_lang}
     //      JOIN ps_feature_product f
     //        ON f.id_product = p.id_product
     //          AND f.id_feature_value = {$id_feature_value}
     //      LEFT JOIN ps_image i
     //        ON i.id_product = p.id_product
     //          AND i.cover=1
     //      WHERE p.id_category_default IN ($sCatIds) AND p.active=1
     //      ORDER BY  p.price DESC
     //      ";
     $lampAccessoriesAll = Db::getInstance()->executeS($sql);
     $lampAccessories = array();
     $lampAccessoriesCount = array();
     foreach ($lampAccessoriesAll as $lampAccessory) {
         if (count($lampAccessories[$lampAccessory['category']]) >= $la_itemcount) {
             continue;
         }
         $imageLink = Link::getImageLink($lampAccessory['link_rewrite'], $lampAccessory['id_image']);
         $productLink = $context->link->getProductLink($lampAccessory);
         $lampAccessory['url'] = $productLink;
         $lampAccessory['image_link'] = 'http://' . $imageLink;
         $lampAccessories[$lampAccessory['category']][] = $lampAccessory;
     }
     foreach ($lampAccessories as $ind => $cat) {
         $lampAccessoriesCount[$ind] = count($cat);
     }
     arsort($lampAccessoriesCount);
     $lampAccessoriesSorted = array();
     foreach ($lampAccessoriesCount as $ind => $count) {
         $lampAccessoriesSorted[] = $lampAccessories[$ind];
     }
     $lampAccessories = array_slice($lampAccessoriesSorted, 0, $la_tabcount);
     $this->context->smarty->assign(array('lampaccessories' => $lampAccessories, 'my_module_name' => Configuration::get('LAMPACCESSORIES_NAME'), 'my_module_link' => $this->context->link->getModuleLink('lampaccessories', 'display')));
     return $this->display(__FILE__, 'lampaccessories.tpl');
 }