I have order increment id like 100000096 and i want to get its invoice id, please help me to achieve this in magento, i have tried with
$incrementId = '100000096';
$order = Mage::getModel('sales/order')->load($incrementId);
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
But it returns an empty array.
You are using order increment id in load() function, you have to use loadByIncrementId().
Try to use this -
$orderid = '100000096'; // order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
if ($order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
}
}
echo "<pre>";
print_r($invIncrementIDs);
echo "</pre>";
Try this :
$orderIncrementId = '100000004'; // your order increment id
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
if ($order->hasInvoices()) {
$invIncrementId = array();
foreach ($order->getInvoiceCollection() as $invoice) {
$invoiceIncId[] = $invoice->getIncrementId();
}
}
echo "<pre>";print_r($invoiceIncId);echo '<br>';
In order to get Invoice id from Invoice incrementId
$incrementId = $invoiceIncId[0];
$invoive = Mage::getModel('sales/order_invoice')->loadByIncrementId($incrementId);
$invoiceId = $invoice->getId();
echo "<pre>";print_r($invoiceId);exit;
try this you will not regret
$order_id = "type_here_your_orderid";
$invoices = Mage::getResourceModel('sales/order_invoice_collection')
->setOrderFilter($order_id)
->load();
$invoice_id = $invoices->getData()[0]["increment_id"];
echo $invoice_id;
thats all.
Related
i am trying here ,
see i am getting order data but, i am not getting any $order->hasInvoice()
$orderID = 100000062;
$order = Mage::getModel('sales/order')->load($orderID);
if ($order->hasInvoices()) {
$invIncrementIDs = array();
foreach ($order->getInvoiceCollection() as $inv) {
$invIncrementIDs[] = $inv->getIncrementId();
} Mage::log($invIncrementIDs);
}
Could you please try the following code:
$orders_invoice = Mage::getModel("sales/order_invoice")->getCollection();
foreach($orders_invoice as $val) {
print_r($val->getData());
}
I try write this code
public function allsalesblock(){
echo 'other block ';
$orders = Mage::getResourceModel('sales/order_collection')
->addFieldToSelect('*')
->addFieldToFilter('customer_id', Mage::getSingleton('customer/session')->getId());
->addAttributeToSort('created_at', 'DESC');
$order = Mage::getModel("sales/order")->load($orders); //load order by order id
$ordered_items = $order->getAllItems();
foreach($ordered_items as $item){
echo $item->getItemId(); //product id
echo $item->getSku();
echo $item->getQtyOrdered(); //ordered qty of item
echo $item->getName();
}
}
But this doesn't work - i see white screen. I found this code(and modification) here How can I display all products bought by a customer in magento?
You can get it using below code,
<?php
require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
$email = 'albert#example.com';
$_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_email',$email);
foreach ($_orders as $order) {
$id[]= $order->getId();
}
//print_r($id);
foreach ($id as $order_id) {
$order = Mage::getModel('sales/order')->load($order_id);
#get all items
$items = $order->getAllItems();
$itemcount= count($items);
$data = array();
$i=0;
#loop for all order items
foreach ($items as $itemId => $item)
{
$data[$i]['name'] = $item->getName();
$data[$i]['price'] = $item->getPrice();
$data[$i]['sku'] = $item->getSku();
$data[$i]['id'] = $item->getProductId();
$data[$i]['qty'] = $item->getQtyToInvoice();
}
#displaying the array in order to see the products
echo '<pre/>';print_r($data);
}
here change the email address as you want to get products which that customer bought,
$email = 'albert#example.com';
Hello i need to get the quantity of the item added in cart for the item i am viewing in product detail
atm i am using this
<?php $cart = Mage::getModel('checkout/cart')->getQuote();
$result = array();
foreach ($cart->getAllItems() as $item) {
$result['qty'] = $item->getQty();
}
$qty=$result['qty'];
//echo $qty ;
if(!$qty == 0){
echo '<span>'.$qty.'</span>';
}else{
echo "<span>0</span>";
}?>
but it returns only the last qty added/updated in the cart, and i need the specific single product qty
Try this:
//$product is current product that you are viewing
$qty = null;
foreach ($cart->getAllItems() as $item) {
if ($product->getId() == $item->getProductId()) {
$qty = $item->getQty();
}
}
if (!is_null($qty)) {
//$qty is what you are looking for
}
else {
//the current product is not in the cart
}
Hi i would like to know how to get the qty_ordered of a specific product in an order with several products.
i have tried these
$orders = Mage::getModel('sales/order')->getCollection()->
addAttributeToSelect('shipping_description')->
addAttributeToSelect('increment_id')->
addAttributeToSelect('base_grand_total')->
addAttributeToSelect('total_qty_ordered')->
addAttributeToSelect('shipping_address_id')->
addAttributeToSelect('billing_address_id')->
addAttributeToSelect('created_at')->
addAttributeToSelect('shipping_incl_tax')->
addAttributeToFilter('status', 'pending');
but addAttributeToSelect('total_qty_ordered')-> which total? which product?
"total_qty_ordered" give total no orders qty of all product in an order
If,you want item qty of product then
you can try
<?php $order_id = 2314; //use your own order id
$order = Mage::getModel("sales/order")->load($order_id); //load order by order id
$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.
} ?>
for me it worked like this:
<?php
$_order = $this->getOrder(); //call the order
$order_qty = floor($_order->getData('total_qty_ordered')); //get qty of all items rounded to full number (without 3.0000 or so)
echo $order_qty;
?>
used it on template/sales/order/totals.phtml
You can Try this also:-
$orderCollection = Mage::getModel('sales/order');
$order_data = $orderCollection->getAllVisibleItems();
foreach ($order_data as $key) {
$id = $key->getProductId();
$orderItems = Mage::getResourceModel('sales/order_item_collection')
->addAttributeToFilter('product_id', $id);
foreach ($orderItems as $key ) {
echo $number_of_prod = $key->getQtyOrdered();
}
}
I have this code:
$session = Mage::getSingleton('checkout/session');
foreach ($session->getQuote()->getAllItems() as $item) {
echo $item->getName();
echo $item->getId();
echo Mage::helper('core')->formatPrice($item->getPrice());
}
But I want to get shipping address and order status of each item I ordered.
To get all orders for the current log in customer
$customerId = Mage::getSingleton('customer/session')->getCustomer()->getId();
$_orders = Mage::getModel("sales/order")->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('customer_id', $customerId);
/* to get last order only -- uncomment
->setOrder('created_at', Varien_Data_Collection_Db::SORT_ORDER_DESC)
->setPageSize(1);
*/
foreach($_orders as $order) {
foreach($order->getAllItems() as $item){
echo $item->getName();
echo $item->getId();
echo Mage::helper('core')->formatPrice($item->getPrice());
}
//display status
echo $order->getStatusLabel();
//display shipping address
print_r($order->getShippingAddress()->getData());
}
To get order info for a particular order by order_id then
$order_id = 123; // put your order id here
$_order = Mage::getModel('sales/order')->load($order_id);
if(!$_order->getID()){
echo 'Order not found.';
}
else{
//display shipping address
print_r($_order->getShippingAddress()->getData());
foreach($_order->getAllItems() as $order) {
echo $order->getName();
echo $order->getId();
echo Mage::helper('core')->formatPrice($order->getPrice());
echo $order->getStatusLabel();
}
}
This code get the customer cart (so this is before you place an order)
$session = Mage::getSingleton('checkout/session');
Get shipping details by order id
$order_id = 2314; //use your own order id
$order = Mage::getModel("sales/order")->load($order_id); //load order by order id
$shipping_address = $order->getShippingAddress();
echo $shipping_address->getTelephone();
echo $shipping_address->getPostcode(); //use print_r($shipping_address->getData()); to get all the available elements of the object