00001 <?php 00002 /** 00003 * Magento 00004 * 00005 * NOTICE OF LICENSE 00006 * 00007 * This source file is subject to the Open Software License (OSL 3.0) 00008 * that is bundled with this package in the file LICENSE.txt. 00009 * It is also available through the world-wide-web at this URL: 00010 * http://opensource.org/licenses/osl-3.0.php 00011 * If you did not receive a copy of the license and are unable to 00012 * obtain it through the world-wide-web, please send an email 00013 * to license@magentocommerce.com so we can send you a copy immediately. 00014 * 00015 * DISCLAIMER 00016 * 00017 * Do not edit or add to this file if you wish to upgrade Magento to newer 00018 * versions in the future. If you wish to customize Magento for your 00019 * needs please refer to http://www.magentocommerce.com for more information. 00020 * 00021 * @category Mage 00022 * @package Mage_Sales 00023 * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com) 00024 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 00025 */ 00026 00027 /** 00028 * Order data convert model 00029 * 00030 * EVENTS 00031 * 00032 * 00033 * @category Mage 00034 * @package Mage_Sales 00035 * @author Magento Core Team <core@magentocommerce.com> 00036 */ 00037 class Mage_Sales_Model_Convert_Quote extends Varien_Object 00038 { 00039 00040 /** 00041 * Convert quote model to order model 00042 * 00043 * @param Mage_Sales_Model_Quote $quote 00044 * @return Mage_Sales_Model_Order 00045 */ 00046 public function toOrder(Mage_Sales_Model_Quote $quote, $order=null) 00047 { 00048 if (!($order instanceof Mage_Sales_Model_Order)) { 00049 $order = Mage::getModel('sales/order'); 00050 } 00051 /* @var $order Mage_Sales_Model_Order */ 00052 00053 $order 00054 /** 00055 * Base Data 00056 */ 00057 ->setIncrementId($quote->getReservedOrderId()) 00058 ->setStoreId($quote->getStoreId()) 00059 ->setQuoteId($quote->getId()); 00060 00061 Mage::helper('core')->copyFieldset('sales_convert_quote', 'to_order', $quote, $order); 00062 00063 if (!$quote->getCustomerId()) { 00064 $order->setCustomerId(null); 00065 } 00066 // 00067 // ->setRemoteIp($quote->getRemoteIp()) 00068 // 00069 // /** 00070 // * Customer data 00071 // */ 00072 // ->setCustomerId($quote->getCustomerId()) 00073 // ->setCustomerEmail($quote->getCustomerEmail()) 00074 // ->setCustomerPrefix($quote->getCustomerPrefix()) 00075 // ->setCustomerFirstname($quote->getCustomerFirstname()) 00076 // ->setCustomerMiddlename($quote->getCustomerMiddlename()) 00077 // ->setCustomerLastname($quote->getCustomerLastname()) 00078 // ->setCustomerSuffix($quote->getCustomerSuffix()) 00079 // ->setCustomerGroupId($quote->getCustomerGroupId()) 00080 // ->setCustomerTaxClassId($quote->getCustomerTaxClassId()) 00081 // ->setCustomerNote($quote->getCustomerNote()) 00082 // ->setCustomerNoteNotify($quote->getCustomerNoteNotify()) 00083 // ->setCustomerIsGuest($quote->getCustomerIsGuest()) 00084 // ->setCustomerDob($quote->getCustomerDob()) 00085 // 00086 // /** 00087 // * Currency data 00088 // */ 00089 // ->setBaseCurrencyCode($quote->getBaseCurrencyCode()) 00090 // ->setStoreCurrencyCode($quote->getStoreCurrencyCode()) 00091 // ->setOrderCurrencyCode($quote->getQuoteCurrencyCode()) 00092 // ->setStoreToBaseRate($quote->getStoreToBaseRate()) 00093 // ->setStoreToOrderRate($quote->getStoreToQuoteRate()) 00094 // 00095 // /** 00096 // * Another data 00097 // */ 00098 // ->setCouponCode($quote->getCouponCode()) 00099 // ->setGiftcertCode($quote->getGiftcertCode()) 00100 // ->setIsVirtual($quote->getIsVirtual()) 00101 // ->setIsMultiPayment($quote->getIsMultiPayment()) 00102 // ->setAppliedRuleIds($quote->getAppliedRuleIds()); 00103 00104 00105 Mage::dispatchEvent('sales_convert_quote_to_order', array('order'=>$order, 'quote'=>$quote)); 00106 return $order; 00107 } 00108 00109 /** 00110 * Convert quote address model to order 00111 * 00112 * @param Mage_Sales_Model_Quote $quote 00113 * @return Mage_Sales_Model_Order 00114 */ 00115 public function addressToOrder(Mage_Sales_Model_Quote_Address $address, $order=null) 00116 { 00117 if (!($order instanceof Mage_Sales_Model_Order)) { 00118 $order = $this->toOrder($address->getQuote()); 00119 } 00120 00121 Mage::helper('core')->copyFieldset('sales_convert_quote_address', 'to_order', $address, $order); 00122 00123 // $order 00124 // ->setWeight($address->getWeight()) 00125 // ->setShippingMethod($address->getShippingMethod()) 00126 // ->setShippingDescription($address->getShippingDescription()) 00127 // ->setShippingRate($address->getShippingRate()) 00128 // 00129 // ->setSubtotal($address->getSubtotal()) 00130 // ->setTaxAmount($address->getTaxAmount()) 00131 // ->setDiscountAmount($address->getDiscountAmount()) 00132 // ->setShippingAmount($address->getShippingAmount()) 00133 // ->setShippingTaxAmount($address->getShippingTaxAmount()) 00134 // ->setGiftcertAmount($address->getGiftcertAmount()) 00135 // ->setCustbalanceAmount($address->getCustbalanceAmount()) 00136 // ->setGrandTotal($address->getGrandTotal()) 00137 // 00138 // ->setBaseSubtotal($address->getBaseSubtotal()) 00139 // ->setBaseTaxAmount($address->getBaseTaxAmount()) 00140 // ->setBaseDiscountAmount($address->getBaseDiscountAmount()) 00141 // ->setBaseShippingAmount($address->getBaseShippingAmount()) 00142 // ->setBaseShippingTaxAmount($address->getBaseShippingTaxAmount()) 00143 // ->setBaseGiftcertAmount($address->getBaseGiftcertAmount()) 00144 // ->setBaseCustbalanceAmount($address->getBaseCustbalanceAmount()) 00145 // ->setBaseGrandTotal($address->getBaseGrandTotal()); 00146 00147 Mage::dispatchEvent('sales_convert_quote_address_to_order', array('address'=>$address, 'order'=>$order)); 00148 return $order; 00149 } 00150 00151 /** 00152 * Convert quote address to order address 00153 * 00154 * @param Mage_Sales_Model_Quote_Address $address 00155 * @return Mage_Sales_Model_Order_Address 00156 */ 00157 public function addressToOrderAddress(Mage_Sales_Model_Quote_Address $address) 00158 { 00159 $orderAddress = Mage::getModel('sales/order_address') 00160 ->setStoreId($address->getStoreId()) 00161 ->setAddressType($address->getAddressType()) 00162 ->setCustomerId($address->getCustomerId()) 00163 ->setCustomerAddressId($address->getCustomerAddressId()); 00164 00165 Mage::helper('core')->copyFieldset('sales_convert_quote_address', 'to_order_address', $address, $orderAddress); 00166 // ->setPrefix($address->getPrefix()) 00167 // ->setFirstname($address->getFirstname()) 00168 // ->setMiddlename($address->getMiddlename()) 00169 // ->setLastname($address->getLastname()) 00170 // ->setSuffix($address->getSuffix()) 00171 // ->setCompany($address->getCompany()) 00172 // ->setStreet($address->getStreet(-1)) 00173 // ->setCity($address->getCity()) 00174 // ->setRegion($address->getRegion()) 00175 // ->setRegionId($address->getRegionId()) 00176 // ->setPostcode($address->getPostcode()) 00177 // ->setCountryId($address->getCountryId()) 00178 // ->setTelephone($address->getTelephone()) 00179 // ->setFax($address->getFax()); 00180 00181 Mage::dispatchEvent('sales_convert_quote_address_to_order_address', 00182 array('address' => $address, 'order_address' => $orderAddress)); 00183 00184 return $orderAddress; 00185 } 00186 00187 /** 00188 * Convert quote payment to order payment 00189 * 00190 * @param Mage_Sales_Model_Quote_Payment $payment 00191 * @return Mage_Sales_Model_Quote_Payment 00192 */ 00193 public function paymentToOrderPayment(Mage_Sales_Model_Quote_Payment $payment) 00194 { 00195 $orderPayment = Mage::getModel('sales/order_payment') 00196 ->setStoreId($payment->getStoreId()) 00197 ->setCustomerPaymentId($payment->getCustomerPaymentId()); 00198 Mage::helper('core')->copyFieldset('sales_convert_quote_payment', 'to_order_payment', $payment, $orderPayment); 00199 // ->setMethod($payment->getMethod()) 00200 // ->setAdditionalData($payment->getAdditionalData()) 00201 // ->setPoNumber($payment->getPoNumber()) 00202 // ->setCcType($payment->getCcType()) 00203 // ->setCcNumberEnc($payment->getCcNumberEnc()) 00204 // ->setCcLast4($payment->getCcLast4()) 00205 // ->setCcOwner($payment->getCcOwner()) 00206 // ->setCcExpMonth($payment->getCcExpMonth()) 00207 // ->setCcExpYear($payment->getCcExpYear()) 00208 // 00209 // ->setCcNumber($payment->getCcNumber()) // only for doing first transaction, not for save 00210 // ->setCcCid($payment->getCcCid()) // only for doing first transaction, not for save 00211 // 00212 // ->setCcSsIssue($payment->getCcSsIssue()) //for direct payment 00213 // ->setCcSsStartMonth($payment->getCcSsStartMonth()) //for direct payment 00214 // ->setCcSsStartYear($payment->getCcSsStartYear()) //for direct payment 00215 // ; 00216 00217 Mage::dispatchEvent('sales_convert_quote_payment_to_order_payment', 00218 array('order_payment' => $orderPayment, 'quote_payment' => $payment)); 00219 00220 return $orderPayment; 00221 } 00222 00223 /** 00224 * Convert quote item to order item 00225 * 00226 * @param Mage_Sales_Model_Quote_Item_Abstract $item 00227 * @return Mage_Sales_Model_Order_Item 00228 */ 00229 public function itemToOrderItem(Mage_Sales_Model_Quote_Item_Abstract $item) 00230 { 00231 $orderItem = Mage::getModel('sales/order_item') 00232 ->setStoreId($item->getStoreId()) 00233 ->setQuoteItemId($item->getId()) 00234 ->setQuoteParentItemId($item->getParentItemId()) 00235 ->setProductId($item->getProductId()) 00236 ->setProductType($item->getProductType()) 00237 ->setProductOptions($item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct())) 00238 ->setQtyBackordered($item->getBackorders()) 00239 ; 00240 00241 Mage::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item', $item, $orderItem); 00242 00243 if ($item->getParentItem()) { 00244 $orderItem->setQtyOrdered($orderItem->getQtyOrdered()*$item->getParentItem()->getQty()); 00245 } 00246 // ->setSku($item->getSku()) 00247 // ->setName($item->getName()) 00248 // ->setDescription($item->getDescription()) 00249 // ->setWeight($item->getWeight()) 00250 // ->setIsQtyDecimal($item->getIsQtyDecimal()) 00251 // ->setQtyOrdered($item->getQty()) 00252 // ->setOriginalPrice($item->getOriginalPrice()) 00253 // ->setAppliedRuleIds($item->getAppliedRuleIds()) 00254 // ->setAdditionalData($item->getAdditionalData()) 00255 // 00256 // ->setPrice($item->getCalculationPrice()) 00257 // ->setTaxPercent($item->getTaxPercent()) 00258 // ->setTaxAmount($item->getTaxAmount()) 00259 // ->setRowWeight($item->getRowWeight()) 00260 // ->setRowTotal($item->getRowTotal()) 00261 // 00262 // ->setBasePrice($item->getBaseCalculationPrice()) 00263 // ->setBaseOriginalPrice($item->getPrice()) 00264 // ->setBaseTaxAmount($item->getBaseTaxAmount()) 00265 // ->setBaseRowTotal($item->getBaseRowTotal()); 00266 00267 if (!$item->getNoDiscount()) { 00268 Mage::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item_discount', $item, $orderItem); 00269 // $orderItem->setDiscountPercent($item->getDiscountPercent()) 00270 // ->setDiscountAmount($item->getDiscountAmount()) 00271 // ->setBaseDiscountAmount($item->getBaseDiscountAmount()); 00272 } 00273 00274 Mage::dispatchEvent('sales_convert_quote_item_to_order_item', 00275 array('order_item'=>$orderItem, 'item'=>$item) 00276 ); 00277 return $orderItem; 00278 } 00279 }