/**
  * @param Mage_Checkout_Model_Session $session
  * @return Mage_Sales_Model_Quote
  */
 protected function getQuoteByCheckoutSession(Mage_Checkout_Model_Session $session)
 {
     $quoteId = $session->getLastQuoteId();
     $quote = $this->getFactory()->getModelSalesQuote();
     $quote->load($quoteId);
     return $quote;
 }
예제 #2
0
 /**
  * Class constructor
  * Set customer already exists message
  */
 public function __construct()
 {
     $this->_helper = Mage::helper('checkout');
     $this->_customerEmailExistsMessage = $this->_helper->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.');
     $this->_checkoutSession = Mage::getSingleton('checkout/session');
     $this->_quote = $this->_checkoutSession->getQuote();
     $this->_customerSession = Mage::getSingleton('customer/session');
 }
예제 #3
0
 /**
  * Reorder success messages
  * 
  * @param Mage_Checkout_Model_Session $session
  */
 public function _reorderSuccessMessages($session)
 {
     $messages = Mage::registry('gift_added_success_messages');
     if (!$messages || !$session instanceof Mage_Checkout_Model_Session) {
         return;
     }
     foreach ($messages as $message) {
         /* @var $message Mage_Core_Model_Message_Abstract */
         $session->getMessages()->deleteMessageByIdentifier($message->getIdentifier());
         $session->getMessages()->add($message);
     }
 }
예제 #4
0
파일: Session.php 프로젝트: Eximagen/pfizer
 /**
  * @param Mage_Checkout_Model_Session $checkoutSession
  * @param bo
  * ol $replace
  * @return mixed
  */
 public function setupPunchoutQuote($checkoutSession, $replace = false)
 {
     /** @var $punchoutSession Vbw_Punchout_Model_Session */
     $punchoutSession = Mage::getSingleton('vbw_punchout/session');
     Mage::getSingleton('vbw_punchout/session')->isPunchoutSession();
     // only if this is a punchout session.
     if ($punchoutSession->isPunchoutSession()) {
         if ($replace == true) {
             if ($checkoutSession->hasQuote()) {
                 $checkoutSession->replaceQuote(Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId()));
                 $checkoutSession->resetCheckout();
             }
         }
         if (!$checkoutSession->hasQuote() || $replace == true) {
             $quote = Mage::getModel('sales/quote')->setStoreId(Mage::app()->getStore()->getId());
             /** @var $customerSession Mage_Customer_Model_Session */
             $customerSession = Mage::getSingleton('customer/session');
             // if no quote id exists, then take the new one and set it up.
             if (!$checkoutSession->getQuoteId() || $replace) {
                 $quote->setIsCheckoutCart(true);
                 Mage::dispatchEvent('checkout_quote_init', array('quote' => $quote));
                 $quote->setStore(Mage::app()->getStore());
                 $checkoutSession->setQuoteId($quote->getId());
                 if ($customerSession->isLoggedIn()) {
                     $checkoutSession->setCustomer($customerSession->getCustomer());
                     $quote->setCustomer($customerSession->getCustomer());
                 }
             }
         }
     }
 }
예제 #5
0
 public function getLastOrderId()
 {
     $ret = parent::getLastOrderId();
     if (!$ret) {
         $c = Mage::getModel('sales/order')->getCollection()->getFirstItem();
         if ($c->getIncrementId()) {
             $ret = $c->getId();
             $block = Mage::getSingleton('core/layout')->createBlock('core/text')->setText('<h1>No last order found, using random system order.</h1>');
             echo $block->toHtml();
         }
     }
     return $ret;
 }
 /**
  * After an order has been placed, surrounding Magento system should be
  * made aware of the new order - session data should be updated and an
  * event should be dispatched.
  */
 public function testSignalOrderSuccess()
 {
     // Setup quote and orders with relevant data.
     $orderId = 1;
     $incrementId = '005012345';
     $quoteId = 3;
     $this->_order->method('getId')->will($this->returnValue($orderId));
     $this->_order->method('getIncrementId')->will($this->returnValue($incrementId));
     $this->_quote->method('getId')->will($this->returnValue($quoteId));
     // Side-effect tests: ensure session data is updated with quote and
     // order data.
     $this->_coreSession->expects($this->once())->method('setOrderIds')->with($this->identicalTo([$orderId => $incrementId]))->will($this->returnSelf());
     $this->_checkoutSession->expects($this->once())->method('setLastQuoteId')->with($this->identicalTo($quoteId))->will($this->returnSelf());
     $this->assertSame($this->_multishippingCheckout, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_multishippingCheckout, '_signalOrderSuccess', [$this->_order]));
     // Ensure the event was dispatched once for the new order.
     $this->assertEventDispatchedExactly('checkout_submit_all_after', 1);
 }
예제 #7
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;
 }
예제 #8
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 {
                 $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;
 }
예제 #9
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;
 }