00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 class Mage_Weee_Helper_Data extends Mage_Core_Helper_Abstract
00031 {
00032
00033 const XML_PATH_FPT_ENABLED = 'tax/weee/enable';
00034
00035 protected $_storeDisplayConfig = array();
00036
00037 public function getPriceDisplayType($store = null)
00038 {
00039 if (!is_null($store)) {
00040 if ($store instanceof Mage_Core_Model_Store) {
00041 $key = $store->getId();
00042 } else {
00043 $key = $store;
00044 }
00045 } else {
00046 $key = 'current';
00047 }
00048
00049 if (!isset($this->_storeDisplayConfig[$key])) {
00050 $value = Mage::getStoreConfig('tax/weee/display', $store);
00051 $this->_storeDisplayConfig[$key] = $value;
00052 }
00053
00054 return $this->_storeDisplayConfig[$key];
00055 }
00056
00057 public function getListPriceDisplayType($store = null)
00058 {
00059 if (!is_null($store)) {
00060 if ($store instanceof Mage_Core_Model_Store) {
00061 $key = $store->getId();
00062 } else {
00063 $key = $store;
00064 }
00065 } else {
00066 $key = 'current';
00067 }
00068
00069 if (!isset($this->_storeDisplayConfig[$key])) {
00070 $value = Mage::getStoreConfig('tax/weee/display_list', $store);
00071 $this->_storeDisplayConfig[$key] = $value;
00072 }
00073
00074 return $this->_storeDisplayConfig[$key];
00075 }
00076
00077 public function getSalesPriceDisplayType($store = null)
00078 {
00079 if (!is_null($store)) {
00080 if ($store instanceof Mage_Core_Model_Store) {
00081 $key = $store->getId();
00082 } else {
00083 $key = $store;
00084 }
00085 } else {
00086 $key = 'current';
00087 }
00088
00089 if (!isset($this->_storeDisplayConfig[$key])) {
00090 $value = Mage::getStoreConfig('tax/weee/display_sales', $store);
00091 $this->_storeDisplayConfig[$key] = $value;
00092 }
00093
00094 return $this->_storeDisplayConfig[$key];
00095 }
00096
00097 public function getEmailPriceDisplayType($store = null)
00098 {
00099 if (!is_null($store)) {
00100 if ($store instanceof Mage_Core_Model_Store) {
00101 $key = $store->getId();
00102 } else {
00103 $key = $store;
00104 }
00105 } else {
00106 $key = 'current';
00107 }
00108
00109 if (!isset($this->_storeDisplayConfig[$key])) {
00110 $value = Mage::getStoreConfig('tax/weee/display_email', $store);
00111 $this->_storeDisplayConfig[$key] = $value;
00112 }
00113
00114 return $this->_storeDisplayConfig[$key];
00115 }
00116
00117 public function getAmount($product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false)
00118 {
00119 if ($this->isEnabled()) {
00120 return Mage::getSingleton('weee/tax')->getWeeeAmount($product, $shipping, $billing, $website, $calculateTaxes);
00121 }
00122 return 0;
00123 }
00124
00125 public function typeOfDisplay($product, $compareTo = null, $zone = null, $store = null)
00126 {
00127 $type = 0;
00128 switch ($zone) {
00129 case 'product_view':
00130 $type = $this->getPriceDisplayType($store);
00131 break;
00132
00133 case 'product_list':
00134 $type = $this->getListPriceDisplayType($store);
00135 break;
00136
00137 case 'sales':
00138 $type = $this->getSalesPriceDisplayType($store);
00139 break;
00140
00141 case 'email':
00142 $type = $this->getEmailPriceDisplayType($store);
00143 break;
00144
00145 default:
00146 if (Mage::registry('current_product')) {
00147 $type = $this->getPriceDisplayType($store);
00148 } else {
00149 $type = $this->getListPriceDisplayType($store);
00150 }
00151 break;
00152 }
00153
00154 if (is_null($compareTo)) {
00155 return $type;
00156 } else {
00157 if (is_array($compareTo)) {
00158 return in_array($type, $compareTo);
00159 } else {
00160 return $type == $compareTo;
00161 }
00162 }
00163 }
00164
00165 public function getProductWeeeAttributes($product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false)
00166 {
00167 return Mage::getSingleton('weee/tax')->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTaxes);
00168 }
00169
00170 public function getApplied($item)
00171 {
00172 if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract) {
00173 if ($item->getHasChildren() && $item->isChildrenCalculated()) {
00174 $result = array();
00175 foreach ($item->getChildren() as $child) {
00176 $childData = $this->getApplied($child);
00177 if (is_array($childData)) {
00178 $result = array_merge($result, $childData);
00179 }
00180 }
00181 return $result;
00182 }
00183 }
00184
00185
00186
00187
00188
00189 $data = $item->getWeeeTaxApplied();
00190 if (empty($data)){
00191 return array();
00192 }
00193 return unserialize($item->getWeeeTaxApplied());
00194 }
00195
00196 public function setApplied($item, $value)
00197 {
00198 $item->setWeeeTaxApplied(serialize($value));
00199 return $this;
00200 }
00201
00202 public function isDiscounted($store = null)
00203 {
00204 return Mage::getStoreConfigFlag('tax/weee/discount', $store);
00205 }
00206
00207 public function isTaxable($store = null)
00208 {
00209 return Mage::getStoreConfigFlag('tax/weee/apply_vat', $store);
00210 }
00211
00212 public function includeInSubtotal($store = null)
00213 {
00214 return Mage::getStoreConfigFlag('tax/weee/include_in_subtotal', $store);
00215 }
00216
00217 public function getProductWeeeAttributesForDisplay($product)
00218 {
00219 if ($this->isEnabled()) {
00220 return $this->getProductWeeeAttributes($product, null, null, null, $this->typeOfDisplay($product, 1));
00221 }
00222 return array();
00223 }
00224
00225
00226 public function getAmountForDisplay($product)
00227 {
00228 if ($this->isEnabled()) {
00229 return Mage::getModel('weee/tax')->getWeeeAmount($product, null, null, null, $this->typeOfDisplay($product, 1));
00230 }
00231 return 0;
00232 }
00233
00234 public function getOriginalAmount($product)
00235 {
00236 if ($this->isEnabled()) {
00237 return Mage::getModel('weee/tax')->getWeeeAmount($product, null, null, null, false, true);
00238 }
00239 return 0;
00240 }
00241
00242 public function processTierPrices($product, &$tierPrices)
00243 {
00244 $weeeAmount = $this->getAmountForDisplay($product);
00245 foreach ($tierPrices as &$tier) {
00246 $tier['formated_price_incl_weee'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $tier['website_price'], true)+$weeeAmount));
00247 $tier['formated_price_incl_weee_only'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice(Mage::helper('tax')->getPrice($product, $tier['website_price'])+$weeeAmount));
00248 $tier['formated_weee'] = Mage::app()->getStore()->formatPrice(Mage::app()->getStore()->convertPrice($weeeAmount));
00249 }
00250 return $this;
00251 }
00252
00253
00254
00255
00256
00257
00258 public function isEnabled($store = null)
00259 {
00260 return Mage::getStoreConfig(self::XML_PATH_FPT_ENABLED, $store);
00261 }
00262 }