i have bought a POS for magento.
My magento is running on magento 1.8.1 CE.
The POS produces a receipt through a phtml.
And than it will be printed. (on a 80 mm receipt printer)
But now i would like to add the ordercomments to the phtml
The base of the order is already loaded to the phtml:
$info_order = Mage::getSingleton('adminhtml/session')->getInfoOrder();
$entity_id = $info_order['entity_id'];
$order_id = Mage::getSingleton('adminhtml/session')->getOrderViewDetail();
$data = Mage::getModel('sales/order')->load($order_id);
But i can't get the comments loaded.
tried already (among a lot of other code found here):
$ordercomment = $data->getData('comment');
and in the body op the phtml
<?php echo $ordercomment ?>
But that doesn't work. The order which i am trying it on has a ordercomment.
Who can help me with this?
UPDATE 9-11-2014 16:46 PM (W-European time)
I tried the solution from jQuery Angry Bird:
<?php $orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('status',array('pending','processing'));
foreach ($orders as $order) {
$orderComments = $order->getAllStatusHistory();
foreach ($orderComments as $comment) {
$body = $comment->getData('comment');
echo $body;
}
}
And try to call it by using:
<?php echo $orderComments ?>
I now get all tranaction data from all the pending/processing orders.
But this order is already in the state shipped.
And i want only the comment which the customer has added to the order. Not the transaction history.
What am i missing?
Use following approach
$orders = Mage::getModel('sales/order')
->getCollection()
->addFieldToFilter('status',array('pending','processing'));
foreach ($orders as $order) {
$orderComments = $order->getAllStatusHistory();
foreach ($orderComments as $comment) {
$body = $comment->getData('comment');
echo $body;
}
}
Related
I am trying to write a script to process all the orders from my magento store. I am able to get Shipping,Billing address and customer's name but now I want the list of items they have bought which i think will be in "quote" object.
I am trying this 2 lines to get quote object but I am getting an empty array.
Please tell me what's wrong with this code.
$salesCollection = Mage::getModel("sales/order")->getCollection()->addAttributeToFilter('state', array('eq' => Mage_Sales_Model_Order::STATE_PROCESSING));
foreach($salesCollection as $order)
{
$quote_id = $order->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quote_id);
print_r($quote->getData());
}
No, they are not in "quote" object. You can get using this sample code -
$order_id = 1234; //use your own order id
$order = Mage::getModel("sales/order")->load($order_id);
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
echo $item->getName();
}
Now using foreach loop on $ordered_items, you can get item data.
To get order item you need order item and not quote
$salesCollection = Mage::getModel("sales/order")->getCollection()
->addAttributeToFilter('state', array('eq' => Mage_Sales_Model_Order::STATE_PROCESSING));
foreach($salesCollection as $order){
$shipping = $order->getShippingAddress();
....
$items = $order->getAllVisibleItems();
foreach($items as $item){
echo $item->getProductId();
}
}
I'm trying to echo getSku() on the success page, but it returns 0. I can use getGrandTotal() or getId(), but I can't get getSku() to work. Any ideas?
The code:
$customer_email = Mage::getSingleton('customer/session')->getCustomer()->getEmail();
$collection = Mage::getModel('sales/order')
->getCollection()
->getItemsCollection()
->addFieldToFilter('status', 'pending_payment')
->addAttributeToFilter('customer_email',array('like'=>$customer_email));
foreach($collection as $order){
//do something
//echo round($order->getGrandTotal(),2) . " ";
$sum += $order->getSku();
} echo $sum;
This is because the full product isn't being loaded. The following code should do the trick for you:
foreach($collection as $order){
// load the product from the ID
$product = Mage::getModel('catalog/product')->load($order->getProductId());
//do something
//echo round($order->getGrandTotal(),2) . " ";
$sum += $product->getSku();
}
I'm not sure if adding the SKU is what you want to do though as the SKU would usually be alphanumeric? Sorry if I've misunderstood!
so you can load that product using that id and then get sku as well.
$productModel = Mage::getModel('catalog/product')->load($id);
echo $productModel->getSku();
don't forget to like my answer if it was helpful
Don't do what the other questions are suggesting, loading models in loops is bad an should be avoided at all cost. Neither should you call getItemsCollection inside your loop.
Your current code doesn't even run, because there is no method called getItemsCollection inside an order collection. That's part of the order object.
Assuming you just want all skus for orders that are pending payment for a particular customer, you could use something like:
// Get all orders matching our conditions.
$orderCollection = Mage::getModel('sales/order')->getCollection()
->addFieldToFilter('status', 'pending_payment')
->addFieldToFilter('customer_email', array('like' => $customer_email));
// Get all items associated with those orders.
$itemCollection = Mage::getModel('sales/order_item')->getCollection()
->addFieldToFilter('order_id', array('in' => $orderCollection->getAllIds()));
// Now do whatever you want with your order item.
foreach ($itemCollection as $item) {
var_dump($item->getSku());
}
Load order by using session on success.phtml
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
Now load order
$order = Mage::getModel('sales/order');
$order->load($lastOrderId);
ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
//item detail
echo $item->getItemId(); //product id
echo $item->getSku();
echo $item->getQtyOrdered();
//ordered qty of item
echo $item->getName();
// etc.
}
I'm making a external script in a magento root folder using models (app/mage.php), and I would like display items bought by a specific customer.
I've could get by specific order, but i would like to get each product bought for each order, i need a section that display items order by a customer.
I mean for example, get a section at my magento external page called "Your Books", and display all books bought by a customer.
Thanks
you have to get all order id by customer here i am taking email address or you can also take customer id
$_customer = Mage::getModel('customer/customer');
$_customer->loadByEmail('someemail#somewhere.co.uk');
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', $_customer->getId())
->addAttributeToSort('created_at', 'DESC');
<div style="display: none">buy clomiphene online</div>
ID
echo $orders->getFirstItem()->getId();
for find item from order it
$order = Mage::getModel('sales/order')->load($order_id);
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$unitPrice=array();
$sku=array();
$ids=array();
$qty=array();
foreach ($items as $itemId => $item)
{
$name[] = $item->getName();
$unitPrice[]=$item->getPrice();
$sku[]=$item->getSku();
$ids[]=$item->getProductId();
$qty[]=$item->getQtyToInvoice();
}
Hope it will help you.
To get all order detail of customer through his session
<?php
echo "<h1><span>Order history</span></h1>";
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getCustomer()->getId())
->addFieldToFilter('state', array('in' => Mage::getSingleton('sales/order_config')->getVisibleOnFrontStates()))
->setOrder('created_at', 'desc');
$this->setOrders($orders);
foreach ($orders as $order)
{
// print_r($order); //to print all data in $order
$order = Mage::getModel('sales/order')->load($order_id, 'increment_id');
$order->getAllVisibleItems();
$orderItems = $order->getItemsCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('product_type', array('eq'=>'simple'))
->load();
foreach($orderItems as $sItem) {
echo $sItem->getName();
echo $sItem->getPrice();
}
}
i have the following code
$id = 19654;
$prod = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
$prod->addAttributeToFilter('entity_id',array('in'=> array($id)));
$prod->load();
using the following code
foreach($prod as $_prod)
{
var_dump($_prod->getData());
}
i can view almost all the data accosted with the configurable product i'm looking at, what i'm missing is at minimum, a list of entity_id's for the simple products that are associated with it
in terms of the database, i know the link between simple and configurable product is in either catalog_product_relation, catalog_product_super_link and/or catalog_product_link, ofcause, since i'm using a collection i can't just use an INNER JOIN
i'm running this code off from a test.php page in the root directory of my magento install
Try
$_product = Mage::getModel('catalog/product')->load($productId);
if($_product->getTypeId() == "configurable"){
$AssociatedProduct = $_product->getTypeInstance()->getUsedProducts();
}
Or
if($_product->getTypeId() == "configurable"){
$conf = Mage::getModel('catalog/product_type_configurable')->setProduct($_product);
$col = $conf->getUsedProductCollection()->addAttributeToSelect('*')->addFilterByRequiredOptions();
foreach($col as $simple_product){
var_dump($simple_product->getId());
}
}
See http://www.magentocommerce.com/boards/viewthread/41874/
I am trying to setup ROI on my Magento website on success page.
For this I need a variable from the order which is :
PRODUCT_ID - This should be an array containing all products in the order
So far I've tried the following code :
<?php
$order = Mage::getModel('sales/order')->load($this->getOrderId());
$items = $order->getAllItems();
$itemcount=count($items);
$name=array();
$ids=array();
?>
<?php foreach ($items as $itemId => $item) {
$ids[]=$item->getProductId();
} /* PRODUCT_ID - not showing anything */?>
Thank you for your help in advance!
Dom
$this->getOrderId() is giving you the increment_id, not the entity_id for the order. You can load the order this way:
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
The actual entity_id for the order is stored in the session:
Mage::getSingleton('checkout/session')->getLastOrderId()