Tuesday, 5 May 2015

Custom Layout not loaded

The cause of this issue 

The handle name is always lower-cased by magento which led my failure of loading my layouts.

An efficient way to sort it out

Magento's front-end including handles, layouts, blocks and templates. Among all of them, handles are the only kind of things that will cause failing to load the layouts without any errors or notices. So print the handles in the controller and compare it with the handles defined in the layout XML file.

Here is what I did. First, use the below code to print the handles in the controller:
var_dump($this->getLayout()->getUpdate()->getHandles());

Then, copy the handle name called 'importjson' in my case and search it case-sensitively in the layout file. The result is that 'importjson' couldn't be found in the file that only contains the string of 'importJson'.

To conclude, in Magento we should always pay attention to case-sensitive which could cause numerous issues and cost us a lot time to figure it out.

Sunday, 19 April 2015

Magento userful SQL queries

Get sorted attributes for products

SELECT *
FROM  `eav_attribute` ea
LEFT JOIN  `catalog_eav_attribute` cea ON ea.attribute_id = cea.attribute_id
WHERE ea.`entity_type_id` =4
AND cea.`used_for_sort_by` =1
LIMIT 0 , 30; #the value of entity_type_id might be different, but it can be found in the table named `eav_entity_type`
Note: `eav_attribute` is the table of basic product attributes' settings, while `catalog_eav_attribute` is containing additional or advanced settings for product attributes. Most of the product attributes' settings could be found in these two tables.

Set all simple products invisible by SQL Query

update catalog_product_entity_int set value =1 where attribute_id = 102 and  entity_id in (select entity_id from `catalog_product_entity` where `type_id`= 'simple')

Set the position value for all of the products by SQL Query

update `catalog_category_product` set position=2000 where position!=1000;

Tuesday, 14 April 2015

How to re-install module database

Where in database does magento record the database set-up of the module?

All of the modules and their database set-up versions are recorded in the table named 'core_resource'.

The steps of re-installing a module

1. Disable the module in the app configuration file located in the folder of 'app/etc/modules/' by changing the value of 'active' from true to false.

2. Find the module set-up record in the database table of 'core_resource' and delete the record.

3. Refresh any page of magento site and the module will be newly installed.