50 $this->
init(
'oxdiscount' );
60 public function delete( $sOXID = null )
63 $sOXID = $this->
getId();
71 $oDb->execute(
'delete from oxobject2discount where oxobject2discount.oxdiscountid = '.$oDb->quote($sOXID) );
87 if ( $this->oxdiscount__oxaddsumtype->value ==
'itm' ) {
91 if ( $this->oxdiscount__oxamount->value || $this->oxdiscount__oxprice->value ) {
95 if ( $this->oxdiscount__oxpriceto->value && ($this->oxdiscount__oxpriceto->value < $oArticle->getBasePrice()) ) {
101 $sDiscountIdQuoted = $oDb->quote($this->oxdiscount__oxid->value);
104 if ( $this->_blIsForArticleOrForCategory ) {
106 } elseif ( $this->_blIsForArticleOrForCategory === null ) {
108 $this->_blIsForArticleOrForCategory =
false;
109 $sQ =
"select 1 from oxobject2discount where oxdiscountid = $sDiscountIdQuoted and ( oxtype = 'oxarticles' or oxtype = 'oxcategories')";
110 if ( ! $oDb->getOne( $sQ ) ) {
111 $this->_blIsForArticleOrForCategory =
true;
116 $sArticleId = $oArticle->getProductId();
118 if ( !$this->_blIsForArticleAndForCategory && !isset($this->_aHasArticleDiscounts[ $sArticleId ] ) ) {
120 $this->_aHasArticleDiscounts[ $sArticleId ] = false ;
123 $sQ =
"select 1 from oxobject2discount where oxdiscountid = {$sDiscountIdQuoted} and oxtype = 'oxarticles' ";
126 if ( $oDb->getOne( $sQ ) ) {
127 $this->_aHasArticleDiscounts[ $sArticleId ] =
true;
131 $aCatIds = $oArticle->getCategoryIds();
132 if (!$aCatIds || !count($aCatIds)) {
138 $sQ =
"select 1 from oxobject2discount where oxdiscountid = {$sDiscountIdQuoted} and oxobjectid in $sCatIds and oxtype = 'oxcategories'";
139 if ( $oDb->getOne( $sQ ) ) {
140 $this->_aHasArticleDiscounts[ $sArticleId ] =
true;
146 return $this->_aHasArticleDiscounts[ $sArticleId ];
158 if ( $this->oxdiscount__oxamount->value == 0 && $this->oxdiscount__oxprice->value == 0 ) {
163 if ( $this->oxdiscount__oxaddsumtype->value ==
'itm' ) {
170 $sQ =
"select 1 from oxobject2discount where oxdiscountid = ".$oDb->quote( $this->oxdiscount__oxid->value).
" and oxtype = 'oxarticles' ";
172 if ( !( $blOk = (
bool ) $oDb->getOne( $sQ ) ) ) {
191 $aBasketItems = $oBasket->getContents();
192 foreach ( $aBasketItems as $oBasketItem ) {
194 $oBasketArticle = $oBasketItem->getArticle(
false);
196 $blForBasketItem =
false;
197 if ( $this->oxdiscount__oxaddsumtype->value !=
'itm' ) {
203 if ( $blForBasketItem ) {
204 $dRate = $oBasket->getBasketCurrency()->rate;
205 if ( $this->oxdiscount__oxprice->value ) {
206 if ( ( $oPrice = $oBasketArticle->getPrice() ) ) {
207 $dAmount += ($oPrice->getPrice() * $oBasketItem->getAmount())/$dRate;
209 } elseif ( $this->oxdiscount__oxamount->value ) {
210 $dAmount += $oBasketItem->getAmount();
229 if ( $this->oxdiscount__oxprice->value &&
230 ( $dAmount < $this->oxdiscount__oxprice->value || $dAmount > $this->oxdiscount__oxpriceto->value ) ) {
232 } elseif ( $this->oxdiscount__oxamount->value &&
233 ( $dAmount < $this->oxdiscount__oxamount->value || $dAmount > $this->oxdiscount__oxamountto->value ) ) {
250 if ( $this->oxdiscount__oxamount->value == 0 && $this->oxdiscount__oxprice->value == 0 ) {
254 $oSummary = $oBasket->getBasketSummary();
256 if ( $this->oxdiscount__oxamount->value && ( $oSummary->iArticleCount < $this->oxdiscount__oxamount->value || $oSummary->iArticleCount > $this->oxdiscount__oxamountto->value ) ) {
259 } elseif ($this->oxdiscount__oxprice->value) {
260 $dRate = $oBasket->getBasketCurrency()->rate;
261 if ( $oSummary->dArticleDiscountablePrice < $this->oxdiscount__oxprice->value*$dRate || $oSummary->dArticleDiscountablePrice > $this->oxdiscount__oxpriceto->value*$dRate ) {
268 $sQ =
'select 1 from oxobject2discount where oxdiscountid = ' . $oDb->quote($this->oxdiscount__oxid->value).
' and oxtype in ("oxarticles", "oxcategories" ) ';
270 return !( (bool) $oDb->getOne( $sQ ) );
282 if ( $this->oxdiscount__oxaddsumtype->value !=
'itm' ) {
287 $sQ =
"select 1 from oxobject2discount where oxdiscountid=".$oDb->quote( $this->
getId() );
289 if ( !( $blOk = (
bool) $oDb->getOne( $sQ ) ) ) {
305 if ( $this->oxdiscount__oxaddsumtype->value !=
'itm' ) {
322 if ( $this->oxdiscount__oxaddsumtype->value ==
'%' ) {
323 return $dPrice * ( $this->oxdiscount__oxaddsum->value / 100 );
325 $oCur = $this->
getConfig()->getActShopCurrencyObject();
326 return $this->oxdiscount__oxaddsum->value * $dAmount * $oCur->rate;
342 if ( $this->oxdiscount__oxaddsumtype->value ==
'abs' ) {
343 $oCur = $this->
getConfig()->getActShopCurrencyObject();
344 $oPrice->subtract( $this->oxdiscount__oxaddsum->value * $oCur->rate );
346 $oPrice->multiply( (100 - $this->oxdiscount__oxaddsum->value) / 100 );
349 if ( $oPrice->getBruttoPrice() < 0 || $oPrice->getNettoPrice() < 0 ) {
350 $oPrice->setPrice(0);
364 return $this->
getAddSum() / $dPrice * 100;
380 if ( $this->oxdiscount__oxaddsumtype->value ==
'abs' ) {
381 $oCur = $this->
getConfig()->getActShopCurrencyObject();
382 return $this->oxdiscount__oxaddsum->value * $oCur->rate;
384 return $this->oxdiscount__oxaddsum->value;
395 return $this->oxdiscount__oxaddsumtype->value;
410 $dItemAmount = $this->oxdiscount__oxitmamount->value;
413 if ( $this->oxdiscount__oxitmmultiple->value && $this->oxdiscount__oxamount->value > 0 ) {
414 $dItemAmount = floor( $dAmount / $this->oxdiscount__oxamount->value ) * $this->oxdiscount__oxitmamount->value;
430 $aCatIds = $oArticle->getCategoryIds();
431 if (!$aCatIds || !count($aCatIds)) {
440 $sQ =
"select oxobjectid from oxobject2discount where oxdiscountid = ".$oDb->quote($this->oxdiscount__oxid->value).
" and oxobjectid in $sCatIds and oxtype = 'oxcategories'";
442 return $oDb->getOne( $sQ );
452 $oDiscount =
new stdClass();
453 $oDiscount->sOXID = $this->
getId();
454 $oDiscount->sDiscount = $this->oxdiscount__oxtitle->value;
455 $oDiscount->sType = $this->oxdiscount__oxaddsumtype->value;
467 return oxDb::getDb()->getCol(
"select `oxobjectid` from oxobject2discount where oxdiscountid = '".$this->
getId().
"' and oxtype = 'oxarticles'");
477 return oxDb::getDb()->getCol(
"select `oxobjectid` from oxobject2discount where oxdiscountid = '".$this->
getId().
"' and oxtype = 'oxcategories'");
492 if ( ( $sParentId = $oProduct->getProductParentId() ) ) {
493 $sArticleId =
" and ( oxobjectid = ".$oDb->quote( $oProduct->getProductId() ).
" or oxobjectid = ".$oDb->quote( $sParentId ) .
" )";
495 $sArticleId =
" and oxobjectid = ".$oDb->quote( $oProduct->getProductId() );