Tag Archives: Magento tutorials online
Magento Load product by id
Magento Load product by id : You Can Load Magento product by Id As Below
Magento Load product by id Syntax
$product = Mage::getModel('catalog/product')->load($id);
Which will load product by id passed.
Magento create custom log file
Magento create custom log file : Magento provide to create logs functionality. Default logs are stored in system.log file which is created in folder var/log/ststem.log. Magento’s defualt warnings and error messages are stored in the same file. We are going to explain the both default and custom error log messages. You can create log in magento simply as below :
Magento create custom log file Example
Magento Create Custom log file Example
Mage::log('Your Error Message here.....', null, 'logfilename.log'); |
The log method accepts three parameters as input parameter to create custom log file. First parameter is message to be logged, second parameter is null and third is file name you want to create and log the message. This file will be create in the same folder system.log file exists.
Magento Default Log File – system.log
Let’s have look over magento default logging file system.log. All the logs created by system are stored in this file.
Magento Create Log in – system.log
Here is simple syntax you can use to create your log in system.log file-
Magento system.log file Example
Mage::log('Your Data here....'); |
This will append the above message in magento system.log file.
Magento call model method in controller
Magento call model method in controller
Magento call model method in controller
You can call the model method in controller simply as
Mage::getModel('module_name/modelname')->yourMethodName();
Magento new column added not saving value in table
Magento new column added not saving value in table.
Magento new column added not saving value in table
Quick Fix : Clear Cache – clear the /var/cache folder
This issue basically occurs when you add a new column and try to save the value in that column. The Value is not saved in table column because the tables are cached in magento even if you have disabled the magento cache because of zend framework table cache.
Magento Load template in template
Magento Load template in template : You can load template in template directly
as following.
Magento Load template in template
Mage::app()->getLayout() ->createBlock('core/template') ->setData('yourData',$yourData) ->setTemplate('yourTemplatePath/yourTemplateName.pthml')->toHtml();
You can get the data passed to your template “yourTemplateName.pthml” data as below:
$data = $this->getData('yourData');
Magento get config variable value
Magento get config variable value: Magento config variable values can be get as below.
Magento get config variable value Syntax
Use the following syntax to get magento admin configuration value.
$configValue = Mage::getStoreConfig('section_name/group_name/field_name');
or
$configValue = Mage::getStoreConfig('section_name/group_name/field_name',Mage::app()->getStore());
This will fetch the current store’s config value.
Note : section_name,group_name and field_name are names defined in your config.xml
Magento get current category name
Magento get current category name: You can get the category id and category name on product detail page as below
Magento get current category name Example
Use the following code to get current category detail.
getCurrentCategory()->getId(); $catName = Mage::getModel('catalog/layer')->getCurrentCategory()->getName(); ?>
Which will give the category name and id.
Magento count cart items
Magento count cart items : You Can count carts item from the current quote.
Magento count cart items Syntax
$count = Mage::helper('checkout/cart')->getCart()->getItemsCount();
Which will the total no of items in the cart.
If Want to process all items
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
Magento join select multiple columns
Magento join select multiple columns : You can select multiple columns as below.
Example of magento join select multiple columns
You can select multiple columns in magento joins as below:
//load collection $collection = Mage::getModel('module/model_name')->getCollection(); $collection->getSelect()->join('table2'=>'table2_to_be_joined','main_table.table_field ='table2.table2_field',array('table2.field_name1','table2.field_name2','main_table.field_name1','main_table.field_name2','main_table.field_name3'));
You can use table alias to select columns as above.