/** * Assign template vars related to category. */ protected function assignCategory() { // Assign category to the template if (($this->category === false || !Validate::isLoadedObject($this->category) || !$this->category->inShop() || !$this->category->isAssociatedToShop()) && Category::inShopStatic($this->product->id_category_default, $this->context->shop)) { $this->category = new Category((int) $this->product->id_category_default, (int) $this->context->language->id); } $sub_categories = array(); if (Validate::isLoadedObject($this->category)) { $sub_categories = $this->category->getSubCategories($this->context->language->id, true); // various assignements before Hook::exec $this->context->smarty->assign(array('category' => $this->category, 'subCategories' => $sub_categories, 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id))); } }
/** * Create a link to a category * * @param mixed $category Category object (can be an ID category, but deprecated) * @param string $alias * @param int $id_lang * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered * @return string */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } $dispatcher = Dispatcher::getInstance(); if ($dispatcher->hasKeyword('category_rule', $id_lang, 'parent_categories')) { // Retrieve all parent categories $p_cats = array(); foreach ($category->getParentsCategories($id_lang) as $p_cat) { // remove root and current category from the URL if (!in_array($p_cat['id_category'], array_merge(self::$category_disable_rewrite, array($category->id)))) { $p_cats[] = $p_cat['link_rewrite']; } } // add the URL slashes among categories, in reverse order $params['parent_categories'] = implode('/', array_reverse($p_cats)); } return $url . $dispatcher->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }
/** * Assign template vars related to category */ protected function assignCategory() { // Assign category to the template if ($this->category !== false && Validate::isLoadedObject($this->category) && $this->category->inShop() && $this->category->isAssociatedToShop()) { $path = Tools::getPath($this->category->id, $this->product->name, true); } elseif (Category::inShopStatic($this->product->id_category_default, $this->context->shop)) { $this->category = new Category((int) $this->product->id_category_default, (int) $this->context->language->id); if (Validate::isLoadedObject($this->category) && $this->category->active && $this->category->isAssociatedToShop()) { $path = Tools::getPath((int) $this->product->id_category_default, $this->product->name); } } if (!isset($path) || !$path) { $path = Tools::getPath((int) $this->context->shop->id_category, $this->product->name); } $sub_categories = array(); if (Validate::isLoadedObject($this->category)) { $sub_categories = $this->category->getSubCategories($this->context->language->id, true); // various assignements before Hook::exec $this->context->smarty->assign(array('path' => $path, 'category' => $this->category, 'subCategories' => $sub_categories, 'id_category_current' => (int) $this->category->id, 'id_category_parent' => (int) $this->category->id_parent, 'return_category_name' => Tools::safeOutput($this->category->getFieldByLang('name')), 'categories' => Category::getHomeCategories($this->context->language->id, true, (int) $this->context->shop->id))); } $this->context->smarty->assign(array('HOOK_PRODUCT_FOOTER' => Hook::exec('displayFooterProduct', array('product' => $this->product, 'category' => $this->category)))); }
/** * Create a link to a category * * @param mixed $category Category object (can be an ID category, but deprecated) * @param string $alias * @param int $id_lang * @param string $selected_filters Url parameter to autocheck filters of the module blocklayered * @return string */ public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false) { if (!$id_lang) { $id_lang = Context::getContext()->language->id; } $url = $this->getBaseLink($id_shop, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!is_object($category)) { $category = new Category($category, $id_lang); } // Set available keywords $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); // Selected filters is used by the module blocklayered $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }
public function getCategoryLink($category, $alias = null, $id_lang = null, $selected_filters = null, $id_shop = null, $relative_protocol = false) { if (!Module::isInstalled('agilemultipleshop')) { return parent::getCategoryLink($category, $alias, $id_lang, $selected_filters, $id_shop, $relative_protocol); } $url_choice_cat = (int) Configuration::get('ASP_URL_CHOICE_CAT'); if ($url_choice_cat == 0) { return parent::getCategoryLink($category, $alias, $id_lang, $selected_filters, $id_shop, $relative_protocol); } $id_seller = AgileSellerManager::getObjectOwnerID('category', is_object($category) ? $category->id : (int) $category); $url = $this->getAgileBaseUrl($url_choice_cat == 2, $id_seller, null, $relative_protocol) . $this->getLangLink($id_lang, null, $id_shop); if (!$id_lang) { $id_lang = Context::getContext()->language->id; } if (!is_object($category)) { $category = new Category($category, $id_lang); } $params = array(); $params['id'] = $category->id; $params['rewrite'] = !$alias ? $category->link_rewrite : $alias; $params['meta_keywords'] = Tools::str2url($category->getFieldByLang('meta_keywords')); $params['meta_title'] = Tools::str2url($category->getFieldByLang('meta_title')); $selected_filters = is_null($selected_filters) ? '' : $selected_filters; if (empty($selected_filters)) { $rule = 'category_rule'; } else { $rule = 'layered_rule'; $params['selected_filters'] = $selected_filters; } return $url . Dispatcher::getInstance()->createUrl($rule, $id_lang, $params, $this->allow, '', $id_shop); }