我正在使用Magento 1.9.2,我正在开发自定义扩展程序。
以下是我用于选择具有特定状态的所有订单的代码:
<?php $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', 'complete'); ?>
如何选择除具有特定状态的订单以外的所有订单?
以下是我使用上面显示的代码的完整代码:
<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', 'complete') ?>
<div class="page-title">
<h1><?php echo $this->__('My Orders') ?></h1>
</div>
<?php echo $this->getChildHtml('info');?>
<?php echo $this->getPagerHtml(); ?>
<?php if($_orders->getSize()): ?>
<table class="data-table orders" id="my-orders-table">
<col width="1" />
<col width="1" />
<col />
<col width="1" />
<col width="1" />
<col width="1" />
<thead>
<tr>
<th class="number"><?php echo $this->__('Order #') ?></th>
<th class="date"><?php echo $this->__('Date') ?></th>
<th class="ship"><?php echo $this->__('Ship To') ?></th>
<th class="total"><span class="nobr"><?php echo $this->__('Order Total') ?></span></th>
<th class="status"><span class="nobr"><?php echo $this->__('Order Status') ?></span></th>
<th class="view"> </th>
</tr>
</thead>
<tbody>
<?php $_odd = ''; ?>
<?php foreach ($_orders as $_order): ?>
<tr>
<td class="number"><?php echo $_order->getRealOrderId() ?></td>
<td class="date"><span class="nobr"><?php echo $this->formatDate($_order->getCreatedAtStoreDate()) ?></span></td>
<td class="ship"><?php echo $_order->getShippingAddress() ? $this->escapeHtml($_order->getShippingAddress()->getName()) : ' ' ?></td>
<td class="total"><?php echo $_order->formatPrice($_order->getGrandTotal()) ?></td>
<td class="status"><em><?php echo $_order->getStatusLabel() ?></em></td>
<td class="a-center view">
<span class="nobr"><a href="<?php echo $this->getViewUrl($_order) ?>"><?php echo $this->__('View Order') ?></a>
<?php /*<span class="separator">|</span><a href="<?php echo $this->getTrackUrl($_order) ?>"><?php echo $this->__('Track Order') ?></a> */ ?>
<?php if ($this->helper('sales/reorder')->canReorder($_order)) : ?>
<span class="separator">|</span> <a href="<?php echo $this->getReorderUrl($_order) ?>" class="link-reorder"><?php echo $this->__('Reorder') ?></a>
<?php endif ?>
</span>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<script type="text/javascript">decorateTable('my-orders-table');</script>
<?php echo $this->getPagerHtml(); ?>
<?php else: ?>
<p><?php echo $this->__('You have placed no orders.'); ?></p>
<?php endif ?>
提前致谢!
答案 0 :(得分:2)
<?php $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status',array('neq' => 'complete')); ?>
或者当您有多种状态时
<?php $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status',array('nin' => array('pending','complete'))); ?>
答案 1 :(得分:1)
您可以使用“不等于”:
...->addAttributeToFilter('status', array('neq' => 'thestatus'));
答案 2 :(得分:1)
<?php $_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status',array('neq' => 'complete')); ?>
答案 3 :(得分:1)
获取已取消订单的状态
/*
* Determine the number of cells the given string would take up on the screen,
* limited (in the case of wide characters) by the maxCells parameter.
*
* If the returnCellNum parameter is TRUE, return the number of cells;
* otherwise, return the length (limited by the len parameter) of the prefix of
* the string that fits in maxCells cells.
*/
获取处理订单的状态
$orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', 'canceled');
foreach ($orders as $order) {
echo $order->getStatus();
}
只需更改订单状态即可获取各个订单的详细信息 您还可以从$ order对象获取所有订单数据