通过Mage :: GetModel下载订单详细信息('销售/订单')
-
16-10-2019 - |
题
我正在尝试从商店下载订单详细信息(电子邮件 +名称)。我们有一个多商店。
我遇到的问题是,当我在商店1或Store 2上运行此代码时 - 两者都会全部收集订单。我需要的是属于商店1或2等的订单
下面的摘要是我域根中的PHP的一部分。
我尝试了下面提到的所有三个选项...
Mage::app();
[OPTIONS I TRIED]
// ->addAttributeToFilter('store_id', Mage::app()->getStore()->getId())
//->addStoreFilter(Mage::app()->getStore()->getId())
// ->setStoreId(Mage::app()->getStore()->getId())
$orders = Mage::getModel('sales/order')
->getCollection()
[OPTIONS]
如何才能做到这一点?
解决方案
这应该适用于版本1.4.0.1+
/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';
/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';
Mage::app($mageRunCode,$mageRunType);
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
->addAttributeToSort('entity_id', 'DESC');
echo "<html><body>";
foreach($orders as $order) {
echo $order->getCustomerName() . "\t" .
$order->getCustomerEmail() . "\r\n<br />";
}