我正在构建一个扩展,将已完成的订单信息导出到CSV文件中。我已经能够成功访问出口的订单和商品信息,但在访问促销数据时遇到问题。
我希望在导出中包括应用于该订单的促销数据(目录和购物车规则)。具体来说,我正在尝试访问特定订单列表的规则ID、名称、描述、代码和应用美元金额。
我将如何访问扩展中的促销数据
如果有帮助的话,以下是我目前访问扩展中订单/项目数据的方式(按日期框限定):
$rows = array(); // array to hold data that will be exported to CSV
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$orders = $read->query("SELECT entity_id FROM sales_flat_order WHERE created_at >= '$from' AND created_at < '$today'");
while ($row = $orders->fetch()) {
$order = Mage::getModel('sales/order')->load($row['entity_id']);
$order_items = $read->query("SELECT item_id FROM sales_flat_order_item WHERE order_id={$order->getId()}");
while ($item_row = $order_items->fetch()) {
$item = Mage::getModel('sales/order_item')->load($item_row['item_id']);
$rows[] = array(
$order->getRealOrderId(),
$order->getCreatedAt(),
$item->getSky(),
$item->getQtyOrdered(),
..... );
); // end item loop
); // end order loop
提前感谢您能提供的任何帮助,
-标记
我相信这个问题在过去的另一个问题上已经得到了回答。你可以在这里找到原始问题和答案的链接Magento-从订单获得价格规则
不过从这个答案来看。。
//The order I want to check
$order_id = 859;
//Get the list of items for your order
$items = Mage::getModel('sales/order_item')
->getCollection()
->addFilter('order_id',array('eq'=>$order_id));
//loop through each item
foreach($items as $item){
//if the item has not had a rule applied to it skip it
if($item->getAppliedRuleIds() == '')continue;
/*
* I cant remember in the database they might be comma separated or space if multiple rules were applied
* the getAppliedRuleIds() function is the one you want
*/
foreach(explode(",",$item->getAppliedRuleIds()) as $ruleID){
//Load the rule object
$rule = Mage::getModel('catalogrule/rule')->load($ruleID);
// Throw out some information like the rule name what product it was applied to
echo "<p>".$item->getSku()." had rule ".$rule->getName()."(".$item->getAppliedRuleIds().") applied </p>";
}
}