/** * Tear down the fixture. */ protected function tearDown() { // deleting demo items if ($this->oArticle) { $this->oArticle->delete(); } if ($this->oCategory) { $this->oCategory->delete(); } oxTestModules::addFunction('oxVatSelector', 'clear', '{ oxVatSelector::$_aUserVatCache = array();}'); oxNew('oxVatSelector')->clear(); oxRemClassModule('oxVatSelector'); parent::tearDown(); }
/** * Loads and returns the article for that basket item * * @param string $sItemKey the key that will be given to oxarticle setItemKey * * @throws oxArticleException article exception * * @return oxArticle */ public function getArticle($sItemKey) { if (!$this->oxuserbasketitems__oxartid->value) { //this exception may not be caught, anyhow this is a critical exception $oEx = oxNew('oxArticleException'); $oEx->setMessage('EXCEPTION_ARTICLE_NOPRODUCTID'); throw $oEx; } if ($this->_oArticle === null) { $this->_oArticle = oxNew('oxArticle'); // performance /* removed due to #4178 if ( $this->_blParentBuyable ) { $this->_oArticle->setNoVariantLoading( true ); } */ if (!$this->_oArticle->load($this->oxuserbasketitems__oxartid->value)) { return false; } $aSelList = $this->getSelList(); if (($aSelectlist = $this->_oArticle->getSelectLists()) && is_array($aSelList)) { foreach ($aSelList as $iKey => $iSel) { if (isset($aSelectlist[$iKey][$iSel])) { // cloning select list information $aSelectlist[$iKey][$iSel] = clone $aSelectlist[$iKey][$iSel]; $aSelectlist[$iKey][$iSel]->selected = 1; } } $this->_oArticle->setSelectlist($aSelectlist); } // generating item key $this->_oArticle->setItemKey($sItemKey); } return $this->_oArticle; }
function getPrice() { if ($this->oPriceCache) { return $this->oPriceCache; } else { return parent::getPrice(); } }
/** * returns reviews list for article * * @param oxArticle $oArticle Article object * * @return oxList */ protected function _getReviewList($oArticle) { $oDb = oxDb::getDb(); $sSelect = "select oxreviews.* from oxreviews\n where oxreviews.OXOBJECTID = " . $oDb->quote($oArticle->oxarticles__oxid->value) . "\n and oxreviews.oxtype = 'oxarticle'"; $aVariantList = $oArticle->getVariants(); if ($this->getConfig()->getConfigParam('blShowVariantReviews') && count($aVariantList)) { // verifying rights foreach ($aVariantList as $oVariant) { $sSelect .= "or oxreviews.oxobjectid = " . $oDb->quote($oVariant->oxarticles__oxid->value) . " "; } } //$sSelect .= "and oxreviews.oxtext".oxLang::getInstance()->getLanguageTag($this->_iEditLang)." != ''"; $sSelect .= "and oxreviews.oxlang = '" . $this->_iEditLang . "'"; $sSelect .= "and oxreviews.oxtext != '' "; // all reviews $oRevs = oxNew("oxlist"); $oRevs->init("oxreview"); $oRevs->selectString($sSelect); return $oRevs; }
/** * returns reviews list for article * * @param oxArticle $article Article object * * @return oxList */ protected function _getReviewList($article) { $database = oxDb::getDb(); $query = "select oxreviews.* from oxreviews\n where oxreviews.OXOBJECTID = " . $database->quote($article->oxarticles__oxid->value) . "\n and oxreviews.oxtype = 'oxarticle'"; $variantList = $article->getVariants(); if ($this->getConfig()->getConfigParam('blShowVariantReviews') && count($variantList)) { // verifying rights foreach ($variantList as $variant) { $query .= "or oxreviews.oxobjectid = " . $database->quote($variant->oxarticles__oxid->value) . " "; } } //$sSelect .= "and oxreviews.oxtext".oxRegistry::getLang()->getLanguageTag($this->_iEditLang)." != ''"; $query .= "and oxreviews.oxlang = '" . $this->_iEditLang . "'"; $query .= "and oxreviews.oxtext != '' "; // all reviews $reviewList = oxNew("oxlist"); $reviewList->init("oxreview"); $reviewList->selectString($query); return $reviewList; }
/** * Loads language for article. * * @param oxArticle $oArticle * @param string $sOxId * * @return oxArticle */ protected function updateArticle($oArticle, $sOxId) { $oArticle->loadInLang($this->_iEditLang, $sOxId); return $oArticle; }
/** * Creates articles from array * * @param array $aArticles * * @return array $aResult of id's and basket amounts of created articles */ public function createArticles($aArticles) { $aResult = array(); if (empty($aArticles)) { return $aResult; } foreach ($aArticles as $aArticle) { $oArticle = new oxArticle(); $oArticle->setId($aArticle['oxid']); foreach ($aArticle as $sKey => $sValue) { if (strstr($sKey, "ox")) { $sField = "oxarticles__{$sKey}"; $oArticle->{$sField} = new oxField($aArticle[$sKey]); } } $oArticle->save(); if ($aArticle['scaleprices']) { $this->_createScalePrices(array($aArticle['scaleprices'])); } if ($aArticle['field2shop']) { $this->_createField2Shop($oArticle, $aArticle['field2shop']); } $aResult[$aArticle['oxid']] = array('id' => $aArticle['oxid'], 'amount' => $aArticle['amount']); } return $aResult; }
/** * loads 'Recommendation lists' rss data * * @param oxArticle $oArticle load lists for this article * * @return null */ public function loadRecommLists(oxArticle $oArticle) { if ($this->_aChannel = $this->_loadFromCache(self::RSS_ARTRECOMMLISTS . $oArticle->getId())) { return; } $oConfig = $this->getConfig(); $oConfig->setConfigParam('iNrofCrossellArticles', $oConfig->getConfigParam('iRssItemsCount')); $oList = oxNew('oxrecommlist')->getRecommListsByIds(array($oArticle->getId())); if ($oList == null) { $oList = oxNew('oxlist'); } $oLang = oxRegistry::getLang(); $this->_loadData(self::RSS_ARTRECOMMLISTS . $oArticle->getId(), $this->getRecommListsTitle($oArticle), sprintf($oLang->translateString('LISTMANIA_LIST_FOR', $oLang->getBaseLanguage()), $oArticle->oxarticles__oxtitle->value), $this->_getRecommListItems($oList), $this->getRecommListsUrl($oArticle), $oArticle->getLink()); }
/** * Loads language for article object. * * @param oxArticle $article * @param string $oxId * * @return oxArticle */ protected function updateArticle($article, $oxId) { $article->loadInLang(oxRegistry::getConfig()->getRequestParameter("editlanguage"), $oxId); return $article; }
/** * Retrieves the article .Throws an exception if article does not exist, * is not buyable or visible. * * @param bool $blCheckProduct checks if product is buyable and visible * @param string $sProductId product id * @param bool $blDisableLazyLoading disable lazy loading * * @throws oxArticleException exception in case of no current object product id is set * @throws oxNoArticleException exception in case if product not exitst or not visible * @throws oxArticleInputException exception if product is not buyable (stock and so on) * * @return oxArticle|oxOrderArticle */ public function getArticle($blCheckProduct = false, $sProductId = null, $blDisableLazyLoading = false) { if ($this->_oArticle === null || !$this->_oArticle->isOrderArticle() && $blDisableLazyLoading) { $sProductId = $sProductId ? $sProductId : $this->_sProductId; if (!$sProductId) { //this exception may not be caught, anyhow this is a critical exception /** @var oxArticleException $oEx */ $oEx = oxNew('oxArticleException'); $oEx->setMessage('EXCEPTION_ARTICLE_NOPRODUCTID'); throw $oEx; } $this->_oArticle = oxNew('oxArticle'); // #M773 Do not use article lazy loading on order save if ($blDisableLazyLoading) { $this->_oArticle->modifyCacheKey('_allviews'); $this->_oArticle->disableLazyLoading(); } // performance: // - skipping variants loading // - skipping 'ab' price info // - load parent field $this->_oArticle->setNoVariantLoading(true); $this->_oArticle->setLoadParentData(true); if (!$this->_oArticle->load($sProductId)) { /** @var oxNoArticleException $oEx */ $oEx = oxNew('oxNoArticleException'); $oLang = oxRegistry::getLang(); $oEx->setMessage(sprintf($oLang->translateString('ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage()), $sProductId)); $oEx->setArticleNr($sProductId); $oEx->setProductId($sProductId); throw $oEx; } // cant put not visible product to basket (M:1286) if ($blCheckProduct && !$this->_oArticle->isVisible()) { /** @var oxNoArticleException $oEx */ $oEx = oxNew('oxNoArticleException'); $oLang = oxRegistry::getLang(); $oEx->setMessage(sprintf($oLang->translateString('ERROR_MESSAGE_ARTICLE_ARTICLE_DOES_NOT_EXIST', $oLang->getBaseLanguage()), $this->_oArticle->oxarticles__oxartnum->value)); $oEx->setArticleNr($sProductId); $oEx->setProductId($sProductId); throw $oEx; } // cant put not buyable product to basket if ($blCheckProduct && !$this->_oArticle->isBuyable()) { /** @var oxArticleInputException $oEx */ $oEx = oxNew('oxArticleInputException'); $oEx->setMessage('ERROR_MESSAGE_ARTICLE_ARTICLE_NOT_BUYABLE'); $oEx->setArticleNr($sProductId); $oEx->setProductId($sProductId); throw $oEx; } } return $this->_oArticle; }
/** * Returns array containing default list type and category (or manufacturer ir vendor) id * * @param oxArticle $oProduct current product object * * @return array */ protected function _getDefaultParams($oProduct) { $sListType = null; $aArticleCats = $oProduct->getCategoryIds(true); if (is_array($aArticleCats) && count($aArticleCats)) { $sActCat = reset($aArticleCats); } elseif ($sActCat = $oProduct->getManufacturerId()) { // not assigned to any category ? maybe it is assigned to Manufacturer ? $sListType = 'manufacturer'; } elseif ($sActCat = $oProduct->getVendorId()) { // not assigned to any category ? maybe it is assigned to vendor ? $sListType = 'vendor'; } else { $sActCat = null; } return array($sListType, $sActCat); }
/** * Checks if discount applies for article * * @param oxArticle $oArticle article object * * @return bool */ public function isForArticle($oArticle) { // item discounts may only be applied for basket if ($this->oxdiscount__oxaddsumtype->value == 'itm') { return false; } if ($this->oxdiscount__oxamount->value || $this->oxdiscount__oxprice->value) { return false; } if ($this->oxdiscount__oxpriceto->value && $this->oxdiscount__oxpriceto->value < $oArticle->getBasePrice()) { return false; } if ($this->isGlobalDiscount()) { return true; } $sArticleId = $oArticle->getProductId(); if (!isset($this->_aHasArticleDiscounts[$sArticleId])) { $blResult = $this->_isArticleAssigned($oArticle) || $this->_isCategoriesAssigned($oArticle->getCategoryIds()); $this->_aHasArticleDiscounts[$sArticleId] = $blResult; } return $this->_aHasArticleDiscounts[$sArticleId]; }
/** * Checks if articles has amount price * * @return bool */ public function hasAmountPrice() { if (self::$_blHasAmountPrice === null) { self::$_blHasAmountPrice = false; $oDb = oxDb::getDb(); $sQ = "SELECT 1 FROM `oxprice2article` LIMIT 1"; if ($oDb->getOne($sQ)) { self::$_blHasAmountPrice = true; } } return self::$_blHasAmountPrice; }
/** * get article user vat * * @param oxArticle $oArticle article object * * @return double | false */ public function getArticleUserVat(oxArticle $oArticle) { if ($oUser = $oArticle->getArticleUser()) { return $this->getUserVat($oUser); } return false; }
/** * Appends dyn params to url. * * @param string $sAddDynParams Dyn params * @param oxArticle $oArticle Article * * @return bool */ protected function _addDynParamsToLink($sAddDynParams, $oArticle) { $blAddedParams = false; if ($sAddDynParams) { $blSeo = oxRegistry::getUtils()->seoIsActive(); if (!$blSeo) { // only if seo is off.. $oArticle->appendStdLink($sAddDynParams); } $oArticle->appendLink($sAddDynParams); $blAddedParams = true; } return $blAddedParams; }
/** * Returns product tags array for given language * * @param oxArticle $oArticle Article object * @param int $iLang language id * * @return array */ protected function _getTagList($oArticle, $iLang) { $oArticleTagList = oxNew("oxarticletaglist"); $oArticleTagList->setLanguage($iLang); $oArticleTagList->load($oArticle->getId()); $aTagsList = array(); if (count($aTags = $oArticleTagList->getArray())) { $sShopId = $this->getConfig()->getShopId(); $iProdId = $oArticle->getId(); foreach ($aTags as $sTitle => $oTagObject) { // A. we do not have oxTag object yet, so reusing manufacturers for general interface $oTag = oxNew("oxManufacturer"); $oTag->setLanguage($iLang); $oTag->setId(md5(strtolower($sShopId . $this->_getStdUrl($iProdId, "oxtag", "tag", $iLang, $sTitle)))); $oTag->oxmanufacturers__oxtitle = new oxField($sTitle); $aTagsList[] = $oTag; } } return $aTagsList; }
/** * Deletes thumbnail file * * @param oxArticle $oArticle article object * * @return null */ protected function _deleteThumbnail($oArticle) { if ($oArticle->oxarticles__oxthumb->value) { if (!$oArticle->isDerived()) { $oPicHandler = oxRegistry::get("oxPictureHandler"); $oPicHandler->deleteThumbnail($oArticle); } //reseting field $oArticle->oxarticles__oxthumb = new oxField(); } }
/** * Test enable price load. * * @depends testDisablePriceLoad * * @param oxArticle $oArticle * * @return null */ public function testEnablePriceLoad(oxArticle $oArticle) { $oArticle->enablePriceLoad(); $this->assertNotNull($oArticle->getBasePrice()); }
/** * deletes article seo entries * * @param oxArticle $oArticle article to remove */ public function onDeleteArticle($oArticle) { $oDb = oxDb::getDb(); $sIdQuoted = $oDb->quote($oArticle->getId()); $oDb->execute("delete from oxseo where oxobjectid = {$sIdQuoted} and oxtype = 'oxarticle'"); $oDb->execute("delete from oxobject2seodata where oxobjectid = {$sIdQuoted}"); }
/** * Encodes article URLs into SEO format * * @param oxArticle $oArticle Article object * @param int $iLang language * @param int $iType type * * @return string */ public function getArticleUrl($oArticle, $iLang = null, $iType = 0) { if (!isset($iLang)) { $iLang = $oArticle->getLanguage(); } $sUri = null; switch ($iType) { case OXARTICLE_LINKTYPE_VENDOR: $sUri = $this->_getArticleVendorUri($oArticle, $iLang); break; case OXARTICLE_LINKTYPE_MANUFACTURER: $sUri = $this->_getArticleManufacturerUri($oArticle, $iLang); break; case OXARTICLE_LINKTYPE_TAG: $sUri = $this->_getArticleTagUri($oArticle, $iLang); break; case OXARTICLE_LINKTYPE_RECOMM: $sUri = $this->_getArticleRecommUri($oArticle, $iLang); break; case OXARTICLE_LINKTYPE_PRICECATEGORY: // goes price category urls to default (category urls) // goes price category urls to default (category urls) default: $sUri = $this->_getArticleUri($oArticle, $iLang); break; } // if was unable to fetch type uri - returning main if (!$sUri) { $sUri = $this->_getArticleMainUri($oArticle, $iLang); } return $this->_getFullUrl($sUri, $iLang); }