/** * Inactivate quote * * @return Mage_Sales_Model_Service_Quote */ protected function _inactivateQuote() { if ($this->_shouldInactivateQuote) { $this->_quote->setIsActive(false); } return $this; }
/** * @param Mage_Sales_Model_Quote $quote */ protected function reactivateQuote(Mage_Sales_Model_Quote $quote) { if ($quote->getId()) { /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed() * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds * (Causes Integrity Constraint Violation, because orderIncrementId already exists */ $quote->setIsActive(1)->setReservedOrderId(null)->save(); $oSession = Mage::getSingleton('checkout/session'); $oSession->replaceQuote($quote)->unsLastRealOrderId(); } }
public function save() { $this->_order->setStoreId($this->_getStore()->getId()); $this->_order->createFromQuoteAddress($this->_quote->getShippingAddress()); $this->_order->validate(); $this->_order->setInitialStatus(); $this->_order->save(); $this->_order->setCreatedAt($this->_getRandomDate()); $this->_order->save(); $this->_quote->setIsActive(false); $this->_quote->save(); return $this; }
/** * Build quote object * * @throws Exception */ public function buildQuote() { try { // do not change invoke order // -------------------- $this->initializeQuote(); $this->initializeCustomer(); $this->initializeAddresses(); $this->configureStore(); $this->initializeCurrency(); $this->initializeShippingMethodData(); $this->initializeQuoteItems(); $this->initializePaymentMethodData(); //$this->quote->setTotalsCollectedFlag(false); $this->quote->collectTotals()->save(); $this->quote->reserveOrderId(); // -------------------- } catch (Exception $e) { $this->quote->setIsActive(false)->save(); throw $e; } }
public function setIsActive($active) { if ($active || !$this->hasItemsCollection()) { return parent::setIsActive($active); } //Change quote active state only then it contains only approved items, //otherwise ignore it $approvedItems = $this->getItemsCollection(); $this->setItemsCollection(null); $allItemsNumber = count($this->getItemsCollection()); $approvedItemsNumber = count($approvedItems); $this->setItemsCollection($approvedItems); return $allItemsNumber == $approvedItemsNumber ? parent::setIsActive($active) : $this; }
protected function _resetOrderCreateInfo() { Mage::unregister('ebayShippingData'); Mage::unregister('ebayPaymentData'); if ($this->_quote != null) { $this->_quote->setIsActive(false); $this->_quote->save(); $this->_quote = null; } Mage::helper('M2ePro/Module')->getConfig()->deleteGroupValue('/synchronization/orders/', 'current_magento_order_id'); $this->_clearNotifyMessages(); $this->_webSiteId = null; $this->_storeId = null; $this->_orderCurrencyRate = 1; $this->_shippingCurrencyRate = 1; $this->_taxPercent = 0; $this->_taxIncludesShipping = false; $this->_productTaxClassId = null; }
/** * @param Mage_Sales_Model_Quote $quote */ protected function reactivateQuote(Mage_Sales_Model_Quote $quote) { if ($quote->getId()) { /* @note: Reset reserved_order_id, Magento up to and including version 1.7 has a bug in Mage_Sales_Model_Resource_Quote::isOrderIncrementIdUsed() * They cast the orderIncrementId to (int), which breaks the checkout/cart for all non-numerical incrementIds * (Causes Integrity Constraint Violation, because orderIncrementId already exists */ $quote->setData('reserved_order_id', ''); $quote->setIsActive(true); $quote->save(); } }
/** * Restore * * @param $quote Mage_Sales_Model_Quote * @param $status string * @return bool */ public function restoreCart(Mage_Sales_Model_Quote $quote, $status) { $storeId = $quote->getStoreId(); $gatewayMethod = $quote->getPayment()->getMethod(); $needRestore = false; $statuses = array('canceled', 'expired', 'declined', 'void'); if (Mage::getStoreConfig('payment/msp/keep_cart', $storeId) || Mage::getStoreConfig('msp/settings/keep_cart', $storeId) || $gatewayMethod == 'msp_payafter') { $needRestore = true; } if ($needRestore && in_array($status, $statuses)) { $quote->setIsActive(true)->setReservedOrderId(null)->save(); return true; } return false; }
/** * @param Mage_Sales_Model_Quote $quote * @param ShopgateCartBase $order * * @return Mage_Sales_Model_Quote * @throws ShopgateLibraryException */ protected function _setQuoteCustomer($quote, $order) { /* @var $customer Mage_Customer_Model_Customer */ $customer = Mage::getModel('customer/customer'); $externalCustomerId = $order->getExternalCustomerId(); if ($externalCustomerId) { $this->log('external customer id: ' . $externalCustomerId, ShopgateLogger::LOGTYPE_DEBUG); $customer->load($externalCustomerId); if (!$customer->getId()) { throw new ShopgateLibraryException(ShopgateLibraryException::UNKNOWN_ERROR_CODE, sprintf('customer with external id \'%s\' does not exist', $externalCustomerId)); } else { $quote->setCustomer($customer); // also set customer in session some 3rd party plugins rely on it Mage::getSingleton('customer/session')->setCustomer($customer)->setCustomerId($customer->getId())->setCustomerGroupId($customer->getGroupId()); $this->log('external customer loaded', ShopgateLogger::LOGTYPE_DEBUG); } } $invoiceAddress = $order->getInvoiceAddress(); if ($invoiceAddress) { $this->log('invoice address start', ShopgateLogger::LOGTYPE_DEBUG); $quote->getBillingAddress()->setShouldIgnoreValidation(true); $billingAddressData = $this->_getSalesHelper()->createAddressData($order, $order->getInvoiceAddress(), true); $billingAddress = $quote->getBillingAddress()->addData($billingAddressData); $this->log('invoice address end', ShopgateLogger::LOGTYPE_DEBUG); } $deliveryAddress = $order->getDeliveryAddress(); if ($deliveryAddress) { $this->log('delivery address start', ShopgateLogger::LOGTYPE_DEBUG); $quote->getShippingAddress()->setShouldIgnoreValidation(true); $shippingAddressData = $this->_getSalesHelper()->createAddressData($order, $order->getDeliveryAddress(), false); $shippingAddress = $quote->getShippingAddress()->addData($shippingAddressData); $this->_getHelper()->setShippingMethod($shippingAddress, $order); $this->log('delivery address end', ShopgateLogger::LOGTYPE_DEBUG); } $quote->setCustomerEmail($order->getMail()); $this->log('customer email: ' . $order->getMail(), ShopgateLogger::LOGTYPE_DEBUG); if ($invoiceAddress) { $this->log('invoice address start (names)', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerPrefix($quote->getShippingAddress()->getPrefix()); $quote->setCustomerFirstname($invoiceAddress->getFirstName()); $quote->setCustomerLastname($invoiceAddress->getLastName()); $this->log('invoice address end (names)', ShopgateLogger::LOGTYPE_DEBUG); } $externalCustomerId = $order->getExternalCustomerId(); if (empty($externalCustomerId)) { $this->log('external customer number unavailable', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerIsGuest(1); $quote->getShippingAddress(); $quote->getBillingAddress(); } else { $this->log('external customer number available', ShopgateLogger::LOGTYPE_DEBUG); $quote->setCustomerIsGuest(0); if ($invoiceAddress) { $billingAddress->setCustomerAddressId($invoiceAddress->getId()); } if ($deliveryAddress) { $shippingAddress->setCustomerAddressId($deliveryAddress->getId()); } } Mage::register('rule_data', new Varien_Object(array('store_id' => Mage::app()->getStore()->getId(), 'website_id' => Mage::app()->getStore()->getWebsiteId(), 'customer_group_id' => $quote->getCustomerGroupId()))); $quote->setIsActive('0'); $quote->setRemoteIp('shopgate.com'); $quote->save(); if (empty($externalCustomerId)) { $quote->getBillingAddress()->isObjectNew(false); $quote->getShippingAddress()->isObjectNew(false); } return $quote; }
/** * Place the order * * @return bool */ protected function _processOrder() { if (!$this->_auth()) { return false; } if (!$this->_validateQuote()) { return false; } // Push address to the quote, set totals, // Convert quote to the order, // Set rakuten_order attribute to "1" try { // To avoid duplicates look for order with the same Rakuten order no $orders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('ext_order_id', (string) $this->_request->order_no); if (count($orders)) { $this->_debugData['reason'] = 'The same order already placed'; return false; } // Import addresses and other data to quote $this->_quote->setIsActive(true)->reserveOrderId(); $storeId = $this->_quote->getStoreId(); Mage::app()->setCurrentStore(Mage::app()->getStore($storeId)); if ($this->_quote->getQuoteCurrencyCode() != $this->_quote->getBaseCurrencyCode()) { Mage::app()->getStore()->setCurrentCurrencyCode($this->_quote->getQuoteCurrencyCode()); } $billing = $this->_convertAddress('client'); $this->_quote->setBillingAddress($billing); $shipping = $this->_convertAddress('delivery_address'); $this->_quote->setShippingAddress($shipping); $this->_convertTotals($this->_quote->getShippingAddress()); $this->_quote->getPayment()->importData(array('method' => 'rakuten')); /** * Convert quote to order * * @var $convertQuote Mage_Sales_Model_Convert_Quote */ $convertQuote = Mage::getSingleton('sales/convert_quote'); /* @var $order Mage_Sales_Model_Order */ $order = $convertQuote->toOrder($this->_quote); if ($this->_quote->isVirtual()) { $convertQuote->addressToOrder($this->_quote->getBillingAddress(), $order); } else { $convertQuote->addressToOrder($this->_quote->getShippingAddress(), $order); } $order->setExtOrderId((string) $this->_request->order_no); $order->setExtCustomerId((string) $this->_request->client->client_id); if (!$order->getCustomerEmail()) { $order->setCustomerEmail($billing->getEmail())->setCustomerPrefix($billing->getPrefix())->setCustomerFirstname($billing->getFirstname())->setCustomerMiddlename($billing->getMiddlename())->setCustomerLastname($billing->getLastname())->setCustomerSuffix($billing->getSuffix())->setCustomerIsGuest(1); } $order->setBillingAddress($convertQuote->addressToOrderAddress($this->_quote->getBillingAddress())); if (!$this->_quote->isVirtual()) { $order->setShippingAddress($convertQuote->addressToOrderAddress($this->_quote->getShippingAddress())); } /** @var $item Mage_Sales_Model_Quote_Item */ foreach ($this->_quote->getAllItems() as $item) { $orderItem = $convertQuote->itemToOrderItem($item); if ($item->getParentItem()) { $orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId())); } $order->addItem($orderItem); } /** * Adding transaction for correct transaction information displaying on the order view in the admin. * It has no influence on the API interaction logic. * * @var $payment Mage_Sales_Model_Order_Payment */ $payment = Mage::getModel('sales/order_payment'); $payment->setMethod('rakuten')->setTransactionId((string) $this->_request->order_no)->setIsTransactionClosed(false); $order->setPayment($payment); $payment->addTransaction(Mage_Sales_Model_Order_Payment_Transaction::TYPE_CAPTURE); $order->setCanShipPartiallyItem(false); $message = ''; if (trim((string) $this->_request->comment_client) != '') { $message .= $this->__('Customer\'s Comment: %s', '<strong>' . trim((string) $this->_request->comment_client) . '</strong><br />'); } $message .= $this->__('Rakuten Order No: %s', '<strong>' . (string) $this->_request->order_no . '</strong><br />') . $this->__('Rakuten Client ID: %s', '<strong>' . (string) $this->_request->client->client_id . '</strong><br />'); $order->addStatusHistoryComment($message); $order->setRakutenOrder(1); // Custom attribute for fast filtering of orders placed via Rakuten Checkout $order->place(); $order->save(); // $order->sendNewOrderEmail(); $this->_quote->setIsActive(false)->save(); Mage::dispatchEvent('checkout_submit_all_after', array('order' => $order, 'quote' => $this->_quote)); } catch (Exception $e) { $this->_debugData['exception'] = $e->getMessage(); Mage::logException($e); return false; } return true; }