예제 #1
0
 /**
  * Checks if discount is setup 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;
     }
     $myDB = oxDb::getDb();
     $sDiscountIdQuoted = $myDB->quote($this->oxdiscount__oxid->value);
     //check for global discount (no articles, no categories)
     if ($this->_blIsForArticleOrForCategory) {
         return true;
     } elseif ($this->_blIsForArticleOrForCategory === null) {
         $this->_blIsForArticleOrForCategory = false;
         $sQ = "select 1 from oxobject2discount where oxdiscountid = {$sDiscountIdQuoted} and ( oxtype = 'oxarticles' or oxtype = 'oxcategories')";
         if (!$myDB->getOne($sQ)) {
             $this->_blIsForArticleOrForCategory = true;
             return true;
         }
     }
     $sArticleId = $oArticle->getProductId();
     if (!$this->_blIsForArticleAndForCategory && !isset($this->_aHasArticleDiscounts[$sArticleId])) {
         $this->_aHasArticleDiscounts[$sArticleId] = false;
         // check if this article is assigned
         $sQ = "select 1 from oxobject2discount where oxdiscountid = {$sDiscountIdQuoted} and oxtype = 'oxarticles' ";
         $sQ .= $this->_getProductCheckQuery($oArticle);
         if ($myDB->getOne($sQ)) {
             $this->_aHasArticleDiscounts[$sArticleId] = true;
             return true;
         } else {
             // check if article is in some assigned category
             $aCatIds = $oArticle->getCategoryIds();
             if (!$aCatIds || !count($aCatIds)) {
                 // no categories are set for article, so no discounts from categories..
                 return false;
             }
             $sCatIds = "(" . implode(",", oxDb::getInstance()->quoteArray($aCatIds)) . ")";
             // getOne appends limit 1, so this one should be fast enough
             $sQ = "select 1 from oxobject2discount where oxdiscountid = {$sDiscountIdQuoted} and oxobjectid in {$sCatIds} and oxtype = 'oxcategories'";
             if ($myDB->getOne($sQ)) {
                 $this->_aHasArticleDiscounts[$sArticleId] = true;
                 return true;
             }
         }
     }
     return $this->_aHasArticleDiscounts[$sArticleId];
 }