コード例 #1
0
ファイル: Onepage.php プロジェクト: sagmahajan/aswan_release
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $service = Mage::getModel('sales/service_quote', $this->getQuote());
     $service->submitAll();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $service->getOrder();
     if ($order) {
         Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
         /**
          * a flag to set that there will be redirect to third party after confirmation
          * eg: paypal standard ipn
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $paymentMethod = $order->getPayment()->getMethod();
                 if ($paymentMethod != 'cashondelivery' || !$order->isOtp()) {
                     $order->sendNewOrderEmail();
                 } else {
                     #start sms
                     $write = Mage::getSingleton('core/resource')->getConnection('core_write');
                     $data = array();
                     $data['send_to'] = $order->getShippingAddress()->getTelephone();
                     $data['name'] = $order->getCustomerFirstname();
                     $data['orderid'] = $order->getIncrementId();
                     $helper = Mage::helper('nosql/joker');
                     $tempOTP = 'OTP_COD';
                     $codCode = Mage::helper('nosql/product')->cod_text();
                     $data['codvarcode'] = $codCode;
                     $write->query("UPDATE sales_flat_order SET codvarcode='" . $codCode . "' WHERE entity_id='" . $order->getId() . "';");
                     //$orderModel = Mage::getModel('sales/order')->load($order->getId())->setCodvarcode($codCode)->save();
                     $data['template'] = $tempOTP;
                     //$helper->sendNow($data, 'sms', $tempOTP);
                     #end sms
                 }
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
         // as well a billing agreement can be created
         $agreement = $order->getPayment()->getBillingAgreement();
         if ($agreement) {
             $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
         }
     }
     // add recurring profiles information to the session
     $profiles = $service->getRecurringPaymentProfiles();
     if ($profiles) {
         $ids = array();
         foreach ($profiles as $profile) {
             $ids[] = $profile->getId();
         }
         $this->_checkoutSession->setLastRecurringProfileIds($ids);
         // TODO: send recurring profile emails
     }
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles));
     return $this;
 }
コード例 #2
0
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     $service = Mage::getModel('sales/service_quote', $this->getQuote());
     $service->submitAll();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $service->getOrder();
     if ($order) {
         Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
         /**
          * a flag to set that there will be redirect to third party after confirmation
          * eg: paypal standard ipn
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $order->queueNewOrderEmail();
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
         // as well a billing agreement can be created
         $agreement = $order->getPayment()->getBillingAgreement();
         if ($agreement) {
             $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
         }
     }
     // add recurring profiles information to the session
     $profiles = $service->getRecurringPaymentProfiles();
     if ($profiles) {
         $ids = array();
         foreach ($profiles as $profile) {
             $ids[] = $profile->getId();
         }
         $this->_checkoutSession->setLastRecurringProfileIds($ids);
         // TODO: send recurring profile emails
     }
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles));
     return $this;
 }
コード例 #3
0
 /**
  * Create order based on checkout type. Create customer if necessary.
  *
  * @return Mage_Checkout_Model_Type_Onepage
  */
 public function saveOrder()
 {
     $this->validate();
     $isNewCustomer = false;
     switch ($this->getCheckoutMethod()) {
         case self::METHOD_GUEST:
             $this->_prepareGuestQuote();
             break;
         case self::METHOD_REGISTER:
             $this->_prepareNewCustomerQuote();
             $isNewCustomer = true;
             break;
         default:
             $this->_prepareCustomerQuote();
             break;
     }
     // ===========================================================================
     // add $1 product to quote
     $deal_category = Mage::getModel('catalog/category');
     $deal_category->load(5);
     # $1 Deal Category
     $quote = $this->getQuote();
     $items = $quote->getAllVisibleItems();
     $apply_discount = false;
     # Check to see if any of the items is in the $1 Deal Category
     foreach ($items as $item) {
         $product = Mage::getModel('catalog/product');
         $_product = $product->load($item->getProductId());
         $categories = $_product->getCategoryIds();
         foreach ($categories as $category) {
             $cat = Mage::getModel('catalog/category');
             $cat->load($category);
             if ($deal_category->getId() == $cat->getId()) {
                 $apply_discount = true;
                 break;
             }
         }
     }
     if ($apply_discount) {
         # $1 Deal Product
         $product = Mage::getModel('catalog/product')->load(1608);
         $quoteItem = $quote->addProduct($product);
         $quoteItem->setOriginalPrice(1);
         $quoteItem->setCustomPrice(1);
         $quoteItem->setPrice(1);
         $quoteItem->setRowTotal(1);
         $quoteItem->setQty(1);
         $quoteItem->setQuote($quote);
         $quote->getPayment()->importData(array('method' => 'checkmo'));
         $quote->collectTotals()->save();
         $quote->save();
     }
     ////////////////////////////
     $service = Mage::getModel('sales/service_quote', $this->getQuote());
     $service->submitAll();
     if ($isNewCustomer) {
         try {
             $this->_involveNewCustomer();
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
     $this->_checkoutSession->setLastQuoteId($this->getQuote()->getId())->setLastSuccessQuoteId($this->getQuote()->getId())->clearHelperData();
     $order = $service->getOrder();
     if ($order) {
         Mage::dispatchEvent('checkout_type_onepage_save_order_after', array('order' => $order, 'quote' => $this->getQuote()));
         /**
          * a flag to set that there will be redirect to third party after confirmation
          * eg: paypal standard ipn
          */
         $redirectUrl = $this->getQuote()->getPayment()->getOrderPlaceRedirectUrl();
         /**
          * we only want to send to customer about new order when there is no redirect to third party
          */
         if (!$redirectUrl && $order->getCanSendNewEmailFlag()) {
             try {
                 $order->sendNewOrderEmail();
             } catch (Exception $e) {
                 Mage::logException($e);
             }
         }
         // add order information to the session
         $this->_checkoutSession->setLastOrderId($order->getId())->setRedirectUrl($redirectUrl)->setLastRealOrderId($order->getIncrementId());
         // as well a billing agreement can be created
         $agreement = $order->getPayment()->getBillingAgreement();
         if ($agreement) {
             $this->_checkoutSession->setLastBillingAgreementId($agreement->getId());
         }
     }
     // add recurring profiles information to the session
     $profiles = $service->getRecurringPaymentProfiles();
     if ($profiles) {
         $ids = array();
         foreach ($profiles as $profile) {
             $ids[] = $profile->getId();
         }
         $this->_checkoutSession->setLastRecurringProfileIds($ids);
         // TODO: send recurring profile emails
     }
     Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->getQuote(), 'recurring_profiles' => $profiles));
     return $this;
 }