00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Mage_Checkout_Helper_Data extends Mage_Core_Helper_Abstract
00033 {
00034 const XML_PATH_GUEST_CHECKOUT = 'checkout/options/guest_checkout';
00035
00036 protected $_agreements = null;
00037
00038
00039
00040
00041
00042
00043 public function getCheckout()
00044 {
00045 return Mage::getSingleton('checkout/session');
00046 }
00047
00048
00049
00050
00051
00052
00053 public function getQuote()
00054 {
00055 return $this->getCheckout()->getQuote();
00056 }
00057
00058 public function formatPrice($price)
00059 {
00060 return $this->getQuote()->getStore()->formatPrice($price);
00061 }
00062
00063 public function convertPrice($price, $format=true)
00064 {
00065 return $this->getQuote()->getStore()->convertPrice($price, $format);
00066 }
00067
00068 public function getRequiredAgreementIds()
00069 {
00070 if (is_null($this->_agreements)) {
00071 if (!Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
00072 $this->_agreements = array();
00073 } else {
00074 $this->_agreements = Mage::getModel('checkout/agreement')->getCollection()
00075 ->addStoreFilter(Mage::app()->getStore()->getId())
00076 ->addFieldToFilter('is_active', 1)
00077 ->getAllIds();
00078 }
00079 }
00080 return $this->_agreements;
00081 }
00082
00083
00084
00085
00086
00087
00088 public function canOnepageCheckout()
00089 {
00090 if (Mage::getStoreConfig('checkout/options/onepage_checkout_disabled')) {
00091 return false;
00092 }
00093 return true;
00094 }
00095
00096 public function getPriceInclTax($item)
00097 {
00098
00099 $qty = ($item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1));
00100
00101
00102 $price = Mage::app()->getStore()->roundPrice(($item->getRowTotal()+$item->getTaxAmount())/$qty);
00103 return $price;
00104 }
00105
00106 public function getSubtotalInclTax($item)
00107 {
00108 if ($item instanceof Mage_Sales_Model_Order_Item) {
00109 $store = $item->getOrder()->getStore();
00110 } elseif($item instanceof Mage_Sales_Model_Order_Invoice_Item) {
00111 $store = $item->getInvoice()->getOrder()->getStore();
00112 } elseif($item instanceof Mage_Sales_Model_Order_Shipment_Item) {
00113 $store = $item->getShipment()->getOrder()->getStore();
00114 } elseif($item instanceof Mage_Sales_Model_Order_Creditmemo_Item) {
00115 $store = $item->getCreditmemo()->getOrder()->getStore();
00116 } else {
00117 $store = $item->getQuote()->getStore();
00118 }
00119 if (!Mage::helper('tax')->applyTaxAfterDiscount($store) and $item->getTaxBeforeDiscount()) {
00120 $tax = $item->getTaxBeforeDiscount();
00121 } else {
00122 $tax = $item->getTaxAmount();
00123 }
00124 return $item->getRowTotal() + $tax;
00125 }
00126
00127 public function getBasePriceInclTax($item)
00128 {
00129
00130 $qty = ($item->getQty() ? $item->getQty() : ($item->getQtyOrdered() ? $item->getQtyOrdered() : 1));
00131
00132
00133 $price = Mage::app()->getStore()->roundPrice(($item->getBaseRowTotal()+$item->getBaseTaxAmount())/$qty);
00134 return $price;
00135 }
00136
00137 public function getBaseSubtotalInclTax($item)
00138 {
00139 $tax = ($item->getBaseTaxBeforeDiscount() ? $item->getBaseTaxBeforeDiscount() : $item->getBaseTaxAmount());
00140 return $item->getBaseRowTotal()+$tax;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage')
00152 {
00153 $translate = Mage::getSingleton('core/translate');
00154
00155 $translate->setTranslateInline(false);
00156
00157 $mailTemplate = Mage::getModel('core/email_template');
00158
00159
00160 $template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId());
00161
00162 $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId());
00163 $copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId());
00164 if ($copyTo && $copyMethod == 'bcc') {
00165 $mailTemplate->addBcc($copyTo);
00166 }
00167
00168 $_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId());
00169 $sendTo = array(
00170 array(
00171 'email' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/email', $checkout->getStoreId()),
00172 'name' => Mage::getStoreConfig('trans_email/ident_'.$_reciever.'/name', $checkout->getStoreId())
00173 )
00174 );
00175
00176 if ($copyTo && $copyMethod == 'copy') {
00177 foreach ($copyTo as $email) {
00178 $sendTo[] = array(
00179 'email' => $email,
00180 'name' => null
00181 );
00182 }
00183 }
00184 $shippingMethod = '';
00185 if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) {
00186 $data = explode('_', $shippingInfo);
00187 $shippingMethod = $data[0];
00188 }
00189
00190 $paymentMethod = '';
00191 if ($paymentInfo = $checkout->getPayment()) {
00192 $paymentMethod = $paymentInfo->getMethod();
00193 }
00194
00195 $items = '';
00196 foreach ($checkout->getItemsCollection() as $_item) {
00197
00198 $items .= $_item->getProduct()->getName() . ' x '. $_item->getQty() . ' '
00199 . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n";
00200 }
00201 $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal();
00202
00203 foreach ($sendTo as $recipient) {
00204 $mailTemplate->setDesignConfig(array('area'=>'frontend', 'store'=>$checkout->getStoreId()))
00205 ->sendTransactional(
00206 $template,
00207 Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()),
00208 $recipient['email'],
00209 $recipient['name'],
00210 array(
00211 'reason' => $message,
00212 'checkoutType' => $checkoutType,
00213 'dateAndTime' => Mage::app()->getLocale()->date(),
00214 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(),
00215 'customerEmail' => $checkout->getCustomerEmail(),
00216 'billingAddress' => $checkout->getBillingAddress(),
00217 'shippingAddress' => $checkout->getShippingAddress(),
00218 'shippingMethod' => Mage::getStoreConfig('carriers/'.$shippingMethod.'/title'),
00219 'paymentMethod' => Mage::getStoreConfig('payment/'.$paymentMethod.'/title'),
00220 'items' => nl2br($items),
00221 'total' => $total
00222 )
00223 );
00224 }
00225
00226 $translate->setTranslateInline(true);
00227
00228 return $this;
00229 }
00230
00231 protected function _getEmails($configPath, $storeId)
00232 {
00233 $data = Mage::getStoreConfig($configPath, $storeId);
00234 if (!empty($data)) {
00235 return explode(',', $data);
00236 }
00237 return false;
00238 }
00239
00240
00241
00242
00243
00244
00245
00246 public function isMultishippingCheckoutAvailable()
00247 {
00248 $quote = $this->getQuote();
00249 $isMultiShipping = (bool)(int)Mage::getStoreConfig('shipping/option/checkout_multiple');
00250 if ((!$quote) || !$quote->hasItems()) {
00251 return $isMultiShipping;
00252 }
00253 $maximunQty = (int)Mage::getStoreConfig('shipping/option/checkout_multiple_maximum_qty');
00254 return $isMultiShipping
00255 && !$quote->hasItemsWithDecimalQty()
00256 && $quote->validateMinimumAmount(true)
00257 && (($quote->getItemsSummaryQty() - $quote->getItemVirtualQty()) > 0)
00258 && ($quote->getItemsSummaryQty() <= $maximunQty)
00259 ;
00260 }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 public function isAllowedGuestCheckout(Mage_Sales_Model_Quote $quote, $store = null)
00271 {
00272 $guestCheckout = Mage::getStoreConfigFlag(self::XML_PATH_GUEST_CHECKOUT, $store);
00273
00274 if ($guestCheckout == true) {
00275 $result = new Varien_Object();
00276 $result->setIsAllowed($guestCheckout);
00277 Mage::dispatchEvent('checkout_allow_guest', array(
00278 'quote' => $quote,
00279 'store' => $store,
00280 'result' => $result
00281 ));
00282
00283 $guestCheckout = $result->getIsAllowed();
00284 }
00285
00286 return $guestCheckout;
00287 }
00288 }