2
我正在研究應該在每晚結束時運行的腳本。它應該查詢當天銷售了多少具體產品(最好由SKU)並將其歸類。這個過程還有第二部分,但現在我只需要回應正確的價值即可。我對我應該如何做到這一點感到困惑。這是我到目前爲止:從Magento銷售/訂單模型中提取項目SKU?
require_once('../app/Mage.php');
ini_set("error_reporting",E_ALL);
ini_set("display_errors",true);
umask(0);
Mage::app('admin');
// Some sort of SKU counter variable
$sku_counter = 0;
// Create order collection object
$collection = Mage::getModel('sales/order')->getCollection();
// Apply date filter. This would be 1 day in production but using this range as a test.
$collection->addFieldToFilter(
'created_at',
array('from' => '2012-05-01', 'to' => '2012-05-09')
);
// Iterate it for displaying results
foreach ($collection as $order) {
// This is where I fall apart. I know I need to either get all items or only get
// items with the specific SKU. After that I need to get the quantity sold of that SKU
// and add it to my $sku_counter.
echo 'There were " . $sku_counter . "sales of SKU XX-XXXX yesterday.";
}
任何幫助表示讚賞!
謝謝。會給它一個鏡頭並報告回來! – jkphl