1: <?php
2: /**
3: * Magento
4: *
5: * NOTICE OF LICENSE
6: *
7: * This source file is subject to the Open Software License (OSL 3.0)
8: * that is bundled with this package in the file LICENSE.txt.
9: * It is also available through the world-wide-web at this URL:
10: * http://opensource.org/licenses/osl-3.0.php
11: * If you did not receive a copy of the license and are unable to
12: * obtain it through the world-wide-web, please send an email
13: * to license@magentocommerce.com so we can send you a copy immediately.
14: *
15: * DISCLAIMER
16: *
17: * Do not edit or add to this file if you wish to upgrade Magento to newer
18: * versions in the future. If you wish to customize Magento for your
19: * needs please refer to http://www.magentocommerce.com for more information.
20: *
21: * @category Mage
22: * @package Mage_XmlConnect
23: * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
24: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25: */
26:
27: /**
28: * PayPal MEP Shopping cart totals xml renderer
29: *
30: * @category Mage
31: * @package Mage_Xmlconnect
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_XmlConnect_Block_Cart_Paypal_Mep_Totals extends Mage_Checkout_Block_Cart_Totals
35: {
36: /**
37: * Render cart totals xml
38: *
39: * @return string
40: */
41: protected function _toHtml()
42: {
43: /** @var $paypalCart Mage_Paypal_Model_Cart */
44: $paypalCart = Mage::getModel('paypal/cart', array($this->getQuote()));
45: /** @var $totalsXmlObj Mage_XmlConnect_Model_Simplexml_Element */
46: $totalsXmlObj = Mage::getModel('xmlconnect/simplexml_element', '<cart_totals></cart_totals>');
47: foreach ($paypalCart->getTotals(true) as $code => $amount) {
48: $currencyAmount = $this->helper('core')->currency($amount, false, false);
49: $totalsXmlObj->addChild($code, sprintf('%01.2F', $currencyAmount));
50: }
51:
52: $paypalTotals = $totalsXmlObj->addChild('paypal_totals');
53: foreach ($this->getQuote()->getTotals() as $total) {
54: $code = $total->getCode();
55: if ($code == 'giftcardaccount' || $code == 'giftwrapping') {
56: continue;
57: }
58: $renderer = $this->_getTotalRenderer($code)->setTotal($total);
59: switch ($code) {
60: case 'subtotal':
61: $subtotal = intval($total->getValueExclTax()) ? $total->getValueExclTax() : $total->getValue();
62: $paypalTotals->addAttribute(
63: $code,
64: Mage::helper('xmlconnect')->formatPriceForXml($subtotal)
65: );
66: break;
67: case 'tax':
68: $paypalTotals->addAttribute(
69: $code,
70: Mage::helper('xmlconnect')->formatPriceForXml($total->getValue())
71: );
72: break;
73: case 'shipping':
74: $paypalTotals->addAttribute(
75: $code,
76: Mage::helper('xmlconnect')->formatPriceForXml($renderer->getShippingExcludeTax())
77: );
78: break;
79: default:
80: break;
81: }
82: }
83:
84: return $totalsXmlObj->asNiceXml();
85: }
86: }
87: