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_Paypal_Block_Express_Review extends Mage_Core_Block_Template
35: {
36: 37: 38:
39: protected $_quote;
40:
41: 42: 43: 44: 45:
46: protected $_currentShippingRate = null;
47:
48: 49: 50: 51: 52:
53: protected $_paypalActionPrefix = 'paypal';
54:
55: 56: 57: 58: 59: 60:
61: public function setQuote(Mage_Sales_Model_Quote $quote)
62: {
63: $this->_quote = $quote;
64: return $this;
65: }
66:
67: 68: 69: 70: 71:
72: public function getBillingAddress()
73: {
74: return $this->_quote->getBillingAddress();
75: }
76:
77: 78: 79: 80: 81:
82: public function getShippingAddress()
83: {
84: if ($this->_quote->getIsVirtual()) {
85: return false;
86: }
87: return $this->_quote->getShippingAddress();
88: }
89:
90: 91: 92: 93: 94: 95:
96: public function renderAddress($address)
97: {
98: return $address->getFormated(true);
99: }
100:
101: 102: 103: 104: 105: 106:
107: public function getCarrierName($carrierCode)
108: {
109: if ($name = Mage::getStoreConfig("carriers/{$carrierCode}/title")) {
110: return $name;
111: }
112: return $carrierCode;
113: }
114:
115: 116: 117: 118: 119: 120:
121: public function renderShippingRateValue(Varien_Object $rate)
122: {
123: if ($rate->getErrorMessage()) {
124: return '';
125: }
126: return $rate->getCode();
127: }
128:
129: 130: 131: 132: 133: 134: 135: 136:
137: public function renderShippingRateOption($rate, $format = '%s - %s%s', $inclTaxFormat = ' (%s %s)')
138: {
139: $renderedInclTax = '';
140: if ($rate->getErrorMessage()) {
141: $price = $rate->getErrorMessage();
142: } else {
143: $price = $this->_getShippingPrice($rate->getPrice(),
144: $this->helper('tax')->displayShippingPriceIncludingTax());
145:
146: $incl = $this->_getShippingPrice($rate->getPrice(), true);
147: if (($incl != $price) && $this->helper('tax')->displayShippingBothPrices()) {
148: $renderedInclTax = sprintf($inclTaxFormat, Mage::helper('tax')->__('Incl. Tax'), $incl);
149: }
150: }
151: return sprintf($format, $rate->getMethodTitle(), $price, $renderedInclTax);
152: }
153:
154: 155: 156: 157: 158:
159: public function getCurrentShippingRate()
160: {
161: return $this->_currentShippingRate;
162: }
163:
164: 165: 166:
167: public function setPaypalActionPrefix($prefix)
168: {
169: $this->_paypalActionPrefix = $prefix;
170: }
171:
172: 173: 174: 175: 176: 177: 178: 179:
180: protected function _getShippingPrice($price, $isInclTax)
181: {
182: return $this->_formatPrice($this->helper('tax')->getShippingPrice($price, $isInclTax, $this->_address));
183: }
184:
185: 186: 187: 188: 189: 190:
191: protected function _formatPrice($price)
192: {
193: return $this->_quote->getStore()->convertPrice($price, true);
194: }
195:
196: 197: 198: 199: 200:
201: protected function _beforeToHtml()
202: {
203: $methodInstance = $this->_quote->getPayment()->getMethodInstance();
204: $this->setPaymentMethodTitle($methodInstance->getTitle());
205: $this->setUpdateOrderSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateOrder"));
206: $this->setUpdateShippingMethodsUrl($this->getUrl("{$this->_paypalActionPrefix}/express/updateShippingMethods"));
207:
208: $this->setShippingRateRequired(true);
209: if ($this->_quote->getIsVirtual()) {
210: $this->setShippingRateRequired(false);
211: } else {
212:
213: $this->_address = $this->_quote->getShippingAddress();
214: $groups = $this->_address->getGroupedAllShippingRates();
215: if ($groups && $this->_address) {
216: $this->setShippingRateGroups($groups);
217:
218: foreach ($groups as $code => $rates) {
219: foreach ($rates as $rate) {
220: if ($this->_address->getShippingMethod() == $rate->getCode()) {
221: $this->_currentShippingRate = $rate;
222: break(2);
223: }
224: }
225: }
226: }
227:
228:
229: $this->setShippingMethodSubmitUrl($this->getUrl("{$this->_paypalActionPrefix}/express/saveShippingMethod"))
230: ->setCanEditShippingAddress($this->_quote->getMayEditShippingAddress())
231: ->setCanEditShippingMethod($this->_quote->getMayEditShippingMethod())
232: ;
233: }
234:
235: $this->setEditUrl($this->getUrl("{$this->_paypalActionPrefix}/express/edit"))
236: ->setPlaceOrderUrl($this->getUrl("{$this->_paypalActionPrefix}/express/placeOrder"));
237:
238: return parent::_beforeToHtml();
239: }
240: }
241: