Answers:
要按增量ID加载订单,可以这样做:
Mage::getModel('sales/order')->loadByIncrementId('10000001'); //use a real increment order id here
要按实体ID加载,您只需调用load
:
Mage::getModel('sales/order')->load(24999); //use an entity id here
获取订单明细取决于一些组件:
加载您的订单:(db:sales_flat_order)
$OrderNumber = "100000001";//Put your order Number here
$order = Mage::getModel('sales/order')->load($OrderNumber, 'increment_id');
接下来,根据订单过滤您的项目集合。
最会做的是:(db:sales_flat_order_item)
$order->getAllVisibleItems();
将显示可见的产品。问题在于,它将从集合中获取“可配置”项(奇怪的是记录中包含孩子的sku)。我发现在SKU更改的情况下这是不可预测的,因为历史SKU不再存在。相反,我发现最好执行以下替代方法。
$orderItems = $order->getItemsCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('product_type', array('eq'=>'simple'))
->load();
遍历订单项的集合
foreach($orderItems as $sItem) {
//Ignore conf for now
//Alt. Mage_Catalog_Model_Product_Type::TYPE_SIMPLE = 'simple';
if($sItem->getProductType() == "simple")
{
echo "\n*********************************\nMage Order #: ".$OrderNumber."\n";
//Simple Item Info from Order
echo "Type: ".$sItem->getProductType()."\n";
echo "Order Id: ".$sItem->getOrderId()."\n";
echo "Product Id: ".$sItem->getProductId()."\n";
echo "Item Id: ".$sItem->getId()."\n";
echo "Item Name: ".$sItem->getName()."\n";
echo "Item Sku: ".$sItem->getSku()."\n";
echo "Item Price: ".$sItem->getPrice()."\n";
$pItemId = $sItem->getParentItemId();
echo "Parent Item Id: ".$pItemId."\n";
echo "\n*****\n";
//Get Parent Item Information
$item = Mage::getModel('sales/order_item')->load("$pItemId"); //use an item_id here
//Testing, want to see whats inside the parent/configurable item?
//print_r($item->toArray());
echo "Parent Type: ".$item->getProductType()."\n";
echo "Parent Order Id: ".$item->getOrderId()."\n";
echo "Product Id: ".$item->getProductId()."\n";
echo "Item Id: ".$item->getId()."\n";
echo "Parent Item Price: ".$item->getPrice()."\n";
echo "Qty: ".$qty = intval($item->getQtyOrdered())."\n";
//get Active Product Data
$nProduct = Mage::getModel('catalog/product')->load($sItem->getProductId());
$nSku = $nProduct->getSku();
echo "new Product UPC:".$nUpc = $nProduct->getUpc() . "\n";
echo "new Product Price:".$nPrice = $nProduct->getPrice(). "\n";
}
}
intval
的getQtyOrdered
,但可以是一个十进制值:)
addAttributeToSelect
。谢谢。