1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Weee_Helper_Data extends Mage_Core_Helper_Abstract
35: {
36:
37: const XML_PATH_FPT_ENABLED = 'tax/weee/enable';
38:
39: protected $_storeDisplayConfig = array();
40:
41: 42: 43: 44: 45: 46:
47: public function getPriceDisplayType($store = null)
48: {
49: return Mage::getStoreConfig('tax/weee/display', $store);
50: }
51:
52: 53: 54: 55: 56: 57:
58: public function getListPriceDisplayType($store = null)
59: {
60: return Mage::getStoreConfig('tax/weee/display_list', $store);
61: }
62:
63: 64: 65: 66: 67: 68:
69: public function getSalesPriceDisplayType($store = null)
70: {
71: return Mage::getStoreConfig('tax/weee/display_sales', $store);
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function getEmailPriceDisplayType($store = null)
81: {
82: return Mage::getStoreConfig('tax/weee/display_email', $store);
83: }
84:
85: 86: 87: 88: 89: 90:
91: public function isDiscounted($store = null)
92: {
93: return Mage::getStoreConfigFlag('tax/weee/discount', $store);
94: }
95:
96: 97: 98: 99: 100: 101:
102: public function isTaxable($store = null)
103: {
104: return Mage::getStoreConfigFlag('tax/weee/apply_vat', $store);
105: }
106:
107: 108: 109: 110: 111: 112:
113: public function includeInSubtotal($store = null)
114: {
115: return Mage::getStoreConfigFlag('tax/weee/include_in_subtotal', $store);
116: }
117:
118: 119: 120: 121: 122: 123: 124: 125: 126: 127:
128: public function getAmount($product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false)
129: {
130: if ($this->isEnabled()) {
131: return Mage::getSingleton('weee/tax')->
132: getWeeeAmount($product, $shipping, $billing, $website, $calculateTaxes);
133: }
134: return 0;
135: }
136:
137: 138: 139: 140: 141: 142: 143: 144: 145:
146: public function typeOfDisplay($product, $compareTo = null, $zone = null, $store = null)
147: {
148: if (!$this->isEnabled($store)) {
149: return false;
150: }
151: switch ($zone) {
152: case 'product_view':
153: $type = $this->getPriceDisplayType($store);
154: break;
155: case 'product_list':
156: $type = $this->getListPriceDisplayType($store);
157: break;
158: case 'sales':
159: $type = $this->getSalesPriceDisplayType($store);
160: break;
161: case 'email':
162: $type = $this->getEmailPriceDisplayType($store);
163: break;
164: default:
165: if (Mage::registry('current_product')) {
166: $type = $this->getPriceDisplayType($store);
167: } else {
168: $type = $this->getListPriceDisplayType($store);
169: }
170: break;
171: }
172:
173: if (is_null($compareTo)) {
174: return $type;
175: } else {
176: if (is_array($compareTo)) {
177: return in_array($type, $compareTo);
178: } else {
179: return $type == $compareTo;
180: }
181: }
182: }
183:
184: 185: 186: 187: 188: 189: 190: 191: 192: 193:
194: public function getProductWeeeAttributes($product, $shipping = null, $billing = null,
195: $website = null, $calculateTaxes = false)
196: {
197: return Mage::getSingleton('weee/tax')
198: ->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTaxes);
199: }
200:
201: 202: 203: 204: 205: 206:
207: public function getApplied($item)
208: {
209: if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract) {
210: if ($item->getHasChildren() && $item->isChildrenCalculated()) {
211: $result = array();
212: foreach ($item->getChildren() as $child) {
213: $childData = $this->getApplied($child);
214: if (is_array($childData)) {
215: $result = array_merge($result, $childData);
216: }
217: }
218: return $result;
219: }
220: }
221:
222: 223: 224: 225:
226: $data = $item->getWeeeTaxApplied();
227: if (empty($data)){
228: return array();
229: }
230: return unserialize($item->getWeeeTaxApplied());
231: }
232:
233: 234: 235: 236: 237: 238: 239:
240: public function setApplied($item, $value)
241: {
242: $item->setWeeeTaxApplied(serialize($value));
243: return $this;
244: }
245:
246: 247: 248: 249: 250: 251:
252: public function getProductWeeeAttributesForDisplay($product)
253: {
254: if ($this->isEnabled()) {
255: return $this->getProductWeeeAttributes($product, null, null, null, $this->typeOfDisplay($product, 1));
256: }
257: return array();
258: }
259:
260: 261: 262: 263: 264: 265: 266: 267: 268: 269:
270: public function getProductWeeeAttributesForRenderer($product, $shipping = null, $billing = null,
271: $website = null, $calculateTaxes = false)
272: {
273: if ($this->isEnabled()) {
274: return $this->getProductWeeeAttributes(
275: $product,
276: $shipping,
277: $billing,
278: $website,
279: $calculateTaxes ? $calculateTaxes : $this->typeOfDisplay($product, 1)
280: );
281: }
282: return array();
283: }
284:
285: 286: 287: 288: 289: 290:
291: public function getAmountForDisplay($product)
292: {
293: if ($this->isEnabled()) {
294: return Mage::getModel('weee/tax')
295: ->getWeeeAmount($product, null, null, null, $this->typeOfDisplay($product, 1));
296: }
297: return 0;
298: }
299:
300: 301: 302: 303: 304: 305:
306: public function getOriginalAmount($product)
307: {
308: if ($this->isEnabled()) {
309: return Mage::getModel('weee/tax')->getWeeeAmount($product, null, null, null, false, true);
310: }
311: return 0;
312: }
313:
314: 315: 316: 317: 318: 319: 320:
321: public function processTierPrices($product, &$tierPrices)
322: {
323: $weeeAmount = $this->getAmountForDisplay($product);
324: $store = Mage::app()->getStore();
325: foreach ($tierPrices as $index => &$tier) {
326: $html = $store->formatPrice($store->convertPrice(
327: Mage::helper('tax')->getPrice($product, $tier['website_price'], true)+$weeeAmount), false);
328: $tier['formated_price_incl_weee'] = '<span class="price tier-' . $index . '-incl-tax">' . $html . '</span>';
329: $html = $store->formatPrice($store->convertPrice(
330: Mage::helper('tax')->getPrice($product, $tier['website_price'])+$weeeAmount), false);
331: $tier['formated_price_incl_weee_only'] = '<span class="price tier-' . $index . '">' . $html . '</span>';
332: $tier['formated_weee'] = $store->formatPrice($store->convertPrice($weeeAmount));
333: }
334: return $this;
335: }
336:
337: 338: 339: 340: 341: 342:
343: public function isEnabled($store = null)
344: {
345: return Mage::getStoreConfig(self::XML_PATH_FPT_ENABLED, $store);
346: }
347:
348: 349: 350: 351: 352: 353: 354:
355: public function getAmountInclTaxes($attributes)
356: {
357: if (is_array($attributes)) {
358: $amount = 0;
359: foreach ($attributes as $attribute) {
360:
361: $amount += $attribute->getAmount() + $attribute->getTaxAmount();
362: }
363: } else {
364: throw new Mage_Exception('$attributes must be an array');
365: }
366:
367: return (float)$amount;
368: }
369: }
370: