Public Member Functions | |
getWeeeAmount ($product, $shipping=null, $billing=null, $website=null, $calculateTax=false, $ignoreDiscount=false) | |
getWeeeAttributeCodes ($forceEnabled=false) | |
getWeeeTaxAttributeCodes ($forceEnabled=false) | |
getProductWeeeAttributes ($product, $shipping=null, $billing=null, $website=null, $calculateTax=null, $ignoreDiscount=false) | |
updateDiscountPercents () | |
Protected Member Functions | |
_construct () | |
_getDiscountPercentForProduct ($product) | |
Protected Attributes | |
$_allAttributes = null | |
$_productDiscounts = array() |
Definition at line 21 of file Tax.php.
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Definition at line 26 of file Tax.php.
00027 { 00028 $this->_init('weee/tax', 'weee/tax'); 00029 }
_getDiscountPercentForProduct | ( | $ | product | ) | [protected] |
Definition at line 140 of file Tax.php.
00141 { 00142 $website = Mage::app()->getStore()->getWebsiteId(); 00143 $group = Mage::getSingleton('customer/session')->getCustomerGroupId(); 00144 $key = implode('-', array($website, $group, $product->getId())); 00145 if (!isset($this->_productDiscounts[$key])) { 00146 $this->_productDiscounts[$key] = (int) $this->getResource()->getProductDiscountPercent($product->getId(), $website, $group); 00147 } 00148 if ($value = $this->_productDiscounts[$key]) { 00149 return 100-min(100, max(0, $value)); 00150 } else { 00151 return 0; 00152 } 00153 }
getProductWeeeAttributes | ( | $ | product, | |
$ | shipping = null , |
|||
$ | billing = null , |
|||
$ | website = null , |
|||
$ | calculateTax = null , |
|||
$ | ignoreDiscount = false | |||
) |
Definition at line 58 of file Tax.php.
00059 { 00060 $result = array(); 00061 $allWeee = $this->getWeeeTaxAttributeCodes(); 00062 if (!$allWeee) { 00063 return $result; 00064 } 00065 00066 $websiteId = Mage::app()->getWebsite($website)->getId(); 00067 $store = Mage::app()->getWebsite($website)->getDefaultGroup()->getDefaultStore(); 00068 00069 if ($shipping) { 00070 $customerTaxClass = $shipping->getQuote()->getCustomerTaxClassId(); 00071 } else { 00072 $customerTaxClass = null; 00073 } 00074 00075 $rateRequest = Mage::getModel('tax/calculation')->getRateRequest($shipping, $billing, $customerTaxClass, $store); 00076 $defaultRateRequest = Mage::getModel('tax/calculation')->getRateRequest(false, false, false, $store); 00077 00078 $discountPercent = 0; 00079 if (!$ignoreDiscount && Mage::helper('weee')->isDiscounted($store)) { 00080 $discountPercent = $this->_getDiscountPercentForProduct($product); 00081 } 00082 00083 $productAttributes = $product->getTypeInstance(true)->getSetAttributes($product); 00084 foreach ($productAttributes as $code=>$attribute) { 00085 if (in_array($code, $allWeee)) { 00086 $attributeId = $attribute->getId(); 00087 00088 $attributeSelect = $this->getResource()->getReadConnection()->select(); 00089 $attributeSelect->from($this->getResource()->getTable('weee/tax'), 'value'); 00090 00091 $on = array(); 00092 $on[] = "attribute_id = '{$attributeId}'"; 00093 $on[] = "(website_id in ('{$websiteId}', 0))"; 00094 00095 $country = $rateRequest->getCountryId(); 00096 $on[] = "(country = '{$country}')"; 00097 00098 $region = $rateRequest->getRegionId(); 00099 $on[] = "(state in ('{$region}', '*'))"; 00100 00101 foreach ($on as $one) { 00102 $attributeSelect->where($one); 00103 } 00104 $attributeSelect->where('entity_id = ?', $product->getId()); 00105 $attributeSelect->limit(1); 00106 00107 $order = array('state DESC', 'website_id DESC'); 00108 00109 $attributeSelect->order($order); 00110 $value = $this->getResource()->getReadConnection()->fetchOne($attributeSelect); 00111 if ($value) { 00112 if ($discountPercent) { 00113 $value = Mage::app()->getStore()->roundPrice($value-($value*$discountPercent/100)); 00114 } 00115 00116 $taxAmount = $amount = 0; 00117 $amount = $value; 00118 00119 if ($calculateTax && Mage::helper('weee')->isTaxable($store)) { 00120 $defaultPercent = Mage::getModel('tax/calculation')->getRate($defaultRateRequest->setProductClassId($product->getTaxClassId())); 00121 $currentPercent = $product->getTaxPercent(); 00122 00123 $taxAmount = Mage::app()->getStore()->roundPrice($value/(100+$defaultPercent)*$currentPercent); 00124 $amount = $value - $taxAmount; 00125 } 00126 00127 $one = new Varien_Object(); 00128 $one->setName(Mage::helper('catalog')->__($attribute->getFrontend()->getLabel())) 00129 ->setAmount($amount) 00130 ->setTaxAmount($taxAmount) 00131 ->setCode($attribute->getAttributeCode()); 00132 00133 $result[] = $one; 00134 } 00135 } 00136 } 00137 return $result; 00138 }
getWeeeAmount | ( | $ | product, | |
$ | shipping = null , |
|||
$ | billing = null , |
|||
$ | website = null , |
|||
$ | calculateTax = false , |
|||
$ | ignoreDiscount = false | |||
) |
Definition at line 31 of file Tax.php.
00032 { 00033 $amount = 0; 00034 $attributes = $this->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTax, $ignoreDiscount); 00035 foreach ($attributes as $attribute) { 00036 $amount += $attribute->getAmount(); 00037 } 00038 return $amount; 00039 }
getWeeeAttributeCodes | ( | $ | forceEnabled = false |
) |
Definition at line 41 of file Tax.php.
00042 { 00043 return $this->getWeeeTaxAttributeCodes($forceEnabled); 00044 }
getWeeeTaxAttributeCodes | ( | $ | forceEnabled = false |
) |
Definition at line 46 of file Tax.php.
00047 { 00048 if (!$forceEnabled && !Mage::helper('weee')->isEnabled()) { 00049 return array(); 00050 } 00051 00052 if (is_null($this->_allAttributes)) { 00053 $this->_allAttributes = Mage::getModel('eav/entity_attribute')->getAttributeCodesByFrontendType('weee'); 00054 } 00055 return $this->_allAttributes; 00056 }
updateDiscountPercents | ( | ) |
Definition at line 155 of file Tax.php.
00156 { 00157 $this->getResource()->updateDiscountPercents(); 00158 return $this; 00159 }