oxpricealarm.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxPricealarm extends oxBase
00008 {
00014     protected $_sClassName = 'oxpricealarm';
00015 
00021     protected $_oArticle = null;
00022 
00028     protected $_fPrice = null;
00029 
00035     protected $_dPrice = null;
00036 
00042     protected $_sTitle = null;
00043 
00049     protected $_oCurrency = null;
00050 
00056     protected $_fProposedPrice = null;
00057 
00063     protected $_iStatus = null;
00064 
00069     public function __construct()
00070     {
00071         parent::__construct();
00072         $this->init( 'oxpricealarm' );
00073     }
00074 
00080     protected function _insert()
00081     {
00082         // set oxinsert value
00083         $this->oxpricealarm__oxinsert = new oxField(date( 'Y-m-d', oxUtilsDate::getInstance()->getTime() ));
00084 
00085         return parent::_insert();
00086     }
00087 
00093     public function getArticle()
00094     {
00095         if ( $this->_oArticle == null ) {
00096             $this->_oArticle = false;
00097             $oArticle = oxNew( "oxarticle" );
00098             if ( $oArticle->load($this->oxpricealarm__oxartid->value) ) {
00099                 $this->_oArticle = $oArticle;
00100             }
00101         }
00102         return $this->_oArticle;
00103     }
00104 
00110     public function getFPrice()
00111     {
00112         if ( $this->_fPrice == null ) {
00113             $this->_fPrice = false;
00114             if ( $dArtPrice = $this->getPrice() ) {
00115                 $myLang    = oxLang::getInstance();
00116                 $oThisCurr = $this->getPriceAlarmCurrency();
00117                 $this->_fPrice = $myLang->formatCurrency( $dArtPrice, $oThisCurr );
00118             }
00119         }
00120         return $this->_fPrice;
00121     }
00122 
00128     public function getPrice()
00129     {
00130         if ( $this->_dPrice == null ) {
00131             $this->_dPrice = false;
00132             if ( $oArticle = $this->getArticle() ) {
00133                 $myUtils  = oxUtils::getInstance();
00134                 $oThisCurr = $this->getPriceAlarmCurrency();
00135 
00136                 // #889C - Netto prices in Admin
00137                 // (we have to call $oArticle->getPrice() to get price with VAT)
00138                 $dArtPrice = $oArticle->getPrice()->getBruttoPrice() * $oThisCurr->rate;
00139                 $dArtPrice = $myUtils->fRound( $dArtPrice );
00140 
00141                 $this->_dPrice = $dArtPrice;
00142             }
00143         }
00144         return $this->_dPrice;
00145     }
00146 
00152     public function getTitle()
00153     {
00154         if ( $this->_sTitle == null ) {
00155             $this->_sTitle = false;
00156             if ( $oArticle = $this->getArticle() ) {
00157                 $this->_sTitle = $oArticle->oxarticles__oxtitle->value;
00158                 if ( $oArticle->oxarticles__oxparentid->value && !$oArticle->oxarticles__oxtitle->value) {
00159                     $oParent = oxNew( "oxarticle" );
00160                     $oParent->load( $oArticle->oxarticles__oxparentid->value );
00161                     $this->_sTitle = $oParent->oxarticles__oxtitle->value . " " . $oArticle->oxarticles__oxvarselect->value;
00162                 }
00163             }
00164         }
00165         return $this->_sTitle;
00166     }
00167 
00173     public function getPriceAlarmCurrency()
00174     {
00175         if ( $this->_oCurrency == null ) {
00176             $this->_oCurrency = false;
00177             $myConfig = $this->getConfig();
00178             $oThisCurr = $myConfig->getCurrencyObject( $this->oxpricealarm__oxcurrency->value );
00179 
00180             // #869A we should perform currency conversion
00181             // (older versions doesn't have currency info - assume as it is default - first in currency array)
00182             if ( !$oThisCurr ) {
00183                 $oDefCurr  = $myConfig->getActShopCurrencyObject();
00184                 $oThisCurr = $myConfig->getCurrencyObject( $oDefCurr->name );
00185                 $this->oxpricealarm__oxcurrency->setValue($oDefCurr->name);
00186             }
00187             $this->_oCurrency = $oThisCurr;
00188         }
00189         return $this->_oCurrency;
00190     }
00191 
00197     public function getFProposedPrice()
00198     {
00199         if ( $this->_fProposedPrice == null ) {
00200             $this->_fProposedPrice = false;
00201             if ( $oThisCurr = $this->getPriceAlarmCurrency() ) {
00202                 $myLang   = oxLang::getInstance();
00203                 $this->_fProposedPrice = $myLang->formatCurrency( $this->oxpricealarm__oxprice->value, $oThisCurr);
00204             }
00205         }
00206         return $this->_fProposedPrice;
00207     }
00208 
00214     public function getPriceAlarmStatus()
00215     {
00216         if ( $this->_iStatus == null ) {
00217             // neutral status
00218             $this->_iStatus = 0;
00219 
00220             // shop price is less or equal
00221             $dArtPrice = $this->getPrice();
00222             if ( $this->oxpricealarm__oxprice->value >= $dArtPrice) {
00223                 $this->_iStatus = 1;
00224             }
00225 
00226             // suggestion to user is sent
00227             if ( $this->oxpricealarm__oxsended->value != "0000-00-00 00:00:00") {
00228                 $this->_iStatus = 2;
00229             }
00230         }
00231         return $this->_iStatus;
00232     }
00233 }