我们正在从旧的,过时的销售点系统切换到仅使用Magento 1.7作为我们的POS。毫不意外的是,我们面临的挑战之一是如何在不造成灾难的情况下从旧系统到Mage获得近20年的记录。
撇开甚至迁移客户记录的挑战,我在此问题上关注的问题是如何将历史订单数据从旧POS迁移到Mage。当我们要谈论的订单记录很多时,我不确定100%的确切数字,但是我至少要说一百万。
这是我在考虑如何实现此目标方面的想法:
- 弄清楚如何格式化数据才能使Magento更好地使用它。我们是否能够以一种可行的格式将其从旧POS机中取出是值得怀疑的,但是让我们暂时假设它运行良好...
- 使用格式正确的历史数据创建一个.CSV文件
- 找到一种将.CSV
$order
逐行读入Magento 对象的方法-> save() - 利润!
我的问题是我对如何逼近第2点和第3点有点困惑。我可以格式化从旧POS发出的数据,尽管它非常麻烦并且涉及Perl,但是我需要格式化,但是一旦有了.CSV文件(或此过程实际上可以使用的任何文件类型),我就不清楚我如何将其输入到Magento的订单对象中。
我已经完成了一些谷歌搜索工作,并列举了一些人使用Mage的order对象以编程方式导入订单的示例,但是很少有人讨论他们如何将前端购物车以外的数据源连接到所述对象。我一直在研究订单对象的版本:
$id=1; // get Customer Id
$customer = Mage::getModel('customer/customer')->load($id);
$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$order = Mage::getModel('sales/order')
->setIncrementId($reservedOrderId)
->setStoreId($storeId)
->setQuoteId(0)
->setGlobal_currency_code('USD')
->setBase_currency_code('USD')
->setStore_currency_code('USD')
->setOrder_currency_code('USD');
// set Customer data
$order->setCustomer_email($customer->getEmail())
->setCustomerFirstname($customer->getFirstname())
->setCustomerLastname($customer->getLastname())
->setCustomerGroupId($customer->getGroupId())
->setCustomer_is_guest(0)
->setCustomer($customer);
// set Billing Address
$billing = $customer->getDefaultBillingAddress();
$billingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
->setCustomerId($customer->getId())
->setCustomerAddressId($customer->getDefaultBilling())
->setCustomer_address_id($billing->getEntityId())
->setPrefix($billing->getPrefix())
->setFirstname($billing->getFirstname())
->setMiddlename($billing->getMiddlename())
->setLastname($billing->getLastname())
->setSuffix($billing->getSuffix())
->setCompany($billing->getCompany())
->setStreet($billing->getStreet())
->setCity($billing->getCity())
->setCountry_id($billing->getCountryId())
->setRegion($billing->getRegion())
->setRegion_id($billing->getRegionId())
->setPostcode($billing->getPostcode())
->setTelephone($billing->getTelephone())
->setFax($billing->getFax());
$order->setBillingAddress($billingAddress);
$shipping = $customer->getDefaultShippingAddress();
$shippingAddress = Mage::getModel('sales/order_address')
->setStoreId($storeId)
->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
->setCustomerId($customer->getId())
->setCustomerAddressId($customer->getDefaultShipping())
->setCustomer_address_id($shipping->getEntityId())
->setPrefix($shipping->getPrefix())
->setFirstname($shipping->getFirstname())
->setMiddlename($shipping->getMiddlename())
->setLastname($shipping->getLastname())
->setSuffix($shipping->getSuffix())
->setCompany($shipping->getCompany())
->setStreet($shipping->getStreet())
->setCity($shipping->getCity())
->setCountry_id($shipping->getCountryId())
->setRegion($shipping->getRegion())
->setRegion_id($shipping->getRegionId())
->setPostcode($shipping->getPostcode())
->setTelephone($shipping->getTelephone())
->setFax($shipping->getFax());
$order->setShippingAddress($shippingAddress)
->setShipping_method('flatrate_flatrate')
->setShippingDescription($this->getCarrierName('flatrate'));
$orderPayment = Mage::getModel('sales/order_payment')
->setStoreId($storeId)
->setCustomerPaymentId(0)
->setMethod('purchaseorder')
->setPo_number(' - ');
$order->setPayment($orderPayment);
// let say, we have 2 products
$subTotal = 0;
$products = array(
'1001' => array(
'qty' => 1
),
'1002' ->array(
'qty' => 3
),
);
foreach ($products as $productId=>$product) {
$_product = Mage::getModel('catalog/product')->load($productId);
$rowTotal = $_product->getPrice() * $product['qty'];
$orderItem = Mage::getModel('sales/order_item')
->setStoreId($storeId)
->setQuoteItemId(0)
->setQuoteParentItemId(NULL)
->setProductId($productId)
->setProductType($_product->getTypeId())
->setQtyBackordered(NULL)
->setTotalQtyOrdered($product['rqty'])
->setQtyOrdered($product['qty'])
->setName($_product->getName())
->setSku($_product->getSku())
->setPrice($_product->getPrice())
->setBasePrice($_product->getPrice())
->setOriginalPrice($_product->getPrice())
->setRowTotal($rowTotal)
->setBaseRowTotal($rowTotal);
$subTotal += $rowTotal;
$order->addItem($orderItem);
}
$order->setSubtotal($subTotal)
->setBaseSubtotal($subTotal)
->setGrandTotal($subTotal)
->setBaseGrandTotal($subTotal);
$transaction->addObject($order);
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));
$transaction->save();
所以这是我的具体问题:
- 对于这个问题,这似乎是一种遥不可及的方法吗?而且,如果没有,您认为我如何能像白痴一样来解决这个问题?
- 如果这是一种明智的方法,那么对于订购过程调用的每个模型,我是否需要不同的.CSV?即Mage :: getModel('sales / order'),Mage :: getModel('sales / order_address')等?
- .CSV甚至可以解决吗?
- 无论数据是包含在.CSV中还是您拥有什么,我如何将数据输入到该对象中?
- 您将如何限制开销?
即使我以一种完全愚蠢的方式来考虑这个问题,而您告诉了我很多,我真的很感谢任何投入。
谢谢你,谢谢你,谢谢你!