我正在开发module
的magento
,其中我显示了网页上的所有订单以及每个订单,我展示了完整的订单信息,包括与该订单相关的购买产品。我能够显示所有订单,但我不明白,其中有多个产品的订单仅显示单个产品,而当我在销售订单下选择销售 - >订单时,显示多于一个产品那里。无法获取Magento中的所有订单项目?
这里是我的代码:
public function indexAction()
{
$model = Mage::getModel('sales/order');
$product_model = Mage::getModel('catalog/product');
$collection = $model->getCollection()
->addFieldToFilter('status', array("in" => array('complete','closed','pending','holded','payment_review','pending_payment','pending_paypal','processing')));
$data = array();
$orderArr = array();
$records = 0;
foreach($collection as $order)
{
$data[$records]['order_data']['shipping_address'] = $order->getShippingAddress()->getData(); // get shipping details
$data[$records]['order_data']['billing_address'] = $order->getBillingAddress()->getData(); // get billing details
$data[$records]['order_data']['order_total'] = $order->getGrandTotal(); // get total amount
$items_obj = $model->loadByIncrementId($order['increment_id']); // get all items
$items = $items_obj->getAllItems();
$data[$records]['order_data']['order_id'] = $order['increment_id'];
$i = 0;
$productData = array();
$orderProductArr = array();
foreach($items as $itemId => $item)
{
$_product = $product_model->load($item->getProductId()); // getting product details here to get description
$taxClassId = $_product->getData("tax_class_id");
$taxClass = $_product->getData("tax_class_name");
$taxRate = $order['tax_amount'];
$orderProductArr[$i]['web_id'] = $item->getProductId();
$orderProductArr[$i]['quantity'] = $item->getQtyToInvoice();
$orderProductArr[$i]['price'] = $item->getPrice();
$orderProductArr[$i]['description'] = $_product->getDescription();
$orderProductArr[$i]['currency'] = $order['order_currency_code'];
$orderProductArr[$i]['tax_id'] = $taxClassId;
$orderProductArr[$i]['tax_amt'] = $taxRate;
$orderProductArr[$i]['total_amt'] = ($item->getPrice()*$item->getQtyToInvoice())+($taxRate);
$productData[$i]['title'] = $item->getName();
$productData[$i]['web_product_id'] = $item->getProductId();
$productData[$i]['price'] = $item->getPrice();
$productData[$i]['product_sku'] = $item->getSku();
$productData[$i]['tax_class'] = $taxClassId;
$productData[$i]['description'] = $_product->getDescription();
$tax_arr[$i]['tax_id'] = $taxClassId;
$tax_arr[$i]['tax_class'] = $taxClassId;
$tax_arr[$i]['tax_amt'] = $taxRate;
$i++;
}
$data[$records]['order_data']['product_details'] = $orderProductArr;
$data[$records]['order_data']['order_product_details'] = $productData;
$data[$records]['order_data']['tax_arr'] = $tax_arr;
$data[$records]['order_data']['shipping_amount'] = $order->getShippingAmount();
$data[$records]['order_data']['order_details'] = $order->toArray();
unset($orderProductArr);
unset($productData);
$records++;
}
echo "<pre>";
print_r($data);
echo "</pre>";
}
任何人都可以请帮我这个?
任何帮助,将不胜感激。
谢谢。
@ R,S你能帮帮我吗? – 2013-03-15 13:21:29
$ order ['increment_id']给我100000108这是正确的,我得到的项目增量ID作为我的函数说loadByIncrementId。 – 2013-03-15 13:26:07
@ R.S是否有任何其他方式获取magento中所有订单的产品? – 2013-03-15 13:33:37