oxpricealarm.php

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