Tag Archives: Magento tutorials online

Magento get quote id from quote


Magento get quote id from quote : If you are working with magento quotes and want quote id you can use following method to get the magento quote id.


This is how you can get quote id

	
$quoteId = Mage::getSingleton('adminhtml/session_quote')->getQuote()->getId();

Which will return the quote id from current Admin quote session.

Magento Load Category Product Collection


Magento Load Category Product Collection: Category Product Collection in magento is loaded using the model catalog/product_collection. It requires the category as resource to load the products.


Syntax for Magento Load Category Product Collection

Here is the syntax to load the magento category products.

$layer = Mage::getSingleton('catalog/layer');
$Category = $layer->getCurrentCategory();
$currentCatId= $Category->getId(); //will give current categeory id
$category = Mage::getModel('catalog/category')->load($categoryId);

$collection = Mage::getResourceModel('catalog/product_collection')
                                 ->addCategoryFilter($category);
foreach ($collection as $product){
   echo $product->getId().'
'; echo $product->getName().'
'; }

The above collection will return the magento products in the selected category. You can use the above code in the phtml you want to display. You can add your own filter to load the products.

Get all files executed in magento


Get all files executed in magento : If You are debugging and wants to get all files executed during the page load or on any event you can use the following method.


How can you code & Get all files executed in Magento

The following function will return the include, include_once, require or require_once files. If you are debugging any framework it will help you a lot to get the files and flow.

$includedFiles = get_included_files();

foreach ($includedFiles as $filename) {
    echo "$filename\n\n";
}

Which will generate the following query as below.

//Select count(*) from users where id=’100′;

where $id = 5;

Magento Get Latest Order created


Magento Get Latest Order created : You can get latest order created in magento.


Magento Get Latest Order created Syntax

You can get latest order as below :


$order = Mage::getModel('sales/order')->getCollection()
		                      ->setOrder('created_at','DESC')
				      ->setPageSize(1)
				      ->setCurPage(1)
				      ->getFirstItem();

Which will return the latest order created

Magento get admin quote cart shipping cost


Magento get admin quote cart shipping cost


Magento get admin quote cart shipping cost Syntax

You can get Shipping cost applied on quote cart as below :


Mage::getSingleton('adminhtml/session_quote')->getQuote()->getShippingAddress()->getShippingAmount();

Which will return shipping amount applied on quote.

Magento get cart shipping cost


Magento get cart shipping cost


Magento get cart shipping cost Syntax

You can get Shipping cost applied on cart as below :

Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingAmount();

$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); 

// will return total object

Magento collection get last item


Magento collection get last item : You can get magento collection last item as below.

For Magento 2 Last Item Read – Magento 2 get Last Item in Collection


Magento collection get last item Syntax

$collection = Mage::getModel('module_name/model_name')
->getCollection()
->setOrder('Id Desc')
->setPageSize('1');

The above filter will select last record from the collection.

Magento collection set page size


Magento collection set page size : You can set page size in magento as below.


Magento collection set page size Syntax

$collection = Mage::getModel('module_name/model_name')
->getCollection()
->setPageSize('1');

The above filter will select only one record from the collection.

Magento set order in collection


Magento set order in collection : You can set order in magento table as below.


Magento set order in collection Syntax

$collection = Mage::getModel('module_name/model_name')
->getCollection()
->setOrder('id DESC');

The above filter will sort magento collection by id in descending order.