oxvatselector.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxVatSelector extends oxSuperCfg
00008 {
00014     protected static $_aUserVatCache = array();
00015 
00025     public function getUserVat(oxUser $oUser, $blCacheReset = false)
00026     {
00027         if (!$blCacheReset) {
00028             if (self::$_aUserVatCache[$oUser->getId()] !== null) {
00029                 return self::$_aUserVatCache[$oUser->getId()];
00030             }
00031         }
00032 
00033         $ret = false;
00034 
00035         if ($sCountryId = $oUser->oxuser__oxcountryid->value) {
00036             $oCountry = oxNew('oxcountry');
00037             if (!$oCountry->load($sCountryId)) {
00038                 throw new oxObjectException();
00039             }
00040             if ($oCountry->isForeignCountry()) {
00041                 $ret = $this->_getForeignCountryUserVat($oUser, $oCountry);
00042             }
00043         }
00044 
00045         self::$_aUserVatCache[$oUser->getId()] = $ret;
00046         return $ret;
00047     }
00048 
00057     protected function _getForeignCountryUserVat(oxUser $oUser, oxCountry $oCountry )
00058     {
00059         if ($oCountry->isInEU()) {
00060             if ($oUser->oxuser__oxustid->value && $oUser->oxuser__oxcompany->value) {
00061                 return 0;
00062             }
00063             return false;
00064         }
00065 
00066         return 0;
00067     }
00068 
00076     protected function _getVatForArticleCategory(oxArticle $oArticle)
00077     {
00078         //return false;
00079         //if (count($aCats)) {
00080         //$sMainCat  = $aCats[0];
00081         //$aCats = $oArticle->getCategoryIds();
00082 
00083         $oDb = oxDb::getDb();
00084         $sCatT = getViewName('oxcategories');
00085         $sSelect = "SELECT oxid
00086                     FROM $sCatT
00087                     WHERE oxvat IS NOT NULL LIMIT 1";
00088 
00089         //no category specific vats in shop?
00090         //then for performance reasons we just return false
00091         $iCount = $oDb->getOne($sSelect);
00092         if (!$iCount) {
00093             return false;
00094         }
00095 
00096         $sO2C = getViewName('oxobject2category');
00097         $sSql = "SELECT c.oxvat
00098                  FROM $sCatT AS c, $sO2C AS o2c
00099                  WHERE c.oxid=o2c.oxcatnid AND
00100                        o2c.oxobjectid = '".$oArticle->getId()."' AND
00101                        c.oxvat IS NOT NULL
00102                  ORDER BY o2c.oxtime ";
00103 
00104         //echo $sSql."<br>";
00105 
00106         $fVat = $oDb->getOne($sSql);
00107         if ($fVat !== false && $fVat !== null) {
00108             return $fVat;
00109         }
00110 
00111         //}
00112         return false;
00113     }
00114 
00122     public function getArticleVat(oxArticle $oArticle)
00123     {
00124         startProfile("_assignPriceInternal");
00125         // article has its own VAT ?
00126 
00127         if ( ( $dArticleVat = $oArticle->getCustomVAT() ) !== null ) {
00128             stopProfile("_assignPriceInternal");
00129             return $dArticleVat;
00130         }
00131         if ( ( $dArticleVat = $this->_getVatForArticleCategory($oArticle) ) !== false ) {
00132             stopProfile("_assignPriceInternal");
00133             return $dArticleVat;
00134         }
00135 
00136         stopProfile("_assignPriceInternal");
00137         return $this->getConfig()->getConfigParam( 'dDefaultVAT' );
00138     }
00139 
00150     public function getBasketItemVat(oxArticle $oArticle, $oBasket )
00151     {
00152         return $this->getArticleVat( $oArticle );
00153     }
00154 }

Generated on Tue Apr 21 15:45:45 2009 for OXID eShop CE by  doxygen 1.5.5