Downloading order details through Mage::getModel('sales/order')
-
16-10-2019 - |
سؤال
I am trying to download order details (email + name) from my stores. We have a multi-store.
The problem that I have is that when I run this code on STORE 1 or STORE 2 - both result in the full collection of orders. What I need is the orders belonging to STORE 1 or 2 etc
The snippet below is part of a PHP in the root of my domain.
I tried all three options mentioned below ...
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]
How can this be done?
المحلول
This should work on versions 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 />";
}
لا تنتمي إلى magento.stackexchange