Пример #1
0
 /**
  * Check if current category is a child of shop root category
  *
  * @param JeproshopShopModelShop $shop
  * @return bool
  */
 public function inShop(JeproshopShopModelShop $shop = null)
 {
     if (!$shop) {
         $shop = JeproshopContext::getContext()->shop;
     }
     if (!($interval = JeproshopCategoryModelCategory::getInterval($shop->getCategoryId()))) {
         return false;
     }
     return $this->n_left >= $interval->n_left && $this->n_right <= $interval->n_right;
 }
Пример #2
0
 /**
  * Get the user's journey
  *
  * @param integer $category_id Category ID
  * @param string $path Path end
  * @param bool $link_on_the_item
  * @param string $category_type
  * @param JeproshopContext $context
  * @return string
  * @internal param bool $linkOnTheLastItem Put or not a link on the current category
  * @internal param $string [optional] $categoryType defined what type of categories is used (products or cms)
  */
 public static function getPath($category_id, $path = '', $link_on_the_item = false, $category_type = 'products', JeproshopContext $context = null)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $category_id = (int) $category_id;
     if ($category_id == 1) {
         return '<span class="navigation_end">' . $path . '</span>';
     }
     $pipe = '>';
     //Configuration::get('PS_NAVIGATION_PIPE');
     if (empty($pipe)) {
         $pipe = '>';
     }
     $full_path = '';
     if ($category_type === 'products') {
         $interval = JeproshopCategoryModelCategory::getInterval($category_id);
         $root_category_id = $context->shop->getCategoryId();
         $interval_root = JeproshopCategoryModelCategory::getInterval($root_category_id);
         $db = JFactory::getDBO();
         if ($interval) {
             $query = "SELECT category.category_id, category_lang.name, category_lang.link_rewrite FROM " . $db->quoteName('#__jeproshop_category');
             $query .= " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON (category_lang.category_id =";
             $query .= "category.category_id" . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . ")" . JeproshopShopModelShop::addSqlAssociation('category');
             $query .= "\tWHERE category.n_left <= " . $interval->n_left . " AND category.n_right >= " . $interval->n_right . "\tAND category.n_left >= ";
             $query .= $interval_root->n_left . " AND category.n_right <= " . $interval_root->n_right . " AND category_lang.lang_id = " . (int) $context->language->lang_id;
             $query .= "\tAND category.published = 1 AND category.depth_level > " . (int) $interval_root->depth_level . " ORDER BY category.depth_level ASC";
             $db->setQuery($query);
             $categories = $db->loadObjectList();
             $n = 1;
             $n_categories = count($categories);
             foreach ($categories as $category) {
                 $full_path .= ($n < $n_categories || $link_on_the_item ? '<a href="' . JeproshopTools::safeOutput($context->controller->getCategoryLink((int) $category->category_id, $category->link_rewrite)) . '" title="' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '">' : '') . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . ($n < $n_categories || $link_on_the_item ? '</a>' : '') . ($n++ != $n_categories || !empty($path) ? '<span class="navigation-pipe">' . $pipe . '</span>' : '');
             }
             return $full_path . $path;
         }
     } else {
         if ($category_type === 'CMS') {
             $category = new CMSCategory($category_id, $context->language->id);
             if (!Validate::isLoadedObject($category)) {
                 die(Tools::displayError());
             }
             $category_link = $context->link->getCMSCategoryLink($category);
             if ($path != $category->name) {
                 $full_path .= '<a href="' . Tools::safeOutput($category_link) . '">' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . $pipe . '</span>' . $path;
             } else {
                 $full_path = ($link_on_the_item ? '<a href="' . Tools::safeOutput($category_link) . '">' : '') . htmlentities($path, ENT_NOQUOTES, 'UTF-8') . ($link_on_the_item ? '</a>' : '');
             }
             return Tools::getPath($category->parent_id, $full_path, $link_on_the_item, $category_type);
         }
     }
 }
Пример #3
0
 public static function inStaticShop($id_category, JeproshopShopModelShop $shop = null)
 {
     if (!$shop || !is_object($shop)) {
         $shop = Context::getContext()->shop;
     }
     if (!($interval = JeproshopCategoryModelCategory::getInterval($shop->getCategoryId()))) {
         return false;
     }
     $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('SELECT nleft, nright FROM `' . _DB_PREFIX_ . 'category` WHERE id_category = ' . (int) $id_category);
     return $row['nleft'] >= $interval['nleft'] && $row['nright'] <= $interval['nright'];
 }