51         $this->
init(
'oxdiscount');
 
   61     public function delete($sOXID = null)
 
   64             $sOXID = $this->
getId();
 
   72         $oDb->execute(
'delete from oxobject2discount where oxobject2discount.oxdiscountid = ' . $oDb->quote($sOXID));
 
   84         if (is_null($this->_blIsForArticleOrForCategory)) {
 
   86             $sDiscountIdQuoted = $oDb->quote($this->oxdiscount__oxid->value);
 
   89                         from oxobject2discount 
   90                         where oxdiscountid = $sDiscountIdQuoted and (oxtype = 'oxarticles' or oxtype = 'oxcategories')";
 
   92             $this->_blIsForArticleOrForCategory = $oDb->getOne($sQuery) ? 
false : 
true;
 
  108         if ($this->oxdiscount__oxaddsumtype->value == 
'itm') {
 
  112         if ($this->oxdiscount__oxamount->value || $this->oxdiscount__oxprice->value) {
 
  116         if ($this->oxdiscount__oxpriceto->value && ($this->oxdiscount__oxpriceto->value < $oArticle->getBasePrice())) {
 
  124         $sArticleId = $oArticle->getProductId();
 
  126         if (!isset($this->_aHasArticleDiscounts[$sArticleId])) {
 
  130             $this->_aHasArticleDiscounts[$sArticleId] = $blResult;
 
  133         return $this->_aHasArticleDiscounts[$sArticleId];
 
  145         if ($this->oxdiscount__oxamount->value == 0 && $this->oxdiscount__oxprice->value == 0) {
 
  150         if ($this->oxdiscount__oxaddsumtype->value == 
'itm') {
 
  157         $sQ = 
"select 1 from oxobject2discount where oxdiscountid = " . $oDb->quote($this->oxdiscount__oxid->value) . 
" and oxtype = 'oxarticles' ";
 
  159         if (!($blOk = ( 
bool ) $oDb->getOne($sQ))) {
 
  178         $aBasketItems = $oBasket->getContents();
 
  179         foreach ($aBasketItems as $oBasketItem) {
 
  181             $oBasketArticle = $oBasketItem->getArticle(
false);
 
  183             $blForBasketItem = 
false;
 
  184             if ($this->oxdiscount__oxaddsumtype->value != 
'itm') {
 
  190             if ($blForBasketItem) {
 
  191                 $dRate = $oBasket->getBasketCurrency()->rate;
 
  192                 if ($this->oxdiscount__oxprice->value) {
 
  193                     if (($oPrice = $oBasketArticle->getPrice())) {
 
  194                         $dAmount += ($oPrice->getPrice() * $oBasketItem->getAmount()) / $dRate;
 
  196                 } elseif ($this->oxdiscount__oxamount->value) {
 
  197                     $dAmount += $oBasketItem->getAmount();
 
  216         if ($this->oxdiscount__oxprice->value &&
 
  217             ($dAmount < $this->oxdiscount__oxprice->value || $dAmount > $this->oxdiscount__oxpriceto->value)
 
  220         } elseif ($this->oxdiscount__oxamount->value &&
 
  221                   ($dAmount < $this->oxdiscount__oxamount->value || $dAmount > $this->oxdiscount__oxamountto->value)
 
  239         if ($this->oxdiscount__oxamount->value == 0 && $this->oxdiscount__oxprice->value == 0) {
 
  243         $oSummary = $oBasket->getBasketSummary();
 
  245         if ($this->oxdiscount__oxamount->value && ($oSummary->iArticleCount < $this->oxdiscount__oxamount->value || $oSummary->iArticleCount > $this->oxdiscount__oxamountto->value)) {
 
  248         } elseif ($this->oxdiscount__oxprice->value) {
 
  249             $dRate = $oBasket->getBasketCurrency()->rate;
 
  250             if ($oSummary->dArticleDiscountablePrice < $this->oxdiscount__oxprice->value * $dRate || $oSummary->dArticleDiscountablePrice > $this->oxdiscount__oxpriceto->value * $dRate) {
 
  257         $sQ = 
'select 1 from oxobject2discount where oxdiscountid = ' . $oDb->quote($this->oxdiscount__oxid->value) . 
' and oxtype in ("oxarticles", "oxcategories" ) ';
 
  259         return !((bool) $oDb->getOne($sQ));
 
  271         if ($this->oxdiscount__oxaddsumtype->value != 
'itm') {
 
  276         $sQ = 
"select 1 from oxobject2discount where oxdiscountid=" . $oDb->quote($this->
getId());
 
  278         if (!($blOk = (
bool) $oDb->getOne($sQ))) {
 
  295         if ($this->oxdiscount__oxaddsumtype->value != 
'itm') {
 
  312         if ($this->oxdiscount__oxaddsumtype->value == 
'%') {
 
  313             return $dPrice * ($this->oxdiscount__oxaddsum->value / 100);
 
  315             $oCur = $this->
getConfig()->getActShopCurrencyObject();
 
  317             return $this->oxdiscount__oxaddsum->value * $dAmount * $oCur->rate;
 
  331             return $this->
getAddSum() / $dPrice * 100;
 
  345         if ($this->oxdiscount__oxaddsumtype->value == 
'abs') {
 
  346             $oCur = $this->
getConfig()->getActShopCurrencyObject();
 
  348             return $this->oxdiscount__oxaddsum->value * $oCur->rate;
 
  350             return $this->oxdiscount__oxaddsum->value;
 
  361         return $this->oxdiscount__oxaddsumtype->value;
 
  373         $dItemAmount = $this->oxdiscount__oxitmamount->value;
 
  376         if ($this->oxdiscount__oxitmmultiple->value && $this->oxdiscount__oxamount->value > 0) {
 
  377             $dItemAmount = floor($dAmount / $this->oxdiscount__oxamount->value) * $this->oxdiscount__oxitmamount->value;
 
  390         $oDiscount = 
new stdClass();
 
  391         $oDiscount->sOXID = $this->
getId();
 
  392         $oDiscount->sDiscount = $this->oxdiscount__oxtitle->value;
 
  393         $oDiscount->sType = $this->oxdiscount__oxaddsumtype->value;
 
  405         return oxDb::getDb()->getCol(
"select `oxobjectid` from oxobject2discount where oxdiscountid = '" . $this->
getId() . 
"' and oxtype = 'oxarticles'");
 
  415         return oxDb::getDb()->getCol(
"select `oxobjectid` from oxobject2discount where oxdiscountid = '" . $this->
getId() . 
"' and oxtype = 'oxcategories'");
 
  429         $aCatIds = $oArticle->getCategoryIds();
 
  430         if (!$aCatIds || !count($aCatIds)) {
 
  439         $sQ = 
"select oxobjectid from oxobject2discount where oxdiscountid = " . $oDb->quote($this->oxdiscount__oxid->value) . 
" and oxobjectid in $sCatIds and oxtype = 'oxcategories'";
 
  441         return $oDb->getOne($sQ);
 
  456         if (($sParentId = $oProduct->getParentId())) {
 
  457             $sArticleId = 
" and ( oxobjectid = " . $oDb->quote($oProduct->getProductId()) . 
" or oxobjectid = " . $oDb->quote($sParentId) . 
" )";
 
  459             $sArticleId = 
" and oxobjectid = " . $oDb->quote($oProduct->getProductId());
 
  475         $sDiscountIdQuoted = $oDb->quote($this->oxdiscount__oxid->value);
 
  478                 from oxobject2discount 
  479                 where oxdiscountid = {$sDiscountIdQuoted} and oxtype = 'oxarticles' ";
 
  482         return $oDb->getOne($sQ) ? 
true : 
false;
 
  494         if (empty($aCategoryIds)) {
 
  499         $sDiscountIdQuoted = $oDb->quote($this->oxdiscount__oxid->value);
 
  501         $sCategoryIds = 
"(" . implode(
",", 
oxDb::getInstance()->quoteArray($aCategoryIds)) . 
")";
 
  503                 from oxobject2discount 
  504                 where oxdiscountid = {$sDiscountIdQuoted} and oxobjectid in {$sCategoryIds} and oxtype = 'oxcategories'";
 
  506         return $oDb->getOne($sQ) ? 
true : 
false;