Example #1
0
    /**
     * Get the user's journey
     *
     * @param integer $id_category Category ID
     * @param string $path Path end
     * @param boolean $linkOntheLastItem Put or not a link on the current category
     * @param string [optionnal] $categoryType defined what type of categories is used (products or cms)
     */
    public static function getPath($id_category, $path = '', $link_on_the_item = false, $category_type = 'products', Context $context = null)
    {
        if (!$context) {
            $context = Context::getContext();
        }
        $id_category = (int) $id_category;
        if ($id_category == 1) {
            return '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><span class="navigation_end">' . $path . '</span></div>';
        }
        $pipe = Configuration::get('PS_NAVIGATION_PIPE');
        if (empty($pipe)) {
            $pipe = '>';
        }
        $full_path = '';
        if ($category_type === 'products') {
            $interval = Category::getInterval($id_category);
            $id_root_category = $context->shop->getCategory();
            $interval_root = Category::getInterval($id_root_category);
            if ($interval) {
                $sql = 'SELECT c.id_category, cl.name, cl.link_rewrite
						FROM ' . _DB_PREFIX_ . 'category c
						LEFT JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (cl.id_category = c.id_category' . Shop::addSqlRestrictionOnLang('cl') . ')
						' . Shop::addSqlAssociation('category', 'c') . '
						WHERE c.nleft <= ' . $interval['nleft'] . '
							AND c.nright >= ' . $interval['nright'] . '
							AND c.nleft >= ' . $interval_root['nleft'] . '
							AND c.nright <= ' . $interval_root['nright'] . '
							AND cl.id_lang = ' . (int) $context->language->id . '
							AND c.active = 1
							AND c.level_depth > ' . (int) $interval_root['level_depth'] . '
						ORDER BY c.level_depth ASC';
                $categories = Db::getInstance()->executeS($sql);
                $n = 1;
                $n_categories = count($categories);
                foreach ($categories as $category) {
                    $full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb">' . ($n < $n_categories || $link_on_the_item ? '<a href="' . Tools::safeOutput($context->link->getCategoryLink((int) $category['id_category'], $category['link_rewrite'])) . '" title="' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '" itemprop="url">' : '') . '<span itemprop="title">' . htmlentities($category['name'], ENT_NOQUOTES, 'UTF-8') . '</span>' . ($n < $n_categories || $link_on_the_item ? '</a>' : '') . '</div>' . ($n++ != $n_categories || !empty($path) ? '<span class="navigation-pipe">' . $pipe . '</span>' : '');
                }
                return $full_path . $path;
            }
        } else {
            if ($category_type === 'CMS') {
                $category = new CMSCategory($id_category, $context->language->id);
                if (!Validate::isLoadedObject($category)) {
                    die(Tools::displayError());
                }
                $category_link = $context->link->getCMSCategoryLink($category);
                if ($path != $category->name) {
                    $full_path .= '<div itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a href="' . Tools::safeOutput($category_link) . '" itemprop="url"><span itemprop="title">' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '</span></a><span class="navigation-pipe">' . $pipe . '</span>' . $path;
                } else {
                    $full_path = ($link_on_the_item ? '<a href="' . Tools::safeOutput($category_link) . '" itemprop="url">' : '') . '<span itemprop="title">' . htmlentities($path, ENT_NOQUOTES, 'UTF-8') . '</span>' . ($link_on_the_item ? '</a>' : '');
                }
                return Tools::getPath($category->id_parent, $full_path, $link_on_the_item, $category_type);
            }
        }
    }
Example #2
0
 /**
  * Get list of parent categories
  *
  * @since 1.5.0
  * @param int $id_lang
  * @return array
  */
 public function getParentCategories($id_lang = null)
 {
     if (!$id_lang) {
         $id_lang = Context::getContext()->language->id;
     }
     $interval = Category::getInterval($this->id_category_default);
     $sql = new DbQuery();
     $sql->from('category', 'c');
     $sql->leftJoin('category_lang', 'cl', 'c.id_category = cl.id_category AND id_lang = ' . (int) $id_lang . Shop::addSqlRestrictionOnLang('cl'));
     $sql->where('c.nleft <= ' . (int) $interval['nleft'] . ' AND c.nright >= ' . (int) $interval['nright']);
     $sql->orderBy('c.nleft');
     return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
 }
Example #3
0
 public static function inShopStatic($id_category, Shop $shop = null)
 {
     if (!$shop || !is_object($shop)) {
         $shop = Context::getContext()->shop;
     }
     if (!($interval = Category::getInterval($shop->getCategory()))) {
         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'];
 }
Example #4
0
 /**
  * Check if current category is a child of shop root category
  *
  * @param int  $idCategory Category ID
  * @param Shop $shop       Shop object
  *
  * @return bool Indicates whether the current category is a child of the Shop root category
  *
  * @since 1.5.0
  */
 public static function inShopStatic($idCategory, Shop $shop = null)
 {
     if (!$shop || !is_object($shop)) {
         $shop = Context::getContext()->shop;
     }
     if (!($interval = Category::getInterval($shop->getCategory()))) {
         return false;
     }
     $sql = new DbQuery();
     $sql->select('c.`nleft`, c.`nright`');
     $sql->from('category', 'c');
     $sql->where('c.`id_category` = ' . (int) $idCategory);
     $row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
     return $row['nleft'] >= $interval['nleft'] && $row['nright'] <= $interval['nright'];
 }