I use the following line to load collection of orders from magento:
// Load Order Collection
$order_collection = Mage::getModel('sales/order')->getCollection();
How do you filter this collection to ignore orders with status "canceled" and "complete"?
Update
After posting this, I was bored so I did some digging around and this post helped me find the right lines of code: http://www.magentocommerce.com/boards/v/viewthread/201797/#t287235
This is how I solved it:
// Load Order Collection
$order_collection = Mage::getModel('sales/order')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status', array('nin' => array('canceled','complete')));
The customer id is required to fetch the customer placed Order collection in Magento 2. Get Customer Order collection, We have to create a factory object of Magento\Sales\Model\ResourceModel\Order\Collection class. Instantiate the Factory object to the __consturct() method and apply condition with customer id.
Let's fetch the products in your Magento 2 store. /** * @var $block \MageSpark\OrderItem\Block\Item */ $itemId = 120; // Use your desired item id here $itemCollection = $block->getOrderItem($itemId); echo $itemCollection->getOrderId(); echo "<pre>"; print_r($itemCollection->debug()); That's it.
Overview of joining data between 2 tables in Magento 2Step 1: Set a Collection class that extends. Step 2: Set your own function to get data. Step 3: Get the collection and call to filterOrder function above. Step 4: Save.
Use the addFieldToFilter
method
$order_collection = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('status', array('nin' => array('canceled','complete')));
If you want to use the original definitions:
$order_collection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', array('nin' => array(
Mage_Sales_Model_Order::STATE_NEW,
Mage_Sales_Model_Order::STATE_CANCELED
)));
Like defined in Mage_Sales_Model_Order:
/**
* Order states
*/
const STATE_NEW = 'new';
const STATE_PENDING_PAYMENT = 'pending_payment';
const STATE_PROCESSING = 'processing';
const STATE_COMPLETE = 'complete';
const STATE_CLOSED = 'closed';
const STATE_CANCELED = 'canceled';
const STATE_HOLDED = 'holded';
const STATE_PAYMENT_REVIEW = 'payment_review';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With