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!
Related
Is there a Syntax to display total clients in WHMCS (as a number)? If not, is there any way of doing this?
You can use this ode within your template files.
Just put this lines of code within your /templates/yourtemplate/yourfile.tpl
{php}
$query ="SELECT COUNT(id) from tblclients ";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
echo "total clients :".$data[0];
{/php}
You can use getcontacts command for getting the total numbr of clients in WHMCS. You might want to have a look at this document:
http://docs.whmcs.com/API:Get_Contacts
I try to get address, which customer select in address step in checkout.
I use in /app/code/local/Mandarin/AddressTypeDiscount/Block/Onepage/Review.php this code:
$checkout = Mage::getSingleton('checkout/session')->getQuote();
$bilAddress = $checkout->getBillingAddress();
$mylog = print_r($bilAddress, true);
Mage::log("addres:".$mylog, null, 'mygento.log');
but in my log file I get array of all customer`s addresses.
How I could get selected address in address step?
Thanks.
Your code seem to be correct see Get billing information in order review section of one page checkout in Magento .
print_r($bilAddress, true) will print the entire object, instead try $bilAddress->getData()
Try
$checkout = Mage::getSingleton('checkout/session')->getQuote();
$billAddress = $checkout->getBillingAddress();
Mage::log($billAddress->getData());
For incremental order address id based on order,
$order_id=Mage::getSingleton('checkout/session')->getLastRealOrderId();
$sales_order=Mage::getModel('sales/order')->load($order_id);
$billing_address_id=$sales_order->billing_address_id;
$shipping_address_id=$sales_order->shipping_address_id;
For address entity id of the order based on customer,
$quote = Mage::getSingleton('checkout/session')->getQuote();
$billing_address_id=$quote->getBillingAddress()->customer_address_id;
$shipping_address_id=$quote->getShippingAddress()->customer_address_id;
Source
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
I need some basic information on my Magento checkout success page to check some conversions through my shop. For that I need the total price of the order and all article IDs.
While searching I found a code to get the last order:
<?php
$_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
?>
But how can I get the total price and all article IDs (seperated by ,).
I'm quiet new to Magento, so everything is a bit confusing to me.
Can somebody help me?
Thank you.
Greetings from Germany,
Raisis
You can get order total by $order->getData('base_grand_total');
in order to get all articles (loop through) you need to do,
foreach($order->getAllItems() as $items) {
$items->getName();
}
Use this code to get order object and order total, it's cleaner
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$total = $order->getGrandTotal();
?>
I am trying to get the entire magento product collection, without any filters or restrictions, but I fail to get all products.
I've tried various methods already, but they all give me a very limited selection of products. Let's say the store contains 5000 products, but it only shows 500. When I check the catalog -> products is does show me the entire list.
Mage::getModel('catalog/product')->getCollection();
Mage::getResourceModel('catalog/product_collection')->addAttributeToSelect('*');
Mage::getModel("catalog/product")->getResourceCollection()->load();
All of them return the same amount (500), while I expect it to give me 5000 products. I would prefer not to use Zend or PHP and just stick to the Magento way to get them.
Does anyone know how to really get ALL products or can point me in the right direction why this isn't working?
The select-string that is returned is:
SELECT 1 AS `status`, `e`.`entity_id`, `e`.`type_id`, `e`.`attribute_set_id` FROM `catalog_product_flat_4` AS `e`
//to overwrite limit but you need first to increase your memory limit
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('*') // select all attributes
->setPageSize(5000) // limit number of results returned
->setCurPage(1); // set the offset (useful for pagination)
// we iterate through the list of products to get attribute values
foreach ($collection as $product) {
echo $product->getName(); //get name
echo (float) $product->getPrice(); //get price as cast to float
echo $product->getDescription(); //get description
echo $product->getShortDescription(); //get short description
echo $product->getTypeId(); //get product type
echo $product->getStatus(); //get product status
// getCategoryIds(); returns an array of category IDs associated with the product
foreach ($product->getCategoryIds() as $category_id) {
$category = Mage::getModel('catalog/category')->load($category_id);
echo $category->getName();
echo $category->getParentCategory()->getName(); // get parent of category
}
//gets the image url of the product
echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
'catalog/product'.$product->getImage();
echo $product->getSpecialPrice();
echo $product->getProductUrl(); //gets the product url
echo '<br />';
}
And something like this:
$products = Mage::getModel('catalog/product')->getCollection();
foreach($products as $prod) {
$product = Mage::getModel('catalog/product')->load($prod->getId());
}
With this method I get more than 500 but all my product...
Several possibilities here:
1. Some inner limitation, like 500 at all.
2. Some paging limitation. Products per page(in db abstract)
3. Some lazyload limitation.
Perhaps, there is some over problem, but I think this is some inner limit.
Turn off your flat_catalog_product in admin > system > configuration > catalog > catalog. After this you will get a full product collection. Even though this is a workaround, it helped me to achieve what I needed to achieve.
You might be using Flat Catalog Product Structure . This create separate table for each store view.
Use Code below to print sql query . you will see the collection is coming from flat table like
catalog_product_flat_38
echo Mage::getModel('catalog/product')->getCollection()->getSelect();
try using
Mage::app()->setCurrentStore('0');
// same as
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
this hepled me