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_XmlConnect_Block_Catalog_Product_Price_Bundle extends Mage_Bundle_Block_Catalog_Product_Price
35: {
36: 37: 38: 39: 40: 41:
42: public function collectProductPrices(
43: Mage_Catalog_Model_Product $product, Mage_XmlConnect_Model_Simplexml_Element $item
44: ) {
45: $this->setProduct($product)->setDisplayMinimalPrice(true) ->setUseLinkForAsLowAs(false);
46:
47: $priceXmlObj = $item->addChild('price');
48:
49:
50: $_coreHelper = $this->helper('core');
51:
52: $_weeeHelper = $this->helper('weee');
53:
54: $_taxHelper = $this->helper('tax');
55:
56: $_tierPrices = $this->_getTierPrices($product);
57:
58: if (count($_tierPrices) > 0) {
59: $tierPricesTextArray = array();
60: foreach ($_tierPrices as $_price) {
61: $discount = ' ' . ($_price['price'] * 1) . '%';
62: $tierPricesTextArray[] = $this->__('Buy %1$s with %2$s discount each', $_price['price_qty'], $discount);
63: }
64: $item->addChild('price_tier', implode(PHP_EOL, $tierPricesTextArray));
65: }
66:
67: list($_minimalPrice, $_maximalPrice) = $product->getPriceModel()->getPrices($product);
68:
69: $_weeeTaxAmount = 0;
70: $_minimalPriceTax = $_taxHelper->getPrice($product, $_minimalPrice);
71: $_minimalPriceInclTax = $_taxHelper->getPrice($product, $_minimalPrice, true);
72:
73: if ($product->getPriceType() == 1) {
74: $_weeeTaxAmount = $_weeeHelper->getAmount($product);
75: if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) {
76: $_minimalPriceTax += $_weeeTaxAmount;
77: $_minimalPriceInclTax += $_weeeTaxAmount;
78: }
79: if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
80: $_minimalPriceInclTax += $_weeeTaxAmount;
81: }
82:
83: if ($_weeeHelper->typeOfDisplay($product, array(1, 2, 4))) {
84: $_weeeTaxAttributes = $_weeeHelper->getProductWeeeAttributesForDisplay($product);
85: }
86: }
87:
88: if ($product->getPriceView()) {
89: if ($_taxHelper->displayBothPrices()) {
90: $priceXmlObj->addAttribute(
91: 'as_low_as_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)
92: );
93: if ($_weeeTaxAmount && $product->getPriceType() == 1
94: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
95: ) {
96: $weeeXmlObj = $priceXmlObj->addChild('weee');
97: $_weeeSeparator = ' + ';
98: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
99: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
100: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
101: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
102: } else {
103: $amount = $_weeeTaxAttribute->getAmount();
104: }
105: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
106: $weeeItemXmlObj->addAttribute(
107: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
108: );
109: $weeeItemXmlObj->addAttribute(
110: 'amount', $_coreHelper->currency($amount, true, false)
111: );
112: }
113: }
114: $priceXmlObj->addAttribute(
115: 'as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
116: );
117: } else {
118: $priceXmlObj->addAttribute(
119: 'as_low_as', $_coreHelper->currency($_minimalPriceTax, true, false)
120: );
121: if ($_weeeTaxAmount && $product->getPriceType() == 1
122: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
123: ) {
124: $weeeXmlObj = $priceXmlObj->addChild('weee');
125: $_weeeSeparator = ' + ';
126: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
127: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
128: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
129: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
130: } else {
131: $amount = $_weeeTaxAttribute->getAmount();
132: }
133: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
134: $weeeItemXmlObj->addAttribute(
135: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
136: );
137: $weeeItemXmlObj->addAttribute(
138: 'amount', $_coreHelper->currency($amount, true, false)
139: );
140: }
141: }
142: if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
143: $priceXmlObj->addAttribute(
144: 'as_low_as_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
145: );
146: }
147: }
148: 149: 150:
151: } else {
152: if ($_minimalPrice <> $_maximalPrice) {
153: if ($_taxHelper->displayBothPrices()) {
154: $priceXmlObj->addAttribute(
155: 'from_excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)
156: );
157: if ($_weeeTaxAmount && $product->getPriceType() == 1
158: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
159: ) {
160: $weeeXmlObj = $priceXmlObj->addChild('from_weee');
161: $_weeeSeparator = ' + ';
162: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
163: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
164: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
165: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
166: } else {
167: $amount = $_weeeTaxAttribute->getAmount();
168: }
169: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
170: $weeeItemXmlObj->addAttribute(
171: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
172: );
173: $weeeItemXmlObj->addAttribute(
174: 'amount', $_coreHelper->currency($amount, true, false)
175: );
176: }
177: }
178: $priceXmlObj->addAttribute(
179: 'from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
180: );
181: } else {
182: $priceXmlObj->addAttribute('from', $_coreHelper->currency($_minimalPriceTax, true, false));
183: if ($_weeeTaxAmount && $product->getPriceType() == 1
184: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
185: ) {
186: $weeeXmlObj = $priceXmlObj->addChild('from_weee');
187: $_weeeSeparator = ' + ';
188: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
189: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
190: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
191: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
192: } else {
193: $amount = $_weeeTaxAttribute->getAmount();
194: }
195: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
196: $weeeItemXmlObj->addAttribute(
197: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
198: );
199: $weeeItemXmlObj->addAttribute('amount', $_coreHelper->currency($amount, true, false));
200: }
201: }
202: if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
203: $priceXmlObj->addAttribute(
204: 'from_including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
205: );
206: }
207: }
208:
209: $_maximalPriceTax = Mage::helper('tax')->getPrice($product, $_maximalPrice);
210: $_maximalPriceInclTax = Mage::helper('tax')->getPrice($product, $_maximalPrice, true);
211:
212: if ($product->getPriceType() == 1) {
213: if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, array(0, 1, 4))) {
214: $_maximalPriceTax += $_weeeTaxAmount;
215: $_maximalPriceInclTax += $_weeeTaxAmount;
216: }
217: if ($_weeeTaxAmount && $_weeeHelper->typeOfDisplay($product, 2)) {
218: $_maximalPriceInclTax += $_weeeTaxAmount;
219: }
220: }
221:
222: if ($_taxHelper->displayBothPrices()) {
223: $priceXmlObj->addAttribute(
224: 'to_excluding_tax', $_coreHelper->currency($_maximalPriceTax, true, false)
225: );
226: if ($_weeeTaxAmount && $product->getPriceType() == 1
227: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
228: ) {
229: $weeeXmlObj = $priceXmlObj->addChild('to_weee');
230: $_weeeSeparator = ' + ';
231: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
232: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
233: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
234: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
235: } else {
236: $amount = $_weeeTaxAttribute->getAmount();
237: }
238: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
239: $weeeItemXmlObj->addAttribute(
240: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
241: );
242: $weeeItemXmlObj->addAttribute(
243: 'amount', $_coreHelper->currency($amount, true, false)
244: );
245: }
246: }
247: $priceXmlObj->addAttribute(
248: 'to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false)
249: );
250: } else {
251: $priceXmlObj->addAttribute(
252: 'to', $_coreHelper->currency($_maximalPriceTax, true, false)
253: );
254: if ($_weeeTaxAmount && $product->getPriceType() == 1
255: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
256: ) {
257: $weeeXmlObj = $priceXmlObj->addChild('to_weee');
258: $_weeeSeparator = ' + ';
259: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
260: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
261: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
262: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
263: } else {
264: $amount = $_weeeTaxAttribute->getAmount();
265: }
266: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
267: $weeeItemXmlObj->addAttribute(
268: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
269: );
270: $weeeItemXmlObj->addAttribute(
271: 'amount', $_coreHelper->currency($amount, true, false)
272: );
273: }
274: }
275: if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
276: $priceXmlObj->addAttribute(
277: 'to_including_tax', $_coreHelper->currency($_maximalPriceInclTax, true, false)
278: );
279: }
280: }
281: 282: 283:
284: } else {
285: if ($_taxHelper->displayBothPrices()) {
286: $priceXmlObj->addAttribute(
287: 'excluding_tax', $_coreHelper->currency($_minimalPriceTax, true, false)
288: );
289: if ($_weeeTaxAmount && $product->getPriceType() == 1
290: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
291: ) {
292: $weeeXmlObj = $priceXmlObj->addChild('weee');
293: $_weeeSeparator = ' + ';
294: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
295: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
296: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
297: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
298: } else {
299: $amount = $_weeeTaxAttribute->getAmount();
300: }
301: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
302: $weeeItemXmlObj->addAttribute(
303: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
304: );
305: $weeeItemXmlObj->addAttribute(
306: 'amount', $_coreHelper->currency($amount, true, false)
307: );
308: }
309: }
310: $priceXmlObj->addAttribute(
311: 'including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
312: );
313: } else {
314: $priceXmlObj->addAttribute(
315: 'regular', $_coreHelper->currency($_minimalPriceTax, true, false)
316: );
317: if ($_weeeTaxAmount && $product->getPriceType() == 1
318: && $_weeeHelper->typeOfDisplay($product, array(2, 1, 4))
319: ) {
320: $weeeXmlObj = $priceXmlObj->addChild('weee');
321: $_weeeSeparator = ' + ';
322: $weeeXmlObj->addAttribute('separator', $_weeeSeparator);
323: foreach ($_weeeTaxAttributes as $_weeeTaxAttribute) {
324: if ($_weeeHelper->typeOfDisplay($product, array(2, 4))) {
325: $amount = $_weeeTaxAttribute->getAmount() + $_weeeTaxAttribute->getTaxAmount();
326: } else {
327: $amount = $_weeeTaxAttribute->getAmount();
328: }
329: $weeeItemXmlObj = $weeeXmlObj->addChild('item');
330: $weeeItemXmlObj->addAttribute(
331: 'name', $weeeItemXmlObj->escapeXml($_weeeTaxAttribute->getName())
332: );
333: $weeeItemXmlObj->addAttribute(
334: 'amount', $_coreHelper->currency($amount, true, false)
335: );
336: }
337: }
338: if ($_weeeHelper->typeOfDisplay($product, 2) && $_weeeTaxAmount) {
339: $priceXmlObj->addAttribute(
340: 'including_tax', $_coreHelper->currency($_minimalPriceInclTax, true, false)
341: );
342: }
343: }
344: }
345: }
346: }
347:
348: 349: 350: 351: 352: 353:
354: protected function _getTierPrices($product)
355: {
356: if (is_null($product)) {
357: return array();
358: }
359: $prices = $product->getFormatedTierPrice();
360:
361: $res = array();
362: if (is_array($prices)) {
363: foreach ($prices as $price) {
364: $price['price_qty'] = $price['price_qty']*1;
365: $price['savePercent'] = ceil(100 - $price['price']);
366: $price['formated_price'] = Mage::app()->getStore()->formatPrice(
367: Mage::app()->getStore()->convertPrice(
368: Mage::helper('tax')->getPrice($product, $price['website_price'])
369: ),
370: false
371: );
372: $price['formated_price_incl_tax'] = Mage::app()->getStore()->formatPrice(
373: Mage::app()->getStore()->convertPrice(
374: Mage::helper('tax')->getPrice($product, $price['website_price'], true)
375: ),
376: false
377: );
378: $res[] = $price;
379: }
380: }
381:
382: return $res;
383: }
384: }
385: