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 * @category Mage 00031 * @package Mage_Sales 00032 * @author Magento Core Team <core@magentocommerce.com> 00033 */ 00034 class Mage_Sales_Model_Convert_Order extends Varien_Object 00035 { 00036 /** 00037 * Converting order object to quote object 00038 * 00039 * @param Mage_Sales_Model_Order $order 00040 * @return Mage_Sales_Model_Quote 00041 */ 00042 public function toQuote(Mage_Sales_Model_Order $order, $quote=null) 00043 { 00044 if (!($quote instanceof Mage_Sales_Model_Quote)) { 00045 $quote = Mage::getModel('sales/quote'); 00046 } 00047 00048 $quote 00049 /** 00050 * Base Data 00051 */ 00052 ->setStoreId($order->getStoreId()) 00053 ->setOrderId($order->getId()); 00054 00055 Mage::helper('core')->copyFieldset('sales_convert_order', 'to_quote', $order, $quote); 00056 00057 // /** 00058 // * Customer data 00059 // */ 00060 // ->setCustomerId($order->getCustomerId()) 00061 // ->setCustomerEmail($order->getCustomerEmail()) 00062 // ->setCustomerGroupId($order->getCustomerGroupId()) 00063 // ->setCustomerTaxClassId($order->getCustomerTaxClassId()) 00064 // /** 00065 // * Not use note from previos order 00066 // */ 00067 // //->setCustomerNote($order->getCustomerNote()) 00068 // //->setCustomerNoteNotify($order->getCustomerNoteNotify()) 00069 // ->setCustomerIsGuest($order->getCustomerIsGuest()) 00070 // 00071 // /** 00072 // * Currency data 00073 // */ 00074 // ->setBaseCurrencyCode($order->getBaseCurrencyCode()) 00075 // ->setStoreCurrencyCode($order->getStoreCurrencyCode()) 00076 // ->setQuoteCurrencyCode($order->getOrderCurrencyCode()) 00077 // ->setStoreToBaseRate($order->getStoreToBaseRate()) 00078 // ->setStoreToQuoteRate($order->getStoreToOrderRate()) 00079 // 00080 // /** 00081 // * Totals data 00082 // */ 00083 // ->setGrandTotal($order->getGrandTotal()) 00084 // ->setBaseGrandTotal($order->getBaseGrandTotal()) 00085 // 00086 // /** 00087 // * Another data 00088 // */ 00089 // ->setCouponCode($order->getCouponCode()) 00090 // ->setGiftcertCode($order->getGiftcertCode()) 00091 // ->setAppliedRuleIds($order->getAppliedRuleIds()); 00092 // //->collectTotals(); 00093 // 00094 00095 Mage::dispatchEvent('sales_convert_order_to_quote', array('order'=>$order, 'quote'=>$quote)); 00096 return $quote; 00097 } 00098 00099 /** 00100 * Convert order to shipping address 00101 * 00102 * @param Mage_Sales_Model_Order $order 00103 * @return Mage_Sales_Model_Quote_Address 00104 */ 00105 public function toQuoteShippingAddress(Mage_Sales_Model_Order $order) 00106 { 00107 $address = $this->addressToQuoteAddress($order->getShippingAddress()); 00108 00109 Mage::helper('core')->copyFieldset('sales_convert_order', 'to_quote_address', $order, $address); 00110 // $address->setWeight($order->getWeight()) 00111 // ->setShippingMethod($order->getShippingMethod()) 00112 // ->setShippingDescription($order->getShippingDescription()) 00113 // ->setShippingRate($order->getShippingRate()) 00114 // 00115 // ->setSubtotal($order->getSubtotal()) 00116 // ->setTaxAmount($order->getTaxAmount()) 00117 // ->setDiscountAmount($order->getDiscountAmount()) 00118 // ->setShippingAmount($order->getShippingAmount()) 00119 // ->setGiftcertAmount($order->getGiftcertAmount()) 00120 // ->setCustbalanceAmount($order->getCustbalanceAmount()) 00121 // ->setGrandTotal($order->getGrandTotal()) 00122 // 00123 // ->setBaseSubtotal($order->getBaseSubtotal()) 00124 // ->setBaseTaxAmount($order->getBaseTaxAmount()) 00125 // ->setBaseDiscountAmount($order->getBaseDiscountAmount()) 00126 // ->setBaseShippingAmount($order->getBaseShippingAmount()) 00127 // ->setBaseGiftcertAmount($order->getBaseGiftcertAmount()) 00128 // ->setBaseCustbalanceAmount($order->getBaseCustbalanceAmount()) 00129 // ->setBaseGrandTotal($order->getBaseGrandTotal()); 00130 return $address; 00131 } 00132 00133 /** 00134 * Convert order address to quote address 00135 * 00136 * @param Mage_Sales_Model_Order_Address $address 00137 * @return Mage_Sales_Model_Quote_Address 00138 */ 00139 public function addressToQuoteAddress(Mage_Sales_Model_Order_Address $address) 00140 { 00141 $quoteAddress = Mage::getModel('sales/quote_address') 00142 ->setStoreId($address->getStoreId()) 00143 ->setAddressType($address->getAddressType()) 00144 ->setCustomerId($address->getCustomerId()) 00145 ->setCustomerAddressId($address->getCustomerAddressId()); 00146 00147 Mage::helper('core')->copyFieldset('sales_convert_order_address', 'to_quote_address', $address, $quoteAddress); 00148 // ->setPrefix($address->getPrefix()) 00149 // ->setFirstname($address->getFirstname()) 00150 // ->setMiddlename($address->getMiddlename()) 00151 // ->setLastname($address->getLastname()) 00152 // ->setSuffix($address->setSuffix()) 00153 // ->setCompany($address->getCompany()) 00154 // ->setStreet($address->getStreet(-1)) 00155 // ->setCity($address->getCity()) 00156 // ->setRegion($address->getRegion()) 00157 // ->setRegionId($address->getRegionId()) 00158 // ->setPostcode($address->getPostcode()) 00159 // ->setCountryId($address->getCountryId()) 00160 // ->setTelephone($address->getTelephone()) 00161 // ->setFax($address->getFax()); 00162 return $quoteAddress; 00163 } 00164 00165 /** 00166 * Convert order payment to quote payment 00167 * 00168 * @param Mage_Sales_Model_Order_Payment $payment 00169 * @return Mage_Sales_Model_Quote_Payment 00170 */ 00171 public function paymentToQuotePayment(Mage_Sales_Model_Order_Payment $payment, $quotePayment=null) 00172 { 00173 if (!($quotePayment instanceof Mage_Sales_Model_Quote_Payment)) { 00174 $quotePayment = Mage::getModel('sales/quote_payment'); 00175 } 00176 00177 $quotePayment->setStoreId($payment->getStoreId()) 00178 ->setCustomerPaymentId($payment->getCustomerPaymentId()); 00179 00180 Mage::helper('core')->copyFieldset('sales_convert_order_payment', 'to_quote_payment', $payment, $quotePayment); 00181 // ->setMethod($payment->getMethod()) 00182 // ->setAdditionalData($payment->getAdditionalData()) 00183 // ->setPoNumber($payment->getPoNumber()) 00184 // ->setCcType($payment->getCcType()) 00185 // ->setCcNumberEnc($payment->getCcNumberEnc()) 00186 // ->setCcLast4($payment->getCcLast4()) 00187 // ->setCcOwner($payment->getCcOwner()) 00188 // ->setCcCidEnc($payment->getCcCidEnc()) 00189 // ->setCcExpMonth($payment->getCcExpMonth()) 00190 // ->setCcExpYear($payment->getCcExpYear()) 00191 // 00192 // ->setCcSsIssue($payment->getCcSsIssue()) //for direct payment 00193 // ->setCcSsStartMonth($payment->getCcSsStartMonth()) //for direct payment 00194 // ->setCcSsStartYear($payment->getCcSsStartYear()) //for direct payment 00195 // ; 00196 return $quotePayment; 00197 } 00198 00199 /** 00200 * Retrieve 00201 * 00202 * @param Mage_Sales_Model_Order_Item $item 00203 * @return unknown 00204 */ 00205 public function itemToQuoteItem(Mage_Sales_Model_Order_Item $item) 00206 { 00207 $quoteItem = Mage::getModel('sales/quote_item') 00208 ->setStoreId($item->getOrder()->getStoreId()) 00209 ->setQuoteItemId($item->getId()) 00210 ->setProductId($item->getProductId()) 00211 ->setParentProductId($item->getParentProductId()); 00212 00213 Mage::helper('core')->copyFieldset('sales_convert_order_item', 'to_quote_item', $item, $quoteItem); 00214 // ->setSku($item->getSku()) 00215 // ->setName($item->getName()) 00216 // ->setDescription($item->getDescription()) 00217 // ->setWeight($item->getWeight()) 00218 // ->setCustomPrice($item->getPrice()) 00219 // ->setDiscountPercent($item->getDiscountPercent()) 00220 // ->setDiscountAmount($item->getDiscountAmount()) 00221 // ->setTaxPercent($item->getTaxPercent()) 00222 // ->setTaxAmount($item->getTaxAmount()) 00223 // ->setRowWeight($item->getRowWeight()) 00224 // ->setRowTotal($item->getRowTotal()) 00225 // ->setAppliedRuleIds($item->getAppliedRuleIds()) 00226 // 00227 // ->setBaseDiscountAmount($item->getBaseDiscountAmount()) 00228 // ->setBaseTaxAmount($item->getBaseTaxAmount()) 00229 // ->setBaseRowTotal($item->getBaseRowTotal()) 00230 // ; 00231 00232 return $quoteItem; 00233 } 00234 00235 /** 00236 * Convert order object to invoice 00237 * 00238 * @param Mage_Sales_Model_Order $order 00239 * @return Mage_Sales_Model_Order_Invoice 00240 */ 00241 public function toInvoice(Mage_Sales_Model_Order $order) 00242 { 00243 $invoice = Mage::getModel('sales/order_invoice'); 00244 $invoice->setOrder($order) 00245 ->setStoreId($order->getStoreId()) 00246 ->setCustomerId($order->getCustomerId()) 00247 ->setBillingAddressId($order->getBillingAddressId()) 00248 ->setShippingAddressId($order->getShippingAddressId()); 00249 00250 Mage::helper('core')->copyFieldset('sales_convert_order', 'to_invoice', $order, $invoice); 00251 // ->setBaseCurrencyCode($order->getBaseCurrencyCode()) 00252 // ->setStoreCurrencyCode($order->getStoreCurrencyCode()) 00253 // ->setOrderCurrencyCode($order->getOrderCurrencyCode()) 00254 // ->setStoreToBaseRate($order->getStoreToBaseRate()) 00255 // ->setStoreToOrderRate($order->getStoreToOrderRate()); 00256 00257 return $invoice; 00258 } 00259 00260 /** 00261 * Convert order item object to invoice item 00262 * 00263 * @param Mage_Sales_Model_Order_Item $item 00264 * @return Mage_Sales_Model_Order_Invoice_Item 00265 */ 00266 public function itemToInvoiceItem(Mage_Sales_Model_Order_Item $item) 00267 { 00268 $invoiceItem = Mage::getModel('sales/order_invoice_item'); 00269 $invoiceItem->setOrderItem($item) 00270 ->setProductId($item->getProductId()); 00271 00272 Mage::helper('core')->copyFieldset('sales_convert_order_item', 'to_invoice_item', $item, $invoiceItem); 00273 // ->setName($item->getName()) 00274 // ->setSku($item->getSku()) 00275 // ->setDescription($item->getDescription()) 00276 // ->setPrice($item->getPrice()) 00277 // ->setBasePrice($item->getBasePrice()) 00278 // ->setCost($item->getCost()); 00279 00280 return $invoiceItem; 00281 } 00282 00283 /** 00284 * Convert order object to Shipment 00285 * 00286 * @param Mage_Sales_Model_Order $order 00287 * @return Mage_Sales_Model_Order_Shipment 00288 */ 00289 public function toShipment(Mage_Sales_Model_Order $order) 00290 { 00291 $shipment = Mage::getModel('sales/order_shipment'); 00292 $shipment->setOrder($order) 00293 ->setStoreId($order->getStoreId()) 00294 ->setCustomerId($order->getCustomerId()) 00295 ->setBillingAddressId($order->getBillingAddressId()) 00296 ->setShippingAddressId($order->getShippingAddressId()); 00297 00298 Mage::helper('core')->copyFieldset('sales_convert_order', 'to_shipment', $order, $shipment); 00299 // ->setBaseCurrencyCode($order->getBaseCurrencyCode()) 00300 // ->setStoreCurrencyCode($order->getStoreCurrencyCode()) 00301 // ->setOrderCurrencyCode($order->getOrderCurrencyCode()) 00302 // ->setStoreToBaseRate($order->getStoreToBaseRate()) 00303 // ->setStoreToOrderRate($order->getStoreToOrderRate()); 00304 00305 return $shipment; 00306 } 00307 00308 /** 00309 * Convert order item object to Shipment item 00310 * 00311 * @param Mage_Sales_Model_Order_Item $item 00312 * @return Mage_Sales_Model_Order_Shipment_Item 00313 */ 00314 public function itemToShipmentItem(Mage_Sales_Model_Order_Item $item) 00315 { 00316 $shipmentItem = Mage::getModel('sales/order_shipment_item'); 00317 $shipmentItem->setOrderItem($item) 00318 ->setProductId($item->getProductId()); 00319 00320 Mage::helper('core')->copyFieldset('sales_convert_order_item', 'to_shipment_item', $item, $shipmentItem); 00321 // ->setName($item->getName()) 00322 // ->setSku($item->getSku()) 00323 // ->setDescription($item->getDescription()) 00324 // ->setPrice($item->getPrice()) 00325 // ->setBasePrice($item->getBasePrice()) 00326 // ->setWeight($item->getWeight()); 00327 00328 return $shipmentItem; 00329 } 00330 00331 /** 00332 * Convert order object to creditmemo 00333 * 00334 * @param Mage_Sales_Model_Order $order 00335 * @return Mage_Sales_Model_Order_Creditmemo 00336 */ 00337 public function toCreditmemo(Mage_Sales_Model_Order $order) 00338 { 00339 $creditmemo = Mage::getModel('sales/order_creditmemo'); 00340 $creditmemo->setOrder($order) 00341 ->setStoreId($order->getStoreId()) 00342 ->setCustomerId($order->getCustomerId()) 00343 ->setBillingAddressId($order->getBillingAddressId()) 00344 ->setShippingAddressId($order->getShippingAddressId()); 00345 00346 Mage::helper('core')->copyFieldset('sales_convert_order', 'to_cm', $order, $creditmemo); 00347 // ->setBaseCurrencyCode($order->getBaseCurrencyCode()) 00348 // ->setStoreCurrencyCode($order->getStoreCurrencyCode()) 00349 // ->setOrderCurrencyCode($order->getOrderCurrencyCode()) 00350 // ->setStoreToBaseRate($order->getStoreToBaseRate()) 00351 // ->setStoreToOrderRate($order->getStoreToOrderRate()); 00352 00353 return $creditmemo; 00354 } 00355 00356 /** 00357 * Convert order item object to Creditmemo item 00358 * 00359 * @param Mage_Sales_Model_Order_Item $item 00360 * @return Mage_Sales_Model_Order_Creditmemo_Item 00361 */ 00362 public function itemToCreditmemoItem(Mage_Sales_Model_Order_Item $item) 00363 { 00364 $creditmemoItem = Mage::getModel('sales/order_creditmemo_item'); 00365 $creditmemoItem->setOrderItem($item) 00366 ->setProductId($item->getProductId()); 00367 00368 Mage::helper('core')->copyFieldset('sales_convert_order_item', 'to_cm_item', $item, $creditmemoItem); 00369 // ->setName($item->getName()) 00370 // ->setSku($item->getSku()) 00371 // ->setDescription($item->getDescription()) 00372 // ->setPrice($item->getPrice()) 00373 // ->setBasePrice($item->getBasePrice()) 00374 // ->setCost($item->getCost()); 00375 00376 return $creditmemoItem; 00377 } 00378 }