/** * Convert quote model to order model * * @param Mage_Sales_Model_Quote $quote * @return Mage_Sales_Model_Order */ public function toOrder(Mage_Sales_Model_Quote $quote, $order = null) { if (!$order instanceof Mage_Sales_Model_Order) { $order = Mage::getModel('sales/order'); } /* @var $order Mage_Sales_Model_Order */ $order->setStoreId($quote->getStoreId())->setQuoteId($quote->getId())->setRemoteIp($quote->getRemoteIp())->setCustomerId($quote->getCustomerId())->setCustomerEmail($quote->getCustomerEmail())->setCustomerFirstname($quote->getCustomerFirstname())->setCustomerLastname($quote->getCustomerLastname())->setCustomerGroupId($quote->getCustomerGroupId())->setCustomerTaxClassId($quote->getCustomerTaxClassId())->setCustomerNote($quote->getCustomerNote())->setCustomerNoteNotify($quote->getCustomerNoteNotify())->setCustomerIsGuest($quote->getCustomerIsGuest())->setBaseCurrencyCode($quote->getBaseCurrencyCode())->setStoreCurrencyCode($quote->getStoreCurrencyCode())->setOrderCurrencyCode($quote->getQuoteCurrencyCode())->setStoreToBaseRate($quote->getStoreToBaseRate())->setStoreToOrderRate($quote->getStoreToQuoteRate())->setCouponCode($quote->getCouponCode())->setGiftcertCode($quote->getGiftcertCode())->setIsVirtual($quote->getIsVirtual())->setIsMultiPayment($quote->getIsMultiPayment())->setAppliedRuleIds($quote->getAppliedRuleIds()); Mage::dispatchEvent('sales_convert_quote_to_order', array('order' => $order, 'quote' => $quote)); return $order; }
/** * Send email id payment was failed * * @param Mage_Sales_Model_Quote $checkout * @param string $message * @param string $checkoutType * @return Mage_Checkout_Helper_Data */ public function sendPaymentFailedEmail($checkout, $message, $checkoutType = 'onepage') { $translate = Mage::getSingleton('Mage_Core_Model_Translate'); /* @var $translate Mage_Core_Model_Translate */ $translate->setTranslateInline(false); $mailTemplate = Mage::getModel('Mage_Core_Model_Email_Template'); /* @var $mailTemplate Mage_Core_Model_Email_Template */ $template = Mage::getStoreConfig('checkout/payment_failed/template', $checkout->getStoreId()); $copyTo = $this->_getEmails('checkout/payment_failed/copy_to', $checkout->getStoreId()); $copyMethod = Mage::getStoreConfig('checkout/payment_failed/copy_method', $checkout->getStoreId()); if ($copyTo && $copyMethod == 'bcc') { $mailTemplate->addBcc($copyTo); } $_reciever = Mage::getStoreConfig('checkout/payment_failed/reciever', $checkout->getStoreId()); $sendTo = array(array('email' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/email', $checkout->getStoreId()), 'name' => Mage::getStoreConfig('trans_email/ident_' . $_reciever . '/name', $checkout->getStoreId()))); if ($copyTo && $copyMethod == 'copy') { foreach ($copyTo as $email) { $sendTo[] = array('email' => $email, 'name' => null); } } $shippingMethod = ''; if ($shippingInfo = $checkout->getShippingAddress()->getShippingMethod()) { $data = explode('_', $shippingInfo); $shippingMethod = $data[0]; } $paymentMethod = ''; if ($paymentInfo = $checkout->getPayment()) { $paymentMethod = $paymentInfo->getMethod(); } $items = ''; foreach ($checkout->getAllVisibleItems() as $_item) { /* @var $_item Mage_Sales_Model_Quote_Item */ $items .= $_item->getProduct()->getName() . ' x ' . $_item->getQty() . ' ' . $checkout->getStoreCurrencyCode() . ' ' . $_item->getProduct()->getFinalPrice($_item->getQty()) . "\n"; } $total = $checkout->getStoreCurrencyCode() . ' ' . $checkout->getGrandTotal(); foreach ($sendTo as $recipient) { $mailTemplate->setDesignConfig(array('area' => Mage_Core_Model_App_Area::AREA_FRONTEND, 'store' => $checkout->getStoreId()))->sendTransactional($template, Mage::getStoreConfig('checkout/payment_failed/identity', $checkout->getStoreId()), $recipient['email'], $recipient['name'], array('reason' => $message, 'checkoutType' => $checkoutType, 'dateAndTime' => Mage::app()->getLocale()->date(), 'customer' => $checkout->getCustomerFirstname() . ' ' . $checkout->getCustomerLastname(), 'customerEmail' => $checkout->getCustomerEmail(), 'billingAddress' => $checkout->getBillingAddress(), 'shippingAddress' => $checkout->getShippingAddress(), 'shippingMethod' => Mage::getStoreConfig('carriers/' . $shippingMethod . '/title'), 'paymentMethod' => Mage::getStoreConfig('payment/' . $paymentMethod . '/title'), 'items' => nl2br($items), 'total' => $total)); } $translate->setTranslateInline(true); return $this; }
/** * set the quote information * @param Mage_Sales_Model_Quote $quoteData */ public function __construct(Mage_Sales_Model_Quote $quoteData) { $customerModel = Mage::getModel('customer/customer'); $customerModel->load($quoteData->getCustomerId()); $this->id = $quoteData->getId(); $this->email = $quoteData->getCustomerEmail(); $this->store_name = $quoteData->getStore()->getName(); $created_at = new Zend_Date($quoteData->getCreatedAt(), Zend_Date::ISO_8601); $this->created_date = $created_at->toString(Zend_Date::ISO_8601); if ($quoteData->getShippingAddress()) { $this->delivery_method = $quoteData->getShippingAddress()->getShippingDescription(); $this->delivery_total = $quoteData->getShippingAddress()->getShippingAmount(); } $this->currency = $quoteData->getStoreCurrencyCode(); if ($payment = $quoteData->getPayment()) { $this->payment = $payment->getMethod(); } $this->couponCode = $quoteData->getCouponCode(); /** * custom quote attributes */ $helper = Mage::helper('ddg'); $website = Mage::app()->getStore($quoteData->getStore())->getWebsite(); $customAttributes = $helper->getConfigSelectedCustomQuoteAttributes($website); if ($customAttributes) { $fields = Mage::getResourceModel('ddg_automation/quote')->getQuoteTableDescription(); foreach ($customAttributes as $customAttribute) { if (isset($fields[$customAttribute])) { $field = $fields[$customAttribute]; $value = $this->_getCustomAttributeValue($field, $quoteData); if ($value) { $this->_assignCustom($field, $value); } } } } /** * Billing address. */ if ($quoteData->getBillingAddress()) { $billingData = $quoteData->getBillingAddress()->getData(); $this->billing_address = array('billing_address_1' => $this->_getStreet($billingData['street'], 1), 'billing_address_2' => $this->_getStreet($billingData['street'], 2), 'billing_city' => $billingData['city'], 'billing_region' => $billingData['region'], 'billing_country' => $billingData['country_id'], 'billing_postcode' => $billingData['postcode']); } /** * Shipping address. */ if ($quoteData->getShippingAddress()) { $shippingData = $quoteData->getShippingAddress()->getData(); $this->delivery_address = array('delivery_address_1' => $this->_getStreet($shippingData['street'], 1), 'delivery_address_2' => $this->_getStreet($shippingData['street'], 2), 'delivery_city' => $shippingData['city'], 'delivery_region' => $shippingData['region'], 'delivery_country' => $shippingData['country_id'], 'delivery_postcode' => $shippingData['postcode']); } /** * Quote items. * @var Mage_Sales_Model_Quote_Item $productItem */ foreach ($quoteData->getAllItems() as $productItem) { $product = $productItem->getProduct(); if ($product) { // category names $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name'); foreach ($categoryCollection as $cat) { $categories = array(); $categories[] = $cat->getName(); $this->categories[]['Name'] = substr(implode(', ', $categories), 0, 244); } //get attribute set name $attributeSetName = $this->_getAttributeSetName($product); $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', ''), 'attribute-set' => $attributeSetName); } else { // when no product information is available limit to this data $this->products[] = array('name' => $productItem->getName(), 'sku' => $productItem->getSku(), 'qty' => (int) number_format($productItem->getData('qty'), 2), 'price' => (double) number_format($productItem->getPrice(), 2, '.', '')); } } $this->quote_subtotal = (double) number_format($quoteData->getData('subtotal'), 2, '.', ''); $discountAmount = $quoteData->getData('subtotal') - $quoteData->getData('subtotal_with_discount'); $this->discount_amount = (double) number_format($discountAmount, 2, '.', ''); $this->quote_total = (double) number_format($quoteData->getData('grand_total'), 2, '.', ''); return true; }