src/ShopBundle/objects/db/TShopCategoryList.class.php
public static function &GetArticleCategories($iArticleId, $sLanguageID = null)
    {
        $oList = null;
        $sCategoryRestriction = TdbShopCategoryList::GetActiveCategoryQueryRestriction();
        if (!empty($sCategoryRestriction)) {
            $sCategoryRestriction = ' AND '.$sCategoryRestriction;
        }
        $db = \ChameleonSystem\CoreBundle\ServiceLocator::get('database_connection');

        $query = 'SELECT `shop_category`.*, 1 AS isprimary
                    FROM `shop_article`
              INNER JOIN `shop_category` ON `shop_article`.`shop_category_id` = `shop_category`.`id`
                   WHERE `shop_article`.`id` = '.$db->quote($iArticleId)."
                     {$sCategoryRestriction}

                     UNION DISTINCT

                  SELECT `shop_category`.*, if (`shop_category`.`id` = `shop_article`.`shop_category_id`, 1, 0) AS isprimary
                    FROM `shop_category`
              INNER JOIN `shop_article_shop_category_mlt` ON `shop_category`.`id` = `shop_article_shop_category_mlt`.`target_id`
              INNER JOIN `shop_article` on `shop_article_shop_category_mlt`.`source_id` = `shop_article`.`id`
                   WHERE `shop_article_shop_category_mlt`.`source_id` = ".$db->quote($iArticleId)."
                     {$sCategoryRestriction}

                ORDER BY isprimary DESC, position ASC
        ";

        return TdbShopCategoryList::GetList($query, $sLanguageID);
    }
public static function &GetArticleCategories($iArticleId, $sLanguageID = null)
    {
        $oList = null;
        $sCategoryRestriction = TdbShopCategoryList::GetActiveCategoryQueryRestriction();
        if (!empty($sCategoryRestriction)) {
            $sCategoryRestriction = ' AND '.$sCategoryRestriction;
        }
        $db = \ChameleonSystem\CoreBundle\ServiceLocator::get('database_connection');

        $query = 'SELECT `shop_category`.*, 1 AS isprimary
                    FROM `shop_article`
              INNER JOIN `shop_category` ON `shop_article`.`shop_category_id` = `shop_category`.`id`
                   WHERE `shop_article`.`id` = '.$db->quote($iArticleId)."
                     {$sCategoryRestriction}

                     UNION DISTINCT

                  SELECT `shop_category`.*, if (`shop_category`.`id` = `shop_article`.`shop_category_id`, 1, 0) AS isprimary
                    FROM `shop_category`
              INNER JOIN `shop_article_shop_category_mlt` ON `shop_category`.`id` = `shop_article_shop_category_mlt`.`target_id`
              INNER JOIN `shop_article` on `shop_article_shop_category_mlt`.`source_id` = `shop_article`.`id`
                   WHERE `shop_article_shop_category_mlt`.`source_id` = ".$db->quote($iArticleId)."
                     {$sCategoryRestriction}

                ORDER BY isprimary DESC, position ASC
        ";

        return TdbShopCategoryList::GetList($query, $sLanguageID);
    }
public static function & GetArticleCategories ( $ iArticleId , $ sLanguageID = null ) { $ oList = null ; $ sCategoryRestriction = TdbShopCategoryList :: GetActiveCategoryQueryRestriction ( ) ; if ( ! empty ( $ sCategoryRestriction ) ) { $ sCategoryRestriction = ' AND ' . $ sCategoryRestriction ; } $ db = \ ChameleonSystem \ CoreBundle \ ServiceLocator :: get ( 'database_connection' ) ; $ query = 'SELECT `shop_category`.*, 1 AS isprimary
                    FROM `shop_article`
              INNER JOIN `shop_category` ON `shop_article`.`shop_category_id` = `shop_category`.`id`
                   WHERE `shop_article`.`id` = ' . $ db -> quote ( $ iArticleId ) . "
                     {$sCategoryRestriction}

                     UNION DISTINCT

                  SELECT `shop_category`.*, if (`shop_category`.`id` = `shop_article`.`shop_category_id`, 1, 0) AS isprimary
                    FROM `shop_category`
              INNER JOIN `shop_article_shop_category_mlt` ON `shop_category`.`id` = `shop_article_shop_category_mlt`.`target_id`
              INNER JOIN `shop_article` on `shop_article_shop_category_mlt`.`source_id` = `shop_article`.`id`
                   WHERE `shop_article_shop_category_mlt`.`source_id` = " . $ db -> quote ( $ iArticleId ) . "
                     {$sCategoryRestriction}

                ORDER BY isprimary DESC, position ASC
        " ; return TdbShopCategoryList :: GetList ( $ query , $ sLanguageID ) ; }
return all categories connected to the article
Add main category from article to list on first position.

@param int    $iArticleId
@param string $sLanguageID

@return TdbShopCategoryList
return all categories connected to the article Add main category from article to list on first position .