Category Archives: Magento
Magento save data in sales_flat_quote_item table
Magento save data in sales_flat_quote_item table : You can save/update data in magento sales_flat_quote_item table as easily using the model sales/quote_item.
Magento save data in sales_flat_quote_item table
Below is syntax to update data in magento sales_flat_quote_item table
Syntax
$quoteItem = Mage::getModel('sales/quote_item')->load(quote_item_id); $quoteItem->setColumnName(value); $quoteItem->save();
Where quote_item_id is quote item id (primary key in sales_flat_quote_item table) used to load the row you want to update.
ColumnName : Name of column you want to update.
Value : Value You want to update.
Example
$quoteItem = Mage::getModel('sales/quote_item')->load($quoteItemId); $quoteItem->setCustomPrice('10.99'); $quoteItem->save();
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.
Magento get Product Collection
Magento get Product Collection: Magento product collection is loaded using the model Mage::getModel(‘catalog/product’). You can use this model to get production collection based on your requirement. You can add your filters to the collection if you want data to be filtered based on some criteria.
Syntax for Magento get Product Collection
Here is the syntax to load the magento products in descending order they are created.
$collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSort('created_at', 'DESC') ->load(); foreach ($collection as $product){ echo $product->getId().'
'; echo $product->getName().'
'; }
The above collection will return the magento products.
Magento get Product Collection : Only 10 Products
If You Want to load magento’s top last 10 created products you can load the model as below.
$collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSort('created_at', 'DESC') >setPageSize(10); ->load(); foreach ($collection as $product){ echo $product->getId().'
'; echo $product->getName().'
'; }
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.