Friday, 10 April 2015

How to override Admin controller Action in Magento

>> Hi! friends this example will help you to override admin controller action. I had to replicate admin product edit section as there were two types of products. First one was normal Magento products another was Used products. Client wanted to manage them separately. So, I override admin product controller action. How ?


 First You need to create a new module. Create a xml file within app/etc/modules/JR_Overridecontroller.xml
                        <?xml version="1.0"?>
                        <config>
                            <modules>
                                <AB_Overridecontroller>
                                    <active>true</active>
                                    <codePool>local</codePool>
                                </AB_Overridecontroller>
                            </modules>
                        </config>




 Now make the config.xml within app/code/local/AB/Overridecontroller/etc/config.xml
                         <?xml version="1.0"?>
                        <config>
                            <modules> 
                               <AB_Overridecontroller> 
                                 <version>1.0.0</version> 
                               </AB_Overridecontroller> 
                             </modules>
                         
                            <admin>
                                <routers>
                                    <adminhtml>
                                        <args>
                                            <modules>
                                                <AB_Overridecontroller before="Mage_Adminhtml">AB_Overridecontroller</AB_Overridecontroller>
                                            </modules>
                                        </args>
                                    </adminhtml>
                                </routers>
                            </admin>
                        </config> 



 So, now make the controller file that you need to modify within app/code/local/AB/Overridecontroller/controllers/Catalog/ProductController.php
                   <?php
                        include_once("Mage/Adminhtml/controllers/Catalog/ProductController.php");
                        class Ab_Overridecontroller_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController
                        {
                            public function editAction(){
                               
                                // Here is your overridden controller method.....
                               
                            }
                        }
                    ?> 

Tuesday, 24 February 2015

Wednesday, 26 November 2014

Magento change currency format

/lib/Zend/Locale/Data/en_US.xml



<numbers>
    <currencyFormats>
        <currencyFormatLength>
            <currencyFormat>
                <pattern>¤#,##0.00(USD);(¤#,##0.00(USD))</pattern>
            </currencyFormat>
        </currencyFormatLength>
        <unitPattern count="one">{0} {1}</unitPattern>
        <unitPattern count="other">{0} {1}</unitPattern>
    </currencyFormats>
</numbers>

Monday, 22 September 2014

magento product collection with specific id


magento product collection with specific id

    $productIds = array(1,3,2);
    $products = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToFilter('entity_id', array('in' => $productIds));

Tuesday, 2 September 2014

Magento Product Collection random in limit


 <?php
                            $c=0;
                            $category = Mage::getModel('catalog/category')->load(3);//3 is category id where we assign the products for men
                            $products = Mage::getModel('catalog/product')->getCollection()
                            ->addCategoryFilter($category);
                           
                            $products->addAttributeToSelect('*');
                           
                            $products->getSelect()->order('RAND()');
                            $products->getSelect()->limit(5);//to show only three products randomly
                           
                            $total = $products->count();
                            foreach ($products as $_product) {
                                $c++; ?>
                            <li class="item <?php if($total== $c){ echo "last"; }?>">
                                <a href="<?php echo $_product->getProductUrl() ?>">
                                    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(375,281)?>" alt="" />
                                </a>
                                <?php echo $_product->getName() ?>
                               
                                <div class="price-box">
                                        <span class="regular-price" >
                                            <span class="price"><?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();?> <?php echo number_format($_product->getPrice(),2);?></span>
                                        </span>
                                </div>
                               
                               
                            </li>
                            <?php } ?>

Monday, 25 August 2014

Get product attribute’s select option id/label/value in magento


$productModel = Mage::getModel('catalog/product');
$attr = $productModel->getResource()->getAttribute("color");
 echo $color_id = $attr->getSource()->getOptionId("Red");