Magento my processing order count - magento

How can I get count of customer's processing order status ??
Like Mage::getModel('checkout/cart')->getQuote()->getItemsCount().
Please let me know.
Thank you.

To get only the number of orders in a processing stateā€¦
$processingOrdersCount = Mage::getModel('sales/order')->getCollection()
->addFilter('status', Mage_Sales_Model_Order::STATE_PROCESSING)
->getSize()
;

Here is a similar question that loads the order collection with the 'status' field you are after:
Get order ids with status = 'Complete' in Magento

Related

wrong order in typo3 tt_content

in typo3 tt_content the field sorting doesn't show the real order of the elements of a page. Is there any possibility to reorder it, to refresh it?
I want in a selection the bodytext and image of the first Contentelement (textpic) of a page.
Thanks
Volker
I don't really get your question but the order is correct in the backend, however you need to have some things in mind
the sorting depends on the page (field pid), so you can't compare sorting over multiple plages
The field colPos is also important as sorting is unique per column
I got the problem. In my installation in the tt_content is not updating the field "sorting" after a clean installation the problem is solved.
Thanks
Volker
A try of a concrete answer to a vague question:
lib.someContent = CONTENT
lib.someContent {
table = tt_content
select {
where = colPos=0
orderBy = sorting
languageField = sys_language_uid
begin = 0
max = 1
}
}

Getting Order Number from Order Id in Magento?

I am using following code to get the Order Number from Order ID.
$orderId=64; //Order Id will be supplied dynamically
$order = Mage::getModel('sales/order')->load($orderId);
echo "Order Number is: ".$order['increment_id'];
I am getting the correct order number using this code like 100000067.
I wanted to know Is this the correct approach to use.
Please guide.
Thanks
This should work for you.
$orderId = 64;
$order = Mage::getModel('sales/order')->load($orderId);
echo $order->getIncrementId();
Cheers!

Observer Magento - Order Cancel

I wonder what the correct event that I observe when a sale is canceled.
I'm trying to "sales_order_item_cancel" but I do not know if that's correct. Besides how can I get the ID of the sale?
I'm trying this way:
$order = $observer->GetEvent()->GetOrder()->getID();
but not working.
Thank You
Should always be camel case ..->get[Xyz]()
$order = $observer->getEvent()->getOrder()->getId();
See
app/code/core/Mage/Sales/Model/Order.php 1139 order_cancel_after
app/code/core/Mage/Sales/Model/Order/Item.php 512 sales_order_item_cancel
Mage::dispatchEvent('sales_order_item_cancel', array('item'=>$this));
Since sales_order_item_cancel dispatch item try
print_r($observer->getEvent()->getItem())
i think it is better to use sales_order_payment_cancel if you want to observe the whole order and not just single items.
You can access the order by $order = $observer->getPayment()->getOrder();
Cheers
Simon

Unexpected behavior in Magento collection filters used in loops

I'm seeing an unexpected behavior in collections that maybe someone can enlighten me on (or maybe it's a bit of PHP I don't grok) (sorry for the length of this post, but I had to include sample code and results).
My goal was to write a report where I get an order and it's order items, then go to the invoice and shipment data for the order and get the matching order item data from their items. I know that there is only one invoice and shipment for all orders, so even though Magento uses a 1-M relationship between orders and invoices/shipments, I can take advantage of it as if it were 1-1
I know that the items are all related using the order_item_id fields, so I tried to write a function that used the the following call -
$invoiceItem = $order
->getInvoiceCollection()
->getFirstItem()
->getItemsCollection()
->addFieldToFilter('order_item_id', $orderItem->getItemId())
->getFirstItem();
But that didn't results I expected, what I saw was the same invoice item returned regardless of the order item id used in the filter.
So, to try to understand the problem, I wrote the following small program to see how the queries where created.
<?php
require dirname(__FILE__).'/../app/Mage.php';
umask(0);
Mage::app('default');
$orders = Mage::getResourceModel('sales/order_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('state', 'processing')
->addAttributeToSort('created_at', 'desc')
->addAttributeToSort('status', 'asc')
->load();
foreach ($orders as $order) {
echo "\ngetting data for order id ". $order->getId();
$items = $order->getAllItems();
$invoice = $order->getInvoiceCollection()->getFirstItem();
foreach ($items as $orderItem) {
echo "\n\ngetting data for order item id ". $orderItem->getItemId();
$invoiceItems = $order
->getInvoiceCollection()
->getFirstItem()
->getItemsCollection()
->addFieldToFilter('order_item_id', $orderItem->getItemId());
echo "\n".$invoiceItems->getSelect();
}
die; //just quit after one iteration
}
The output from this program was the following -
getting data for order id 7692
getting data for order item id 20870
SELECT `main_table`.* FROM `sales_flat_invoice_item` AS `main_table` WHERE (parent_id = '7623') AND (order_item_id = '20870')
getting data for order item id 20871
SELECT `main_table`.* FROM `sales_flat_invoice_item` AS `main_table` WHERE (parent_id = '7623') AND (order_item_id = '20870') AND (order_item_id = '20871')
getting data for order item id 20872
SELECT `main_table`.* FROM `sales_flat_invoice_item` AS `main_table` WHERE (parent_id = '7623') AND (order_item_id = '20870') AND (order_item_id = '20871') AND (order_item_id = '20872')
As you can see, every time though the loop another "AND (order_item_id =" was added for each item Id that I was filtering on. I thought that every time though the loop, I'd be getting a fresh version of the collection from using $order->getInvoiceCollection().
So, can anyone tell me what's going wrong in my sample code and educate me on the correct way to do this?
Thanks!
Regarding your business question: need more info. Is the goal to generate a collection with order item objects which are EACH aware of invoice and shipment details? It seems like there are rendering concerns getting pushed into modeling concerns.
Regarding the select statement question: Varien collections have an optimization which prevents them from accessing the storage backend more than once. This standard behavior is achieved in DB collection instances by setting the _isCollectionLoaded property to true.
In your case, the invoice collection instance is created via the order instance stored in a protected property, and immediately load()ed via IteratorAggregate (invoked via foreach). Because you are using the same order object instance in each iteration, you are dealing with this loaded invoice collection instance and are effectively calling addFieldToFilter(/* next order id */) with each iteration, resulting in the ever-expanding WHERE clause. This specific optimization can easily be worked around by calling $order->reset(). This brings us back to the salient issue though, which is the need to better understand the goal and (likely) use a custom collection or to manipulate a collection to join in the specific data that you need.

Get ordernumber on the event sales_order_payment_pay

I'm trying to get my order number on the event sales_order_payment_pay
But somehow I got nothing .. maybe you can help me ?
Here is the sample of my code in my Observer.php
public function functioninobserver($observer) {
$orderid = $observer->getEvent()->getInvoice()->getIncrementId();
}
First of all it returns nothing and I think Incrementid is not the same as orderthe number ...
The invoice isn't the same as the order, you can get the order in a slightly roundabout way...
$orderId = $observer->getPayment()->getOrder()->getId();
$orderNumber = $observer->getPayment()->getOrder()->getIncrementId();
Just to clarify; The order ID is used internally in the database. The order number is what's displayed on screen and looks like #100000123.

Resources