我希望得到管理员方面所有客户的所有订单,以便在csv中导出它们,但我遇到问题,在下面的foreach中不知道为什么它不会将$ collection转换为$ col并给我那个例子,你能帮帮我吗?
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));
Mage::log("80",null,"ordenes.log");
foreach ($collection as $col) { //falls here Mage::log($col,null,"ordenes.log");
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";
答案 0 :(得分:0)
问题出在你的addAttributeToFilter()过滤器中。该集合正在获取空数据。
如果删除日期过滤器,则代码正常运行。或者尝试增加From&amp;至今差异。
require_once('app/Mage.php');
Mage::app('admin');
Mage::getSingleton("core/session", array("name" => "adminhtml"));
Mage::register('isSecureArea',true);
$collection = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*');
$min_diff = '60';
$from_date = date("Y-m-d H:i:s", strtotime("-".$min_diff." minute"));
$to_date = date("Y-m-d H:i:s");
/*$collection->addAttributeToFilter('updated_at', array(
'from' => $from_date,
'to' => $to_date
));*/
Mage::log("80",null,"ordenes.log");
foreach ($collection as $col) { //falls here Mage::log($col,null,"ordenes.log");
echo '<tr>';
echo "<td>".$col->getIncrementId()."</td>";
echo "<td>".$col->getCreatedAt()."</td>";
echo "<td>".$col->getUpdatedAt()."</td>";
echo "<td>".$col->getState()."</td>";
echo "<td>".$col->getStatus()."</td>";
echo "<td>".$col->getHpcOrderId()."</td>";
echo "<td>".$col->getHpcOrderFrom()."</td>";
echo '</tr>';
}
echo '</table>';
echo "<br />supplement order ends";