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: class Mage_Checkout_Helper_Data extends Mage_Core_Helper_Abstract
33: {
34: const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout';
35: const XML_PATH_CUSTOMER_MUST_BE_LOGGED = 'checkout/options/customer_must_be_logged';
36:
37: protected $_agreements = null;
38:
39: 40: 41: 42: 43:
44: public function getCheckout()
45: {
46: return Mage::getSingleton('checkout/session');
47: }
48:
49: 50: 51: 52: 53:
54: public function getQuote()
55: {
56: return $this->getCheckout()->getQuote();
57: }
58:
59: public function formatPrice($price)
60: {
61: return $this->getQuote()->getStore()->formatPrice($price);
62: }
63:
64: public function convertPrice($price, $format=true)
65: {
66: return $this->getQuote()->getStore()->convertPrice($price, $format);
67: }
68:
69: public function getRequiredAgreementIds()
70: {
71: if (is_null($this->_agreements)) {
72: if (!Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
73: $this->_agreements = array();
74: } else {
75: $this->_agreements = Mage::getModel('checkout/agreement')->getCollection()
76: ->addStoreFilter(Mage::app()->getStore()->getId())
77: ->addFieldToFilter('is_active', 1)
78: ->getAllIds();
79: }
80: }
81: return $this->_agreements;
82: }
83:
84: 85: 86: 87: 88:
89: public function canOnepageCheckout()
90: {
91: return (bool)Mage::getStoreConfig('checkout/options/onepage_checkout_enabled');
92: }
93:
94: 95: 96: 97: 98: 99:
100: public function getPriceInclTax($item)
101: {
102: if ($item->getPriceInclTax()) {
103: return $item->getPriceInclTax();
104: }
105: $qty = ($item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1));
106: $taxAmount = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
107: $price = (floatval($qty)) ? ($item->getRowTotal() + $taxAmount)/$qty : 0;
108: return Mage::app()->getStore()->roundPrice($price);
109: }
110:
111: 112: 113: 114: 115: 116:
117: public function getSubtotalInclTax($item)
118: {
119: if ($item->getRowTotalInclTax()) {
120: return $item->getRowTotalInclTax();
121: }
122: $tax = $item->getTaxAmount() + $item->getDiscountTaxCompensation();
123: return $item->getRowTotal() + $tax;
124: }
125:
126: public function getBasePriceInclTax($item)
127: {
128: $qty = ($item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1));
129: $taxAmount = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
130: $price = (floatval($qty)) ? ($item->getBaseRowTotal() + $taxAmount)/$qty : 0;
131: return Mage::app()->getStore()->roundPrice($price);
132: }
133:
134: public function getBaseSubtotalInclTax($item)
135: {
136: $tax = $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensation();
137: return $item->getBaseRowTotal()+$tax;
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147:
148: public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
149: {
150: $translate = Mage::getSingleton('core/translate');
151:
152: $translate->setTranslateInline(false);
153:
154: $mailTemplate = Mage::getModel('core/email_template');
155:
156:
157: $template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
158:
159: $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
160: $copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId());
161: if ($copyTo && $copyMethod == 'bcc') {
162: $mailTemplate->addBcc($copyTo);
163: }
164:
165: $_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId());
166: $sendTo = array(
167: array(
168: 'email' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/email', $checkout->getStoreId()),
169: 'name' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/name', $checkout->getStoreId())
170: )
171: );
172:
173: if ($copyTo && $copyMethod == 'copy') {
174: foreach ($copyTo as $email) {
175: $sendTo[] = array(
176: 'email' => $email,
177: 'name' => null
178: );
179: }
180: }
181: $shippingMethod = '';
182: if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
183: $data = explode('_', $shippingInfo);
184: $shippingMethod = $data[0];
185: }
186:
187: $paymentMethod = '';
188: if ($paymentInfo = $checkout->getPayment()) {
189: $paymentMethod = $paymentInfo->getMethod();
190: }
191:
192: $items = '';
193: foreach ($checkout->getAllVisibleItems() as $_item) {
194:
195: $items .= $_item->getProduct()->getName() . ' x '. $_item->getQty() . ' '
196: . $checkout->getStoreCurrencyCode() . ' '
197: . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
198: }
199: $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
200:
201: foreach ($sendTo as $recipient) {
202: $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$checkout->getStoreId()))
203: ->sendTransactional(
204: $template,
205: Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()),
206: $recipient['email'],
207: $recipient['name'],
208: array(
209: 'reason' => $message,
210: 'checkoutType' => $checkoutType,
211: 'dateAndTime' => Mage::app()->getLocale()->date(),
212: 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(),
213: 'customerEmail' => $checkout->getCustomerEmail(),
214: 'billingAddress' => $checkout->getBillingAddress(),
215: 'shippingAddress' => $checkout->getShippingAddress(),
216: 'shippingMethod' => Mage::getStoreConfig('carriers/'.$shippingMethod.'/title'),
217: 'paymentMethod' => Mage::getStoreConfig('payment/'.$paymentMethod.'/title'),
218: 'items' => nl2br($items),
219: 'total' => $total
220: )
221: );
222: }
223:
224: $translate->setTranslateInline(true);
225:
226: return $this;
227: }
228:
229: protected function _getEmails($configPath, $storeId)
230: {
231: $data = Mage::getStoreConfig($configPath, $storeId);
232: if (!empty($data)) {
233: return explode(',', $data);
234: }
235: return false;
236: }
237:
238: 239: 240: 241: 242: 243:
244: public function isMultishippingCheckoutAvailable()
245: {
246: $quote = $this->getQuote();
247: $isMultiShipping = (bool)(int)Mage::getStoreConfig('shipping/option/checkout_multiple');
248: if ((!$quote) || !$quote->hasItems()) {
249: return $isMultiShipping;
250: }
251: $maximunQty = (int)Mage::getStoreConfig('shipping/option/checkout_multiple_maximum_qty');
252: return $isMultiShipping
253: && !$quote->hasItemsWithDecimalQty()
254: && $quote->validateMinimumAmount(true)
255: && (($quote->getItemsSummaryQty() - $quote->getItemVirtualQty()) > 0)
256: && ($quote->getItemsSummaryQty() <= $maximunQty)
257: && !$quote->hasNominalItems()
258: ;
259: }
260:
261: 262: 263: 264: 265: 266: 267: 268:
269: public function isAllowedGuestCheckout(Mage_Sales_Model_Quote $quote, $store = null)
270: {
271: if ($store === null) {
272: $store = $quote->getStoreId();
273: }
274: $guestCheckout = Mage::getStoreConfigFlag(self::XML_PATH_GUEST_CHECKOUT, $store);
275:
276: if ($guestCheckout == true) {
277: $result = new Varien_Object();
278: $result->setIsAllowed($guestCheckout);
279: Mage::dispatchEvent('checkout_allow_guest', array(
280: 'quote' => $quote,
281: 'store' => $store,
282: 'result' => $result
283: ));
284:
285: $guestCheckout = $result->getIsAllowed();
286: }
287:
288: return $guestCheckout;
289: }
290:
291: 292: 293: 294: 295:
296: public function isContextCheckout()
297: {
298: return (Mage::app()->getRequest()->getParam('context') == 'checkout');
299: }
300:
301: 302: 303: 304: 305:
306: public function isCustomerMustBeLogged()
307: {
308: return Mage::getStoreConfigFlag(self::XML_PATH_CUSTOMER_MUST_BE_LOGGED);
309: }
310: }
311: