Monday, April 29, 2013

Import dump data to mysql through command promt

>> Mysql import from CSV :

      > mysqlimport --fields-terminated-by=, --fields-enclosed-by="\"" --lines-terminated-by="\r\n" DBNAME FILEPATH -u USERNAME -p --columns=code,city,state,county

Thursday, April 18, 2013

How to get all subcategories of a category in Magento

 >> Suppose you need to get the list of all subcategory of "cat1" (id : 10)

       $category = Mage::getModel('catalog/category')->load(10); // load the parent category
    There are many way to do it. I'll show you the two :
    1. $subcatCollection = Mage::getModel('catalog/category')->getCollection()
                ->addAttributeToFilter('parent_id',array('eq' => 10));
       // This will return the subcategory collection.
   2. $subcategories = $category->getChildren();
       // This will return all subcategory id with comma separator like : 11,12,13

Thursday, April 11, 2013

How to show review block on product page in Magento

>> To get the review block in product details page. You need to follow the two steps:

       1) Add this code to catalog.xml like:
            <catalog_product_view translate="label">
                <reference name="content">
                    <block type="catalog/product_view" name="" template="catalog/product/view.phtml">
                            <!--You need to copy below section -->
                        <block type="page/html_pager" name="product_review_list.toolbar"/>
                        <block type="core/template" name="product_review_list.count" template="review/product/view/count.phtml" />
                        <block type="review/product_view_list" name="" as="product_review_data" template="review/product/view/list.phtml">
                            <block type="review/form" name="" as="review_form">
                                <block type="page/html_wrapper" name="" as="form_fields_before" translate="label">
                                    <label>Review Form Fields Before</label>
                                    <action method="setMayBeInvisible"><value>1</value></action>
                            <!--        END            -->

       2) Now go to the view.phtml page. here you need to add this code:
               <?php echo $this->getChildHtml('product_review_data') ?>
            you are done> :)
>> To change the default number of reviews shown per page, follow this:

        By default it shows 10, 20, 50. Go to app/code/core/Mage/Page/Block/Html/Pager.php
        there you can find the line 
            <?php protected $_availableLimit = array(10=>10,20=>20,50=>50);  ?>
        change it as you want        
            <?php protected $_availableLimit = array(5=>5,10=>10,50=>50);  ?>
   Note*: You should do this step either by overriding the block OR copy the same file in the local directory like:  app/code/local/Mage/Page/Block/Html/Pager.php