/** * 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; }
/** * Recalculate amount to store currency * * @param float $amount * @param Mage_Sales_Model_Quote $quote * @return float */ protected function _reCalculateToStoreCurrency($amount, $quote) { if ($quote->getQuoteCurrencyCode() != $quote->getBaseCurrencyCode()) { $amount = $amount * $quote->getStoreToQuoteRate(); $amount = Mage::app()->getStore()->roundPrice($amount); } return $amount; }
/** * Fetches the current store's currency or the one from the quote model. * @param Mage_Sales_Model_Quote $quote [also accepts order model] */ public function getCurrencyRate($quote = null) { if ($quote->getStoreToQuoteRate() && $quote) { $c = round($quote->getStoreToQuoteRate(), 4); } else { if ($quote) { $store = $quote->getStore() ? $quote->getStore() : Mage::app()->getStore(); } else { $store = Mage::app()->getStore(); } $baseCurrency = $store->getBaseCurrency(); if ($quote) { $quoteCurrency = $quote->hasForcedCurrency() ? $quote->getForcedCurrency() : $store->getCurrentCurrency(); } else { $quoteCurrency = $store->getCurrentCurrency(); } $c = $baseCurrency->getRate($quoteCurrency); } return $c; }