oxpricealarm.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxPricealarm extends oxBase
00009 {
00010 
00016     protected $_sClassName = 'oxpricealarm';
00017 
00023     protected $_oArticle = null;
00024 
00030     protected $_fPrice = null;
00031 
00037     protected $_dPrice = null;
00038 
00044     protected $_sTitle = null;
00045 
00051     protected $_oCurrency = null;
00052 
00058     protected $_fProposedPrice = null;
00059 
00065     protected $_iStatus = null;
00066 
00071     public function __construct()
00072     {
00073         parent::__construct();
00074         $this->init('oxpricealarm');
00075     }
00076 
00082     protected function _insert()
00083     {
00084         // set oxinsert value
00085         $this->oxpricealarm__oxinsert = new oxField(date('Y-m-d', oxRegistry::get("oxUtilsDate")->getTime()));
00086 
00087         return parent::_insert();
00088     }
00089 
00095     public function getArticle()
00096     {
00097         if ($this->_oArticle == null) {
00098             $this->_oArticle = false;
00099             $oArticle = oxNew("oxarticle");
00100             if ($oArticle->load($this->oxpricealarm__oxartid->value)) {
00101                 $this->_oArticle = $oArticle;
00102             }
00103         }
00104 
00105         return $this->_oArticle;
00106     }
00107 
00113     public function getFPrice()
00114     {
00115         if ($this->_fPrice == null) {
00116             $this->_fPrice = false;
00117             if ($dArtPrice = $this->getPrice()) {
00118                 $myLang = oxRegistry::getLang();
00119                 $oThisCurr = $this->getPriceAlarmCurrency();
00120                 $this->_fPrice = $myLang->formatCurrency($dArtPrice, $oThisCurr);
00121             }
00122         }
00123 
00124         return $this->_fPrice;
00125     }
00126 
00132     public function getPrice()
00133     {
00134         if ($this->_dPrice == null) {
00135             $this->_dPrice = false;
00136             if ($oArticle = $this->getArticle()) {
00137                 $myUtils = oxRegistry::getUtils();
00138                 $oThisCurr = $this->getPriceAlarmCurrency();
00139 
00140                 // #889C - Netto prices in Admin
00141                 // (we have to call $oArticle->getPrice() to get price with VAT)
00142                 $dArtPrice = $oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate;
00143                 $dArtPrice = $myUtils->fRound($dArtPrice);
00144 
00145                 $this->_dPrice = $dArtPrice;
00146             }
00147         }
00148 
00149         return $this->_dPrice;
00150     }
00151 
00157     public function getTitle()
00158     {
00159         if ($this->_sTitle == null) {
00160             $this->_sTitle = false;
00161             if ($oArticle = $this->getArticle()) {
00162                 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00163                 if ($oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00164                     $oParent = oxNew("oxarticle");
00165                     $oParent->load($oArticle->oxarticles__oxparentid->value);
00166                     $this->_sTitle = $oParent->oxarticles__oxtitle->value . " " . $oArticle->oxarticles__oxvarselect->value;
00167                 }
00168             }
00169         }
00170 
00171         return $this->_sTitle;
00172     }
00173 
00179     public function getPriceAlarmCurrency()
00180     {
00181         if ($this->_oCurrency == null) {
00182             $this->_oCurrency = false;
00183             $myConfig = $this->getConfig();
00184             $oThisCurr = $myConfig->getCurrencyObject($this->oxpricealarm__oxcurrency->value);
00185 
00186             // #869A we should perform currency conversion
00187             // (older versions doesn't have currency info - assume as it is default - first in currency array)
00188             if (!$oThisCurr) {
00189                 $oDefCurr = $myConfig->getActShopCurrencyObject();
00190                 $oThisCurr = $myConfig->getCurrencyObject($oDefCurr->name);
00191                 $this->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00192             }
00193             $this->_oCurrency = $oThisCurr;
00194         }
00195 
00196         return $this->_oCurrency;
00197     }
00198 
00204     public function getFProposedPrice()
00205     {
00206         if ($this->_fProposedPrice == null) {
00207             $this->_fProposedPrice = false;
00208             if ($oThisCurr = $this->getPriceAlarmCurrency()) {
00209                 $myLang = oxRegistry::getLang();
00210                 $this->_fProposedPrice = $myLang->formatCurrency($this->oxpricealarm__oxprice->value, $oThisCurr);
00211             }
00212         }
00213 
00214         return $this->_fProposedPrice;
00215     }
00216 
00222     public function getPriceAlarmStatus()
00223     {
00224         if ($this->_iStatus == null) {
00225             // neutral status
00226             $this->_iStatus = 0;
00227 
00228             // shop price is less or equal
00229             $dArtPrice = $this->getPrice();
00230             if ($this->oxpricealarm__oxprice->value >= $dArtPrice) {
00231                 $this->_iStatus = 1;
00232             }
00233 
00234             // suggestion to user is sent
00235             if ($this->oxpricealarm__oxsended->value != "0000-00-00 00:00:00") {
00236                 $this->_iStatus = 2;
00237             }
00238         }
00239 
00240         return $this->_iStatus;
00241     }
00242 }