You need to follow below points:
1) Disable any unused modules
2) Enable magento caching
3) Disable magento log
4) Combine external js/CSS in one file
5) MySql query caching
6) Image optimization
7) Enable Gzip compression
Megento Solutions is a place where you can get answers to you questions about magento. For beginner its a best place to start with.
You need to follow below points:
1) Disable any unused modules
2) Enable magento caching
3) Disable magento log
4) Combine external js/CSS in one file
5) MySql query caching
6) Image optimization
7) Enable Gzip compression
The main difference is that Mage::getSingleton() does not create new object if the object for same class is already created.
But Mage::getModel() creates new objects for the class everytime when it is called.
Compilation is introduce in Magento 1.6 and above. These versions by default has a compilation tool built into it. The compiler is disabled and your files have not been compiled initally when you configure the megento for first time. Basically the compilation process allows you to compile all the installation files in the Magento to create a single include path. This can increase performance by 30%-50%. This is useful for large website where performance matters, below are the steps to run the compolation process.
Steps for compilation process:
1) Login in to Admin panel.
2) Go to Admin»System»Tools»Compilation
3) Click on 'Run Compilation' this will compile all the installation files.
4) This will take a while and after sucessful compilation it will give status message.
I am working on a project which has different type of products having different product fields, initially i have created all the product under same default Attribute set, but after some time i realize that it will be tough to manage the products so i created different set of attribute sets, since i have already inserted lot of products and at such stage changing each products attribute set is something difficult process.
After doing some research i got a code to add the functionality to change a simple products attribute set directly on the Catalog > Manage Products page.
To achieve this go to file app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php
around line 253 add below line of code in function _prepareMassaction():
$sets = Mage::getResourceModel('eav/entity_attribute_set_collection')
->setEntityTypeFilter(Mage::getModel('catalog/product')
->getResource()->getTypeId())->load()->toOptionHash();
array_unshift($statuses, array('label'=>", 'value'=>"));
$this->getMassactionBlock()->addItem('attribute_set', array(
'label'=> Mage::helper('catalog')->__('Change attribute set'),
'url' => $this->getUrl('*/*/massAttributeSet', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'attribute_set',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('catalog')->__('Attribute Set'),
'values' => $sets
)
)
));
And in this file: app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php (anywhere in the class) add a new function:
public function massAttributeSetAction(){
$productIds = $this->getRequest()->getParam('product');
$storeId = (int)$this->getRequest()->getParam('store', 0);
if(!is_array($productIds)) {
$this->_getSession()->addError($this->__('Please select product(s)'));
} else {
try {
foreach ($productIds as $productId) {
$product = Mage::getSingleton('catalog/product')
->unsetData()
->setStoreId($storeId)
->load($productId)
->setAttributeSetId($this->getRequest()->getParam('attribute_set'))
->setIsMassupdate(true)
->save();
}
Mage::dispatchEvent('catalog_product_massupdate_after', array('products'=>$productIds));
$this->_getSession()->addSuccess($this->__('Total of %d record(s) were successfully updated', count($productIds)));
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
$this->_redirect('*/*/', array('store'=>(int)$this->getRequest()->getParam('store', 0)));
}
Now go to manage product in admin panel now you will be able to select the product and from action dropdown you can select the attribute set.
EAV stands for Entity, Attribute and Value.
Now what is this EAV means? We know that there are several table used in magento lets say we have a table Customer, this table would have several fields like first name, last name, email ID etc. and the values like Ashok, Sharma, ashok@somthing.com respectively. Now lets relate it with this EAV structure, here customer is an entity which has several attribute firstname, lastname and email ID and at last Ashok, sharma ect are values for the attributes.
Lets get into it deeply, in general scenario if we have an ecommerce application it will have several tables lets take an example of product table it will have all the information of a product and there will be another table for categories etc. So what we see is all the information of a product is in one table.
This is what magento doesn't follow. In magento product information is spread into several table. The core table for product is catalog_product_entity, if you see this table it doesn’t have any information of product which you have entered from admin panel except SKU. Now to get all details of product you have to join all attribute to the product entity table, to get product attribute go to the table eav_attribute. If you closely see this table there are lot of attributes so to distinguish product attribute see the field entity_type_id, since each entity has its unique entity_type_id, using this you can get load the attributes of product.
Now you have both entity and attribute its time to get values of the attributes, values are also separated across several table like all the string type values will be stored in catelog_product_varchar table, price will be stored in catelog_product_entity_decimal tables and so on.
So what we come to know from above is that EAV is much more scalable than normal database structure, this mean if we have to add any new field in product we don’t have to change the database table structure, what we do we create an attribute for that and insert values for it.
Hope this will be helpful.
Redirection in Magento Controllers.
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/login'));
How to run an custom query in magento?
$sql = "SELECT * FROM your_table";
$getData = Mage::getSingleton('core/resource') ->getConnection('core_read')->fetchAll($sql);
foreach($getData as $row) {
echo $row['name'] . "\n";
}
// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
// now $write is an instance of Zend_Db_Adapter_Abstract
$write->query("insert into yourtablename values ('val1','val2')");
//or you can do it like this
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$sql = "insert into yourtablename values (?, ?)";
$write->query($sql, array('val1','val2'));
Get Customer Data
$customerData = Mage::helper('customer')->getCustomer()->getData());
Get CMS Page ID
$pageId = Mage::getBlockSingleton('cms/page')->getPage()->getIdentifier();
How to get product attributes?
<?php echo $_product->getResource()->getAttribute('attribute name')->getFrontend()->getValue($_product) ?>
How to show breadcrumbs in magento?
<?php echo $this->getLayout()->getBlock("breadcrumbs")->toHtml(); ?>
How to show Static Blocks?
<?php /* $this->block_code2call, static block code name - the one added under CMS > Static Blocks */ $_block = Mage::getModel('cms/block') ->setStoreId(Mage::app()->getStore()->getId()) ->load($this->getLayout()->createBlock('cms/block')->setBlockId($this->block_code2call)->getBlockId()); ?>
Get current category
Mage::getModel('catalog/layer')->getCurrentCategory()->getName()
<?php $cats = Mage::getModel('catalog/category')->load(2)->getChildren(); $catIds = explode(',',$cats); ?> <ul> <?php foreach($catIds as $catId): ?> <li> <?php $category = Mage::getModel('catalog/category')->load($catId); echo $category->getName(); $subCats = Mage::getModel('catalog/category')->load($category->getId())->getChildren(); $subCatIds = explode(',',$subCats); ?> <?php if(count($subCatIds) > 1):?> <ul> <?php foreach($subCatIds as $subCat) :?> <li> <?php $subCategory = Mage::getModel('catalog/category')->load($subCat); echo $subCategory->getName(); ?> </li> <?php endforeach;?> </ul> <?php endif; ?> </li> <?php endforeach; ?> </ul>