oxvatselector.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxVatSelector extends oxSuperCfg
00009 {
00015     protected static $_aUserVatCache = array();
00016 
00026     public function getUserVat(oxUser $oUser, $blCacheReset = false)
00027     {
00028         if (!$blCacheReset) {
00029             if (self::$_aUserVatCache[$oUser->getId()] !== null) {
00030                 return self::$_aUserVatCache[$oUser->getId()];
00031             }
00032         }
00033 
00034         $ret = false;
00035 
00036         if ($sCountryId = $oUser->oxuser__oxcountryid->value) {
00037             $oCountry = oxNew('oxcountry');
00038             if (!$oCountry->load($sCountryId)) {
00039                 throw new oxObjectException();
00040             }
00041             if ($oCountry->isForeignCountry()) {
00042                 $ret = $this->_getForeignCountryUserVat($oUser, $oCountry);
00043             }
00044         }
00045 
00046         self::$_aUserVatCache[$oUser->getId()] = $ret;
00047         return $ret;
00048     }
00049 
00058     protected function _getForeignCountryUserVat(oxUser $oUser, oxCountry $oCountry )
00059     {
00060         if ($oCountry->isInEU()) {
00061             if ($oUser->oxuser__oxustid->value && $oUser->oxuser__oxcompany->value) {
00062                 return 0;
00063             }
00064             return false;
00065         }
00066 
00067         return 0;
00068     }
00069 
00077     protected function _getVatForArticleCategory(oxArticle $oArticle)
00078     {
00079         //return false;
00080         //if (count($aCats)) {
00081         //$sMainCat  = $aCats[0];
00082         //$aCats = $oArticle->getCategoryIds();
00083 
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 = oxDb::getDb()->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 = oxDb::getDb()->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 Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5