source/Application/Model/SeoEncoderArticle.php
protected function _getMainCategory($oArticle)
    {
        $oMainCat = null;

        // if variant parent id must be used
        $sArtId = $oArticle->getId();
        if (isset($oArticle->oxarticles__oxparentid->value) && $oArticle->oxarticles__oxparentid->value) {
            $sArtId = $oArticle->oxarticles__oxparentid->value;
        }

        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        // add main category caching;
        $sQ = "select oxcatnid from " . getViewName("oxobject2category") . " where oxobjectid = " . $oDb->quote($sArtId) . " order by oxtime";
        $sIdent = md5($sQ);

        if (($sMainCatId = $this->_loadFromCache($sIdent, "oxarticle")) === false) {
            $sMainCatId = $oDb->getOne($sQ);
            // storing in cache
            $this->_saveInCache($sIdent, $sMainCatId, "oxarticle");
        }

        if ($sMainCatId) {
            $oMainCat = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
            if (!$oMainCat->load($sMainCatId)) {
                $oMainCat = null;
            }
        }

        return $oMainCat;
    }
protected function _getMainCategory($oArticle)
    {
        $oMainCat = null;

        // if variant parent id must be used
        $sArtId = $oArticle->getId();
        if (isset($oArticle->oxarticles__oxparentid->value) && $oArticle->oxarticles__oxparentid->value) {
            $sArtId = $oArticle->oxarticles__oxparentid->value;
        }

        $oDb = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
        // add main category caching;
        $sQ = "select oxcatnid from " . getViewName("oxobject2category") . " where oxobjectid = " . $oDb->quote($sArtId) . " order by oxtime";
        $sIdent = md5($sQ);

        if (($sMainCatId = $this->_loadFromCache($sIdent, "oxarticle")) === false) {
            $sMainCatId = $oDb->getOne($sQ);
            // storing in cache
            $this->_saveInCache($sIdent, $sMainCatId, "oxarticle");
        }

        if ($sMainCatId) {
            $oMainCat = oxNew(\OxidEsales\Eshop\Application\Model\Category::class);
            if (!$oMainCat->load($sMainCatId)) {
                $oMainCat = null;
            }
        }

        return $oMainCat;
    }
protected function _getMainCategory ( $ oArticle ) { $ oMainCat = null ; // if variant parent id must be used $ sArtId = $ oArticle -> getId ( ) ; if ( isset ( $ oArticle -> oxarticles__oxparentid -> value ) && $ oArticle -> oxarticles__oxparentid -> value ) { $ sArtId = $ oArticle -> oxarticles__oxparentid -> value ; } $ oDb = \ OxidEsales \ Eshop \ Core \ DatabaseProvider :: getDb ( ) ; // add main category caching; $ sQ = "select oxcatnid from " . getViewName ( "oxobject2category" ) . " where oxobjectid = " . $ oDb -> quote ( $ sArtId ) . " order by oxtime" ; $ sIdent = md5 ( $ sQ ) ; if ( ( $ sMainCatId = $ this -> _loadFromCache ( $ sIdent , "oxarticle" ) ) === false ) { $ sMainCatId = $ oDb -> getOne ( $ sQ ) ; // storing in cache $ this -> _saveInCache ( $ sIdent , $ sMainCatId , "oxarticle" ) ; } if ( $ sMainCatId ) { $ oMainCat = oxNew ( \ OxidEsales \ Eshop \ Application \ Model \ Category :: class ) ; if ( ! $ oMainCat -> load ( $ sMainCatId ) ) { $ oMainCat = null ; } } return $ oMainCat ; }
Returns products main category id

@param \OxidEsales\Eshop\Application\Model\Article $oArticle product

@return string
Returns products main category id