Ask your Question

Write to us !

Ask Question !

Magento Questions

  • 1 What is Magento

    Magento is an open source-ecommerce web application developed by Varien, launched on 31st March 2008. Magento was built by using the part of Zend Framework and using the EAV (entity-attribute-value) database model to save the data. Now Magento is divison of eBay. On June 6 2011 eBay owns 100% of Magento.

  • 2 How to call a static block/cms page in a Phtml file

    $this->getLayout->createBlock('cms/block')->setBlockId('identfierName')->toHtml();

  • 3 How to write custom SQL Queries in Magento

    $resource = Mage::getSingleton('core/resource');

    $readConnection = $resource->getConnection('core_read');

    $query = 'SELECT * FROM catalog_category_product';

    $results = $readConnection->fetchAll($query);

    var_dump($results);.

  • 4 How to use sessions in magneto

    Mage::getSingleton('core/session')->setVariable_name('variable_value');
    Mage::getSingleton('core/session')->getVariable_name();

  • 5 How to make a custom payment method only enable for admin section

    To  enable the payment method only for admin,  we have to set $_canUseInternal  to true and $_canUseCheckout  to false  in model of the custom payment method.

    e.g:

    protected   $_canUseInternal          = true;

    protected   $_canUseCheckout      = false;

  • 6 How to include js files in Magento

    We can add js files through xml files  in Magento .

    For e.g : To add js files on product page we will add below  code in catalog.xml under

     <category_product_view ></catalog_product_view> tag.

     

     <reference name=”head”>

      <action method=”addItem” ><type>js</type><name>jquery-1.6.3.min.js</name></action>

    </reference>

     

  • 7 What is difference between Mage::getSingleton and Mage::getModel

    Mage::getSingleton():  When we declare Mage::getSingleton, it  will  search  for the  object of the same class in the memory .If the object is already created for the same class it return the same object from memory .If there are no existing objects of class in  memory,  it will create new object for the class.

    Mage::getModel: Mage::getModel  each time will create a new objects of  the class.

  • 8 How to improve magento performance?

    We can improve Magento site performance in some easy steps:

    1. Enabled Magento default caching (Cache Management)

    2. MySQL Query caching

    3. Enable Gzip Compression code

    4. Disable all the modules which are useless.

    5. Disable all the Magento logs.

    6. Use optimized images to reduce the load of site.

    7. Merge Css and Javascript.

    8. Enable compilation.

    9. Enable Magento full page caching.

    10. Enable flat catalogs for smaller websites.

  • 9 How many types of products are availabel in Magento?

    In Magento there are 6 types of products:

    1. Simple Product

    2. Grouped Product

    3. Configurable Product

    4. Virtual Product

    5. Bundle Product

    6. Downloadable Product

  • 10 How to enable cron in Magento?

    In Magento we can schedule custom tasks in our  XML configuration, in a similar manner to the UNIX crontab style.
    Like in  app/code/core/Mage/CatalogRule/etc/config.xml:

    <config>
        <crontab>
                <jobs>
                    <catalogrule_apply_all>
                        <schedule><cron_expr>0 1 * * *</cron_expr></schedule>
                        <run><model>catalogrule/observer::dailyCatalogUpdate</model></run>
                    </catalogrule_apply_all>
                </jobs>
        </crontab>

    </config>
    This example will run Mage_CatalogRule_Model_Observer::dailyCatalogUpdate method every day at 01:00am (0 1 * * *).

    To execute  these configured tasks, there is a  cron.php file located in the Magento root and it  need to be run periodically,like every 15 minutes. Basically, these script will check that if it  needs to run any tasks, and if it needs to schedule any future tasks.
    In UNIX/BSD/linux systems we  need to add this line in our crontab:
    */10 * * * *  /bin/sh /absolute/path/to/magento/cron.sh

    If the above will not  work then try :
    0,10,20,30,40,50,60 * * * * /bin/sh /absolute/path/to/magento/cron.sh

  • 11 What is MVC architecture?

    MVC stands for Model-View-Controller. Any application that separates it’s data access, business logicand user interface is called MVC.
     There can be two types of MVC: convention-based and configuration-based.

    Example, CakePHP is convention-based, i.e. you just need to follow the instructions of the core system to get your module ready in just few lines. Magento is configuration-based, i.e. you need to specify each and every thing to your module’s config file in order to get it work. Magento has Controller (for Routing), Block, Model and Template file.

  • 12 What is EAV in magento?

    EAV stands for Entity, Attribute and Value.Entity-Attribute-Value model (EAV), also known as object-attribute-value model.
    The entity represents Magento data items such as products, categories, customers and orders. Each entity (product, category etc) will have it's own entity record in the database
    The attributes represent data items that belong to an entity. For example, the product entity has attributes such as name, price, status and many more.
    The value is the simplest to understand as it is simply a value linked to an attribute.

  • 13 How Magento ORM works?

    ORM stands for "Object Relational Mapping" and it   a programming technique that is  used to convert different types of data to Objects and objects to data.
    In Magento, ORM is represented as Model (based on Zend Framework’s Zend_Db_Adapter), .There are two types of mmodels in magneto Simple and EAV.

    - Simple Models : Simple Or  Regular Models which is nothing but  flat table or our regular table structure.
    EAV (Entity Attribute Value): It is  which is quite complicated and expensive to query.

    All Magento Models interacting with database are inherited from Mage_Core_Model_Abstract class, which is further inherited from Varien_Object.
    Difference between two Models is, Simple Model is inherited from Mage_Core_Model_Resource_Db_Abstract class, while EAV is inherited from Mage_Eav_Model_Entity_Abstract.

    when we want to get some data in Magento, we call it like this:
    Mage::getModel('module/model')->load(1);
    where 1 is the primary key id for some Regular/Simple table, while in EAV so many tables are joined to fetch just single row of data.

  • 14 What permission are required for magento folders and files?

    In Mageto We need to give permission as below:
     For Folders      : 755 permission
     For Files           : 644 permission
     For Media Folder : 777 permission

    From SSH we need to run below commands for  setting magento permissions:
     find . -type f -exec chmod 644 {} ;
     find . -type d -exec chmod 755 {} ;
     chmod 550 pear
     chmod 550 mage #for magento 1.5+

  • 15 How to get product collection of a category in Magento?

    $category_id = 5;

    $products = Mage::getModel('catalog/category')->load($category_id)
     ->getProductCollection()
     ->addAttributeToSelect('*')             // add all attributes - optional
     ->addAttributeToFilter('status', 1)  // enabled
     ->addAttributeToFilter('visibility', 4)  //visibility in catalog,search
     ->setOrder('price', 'ASC');                 //sets the order by price

  • 16 How to get product information from product Id?

    $productid    = 3;
    $_ProductInfo = Mage::getModel('catalog/product')->load($productid);
    $_ProductArr  = $_ProductInfo->getData();

  • 17 How to get total items and total price in shopping cart of magento

    $cartQuantity  =  Mage::getSingleton('checkout/cart')->getItemsCount();

    $TotalPrice      =  Mage::getSingleton('checkout/cart')->getQuote()->getGrandTotal();

     

  • 18 What are handles in magento

     In Magento Handles(layout) are used to maintain the structure of the page and  Layouts are responsible for displaying the block, Layout is built with a small set of XML tags and specify which block will be displayed and where.In ever layout the first level child elements of the node are called layout handles and every page request have several handles. These layouts are called on every page requests.

  • 19 From where we can change the URL of admin in Magento

    To change the admin url of our existing magento store we have two methods:

    1: Go to app/etc/local.xml file and open with an editor and look for the admin node in which you have to  change frontName to your chosen url

    e.g we have chnaged the admin url to adminpanel in below example
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <frontName><![CDATA[adminpanel]]></frontName>
                </args>
            </adminhtml>
        </routers>
    </admin>

    2: Another way  to change the admin URL is from  admin panel of Magento
    GO TO  System -> Configuration->Advanced ->Admin→Admin Base URL→Use Custom Admin URL, set to  'yes' and enter  new admin path in Custom admin path text field and save it.

  • 20 What is virtual Product in Magento

    A Magento virtual product is  used for a virtual (not touchable) item. Just like we have  an insurance, a reservation, an extra product guarantee , some kind of online services etc.
    A virtual product does not allow selecting a shipping method at checkout simply because there’s nothing to ship. While purchasing virtual product we do not have shipping method during checkout process.

  • 21 Define codePool in Magento

    In Magento codePool is a tag which we have to specify while registering a new module in app/etc/modules/Namespace_Module.xml
    In magento extesnion code is maintained in three codepools: ie. core, community and local in app/code/ directory .
    The core codepools is used by Magento itself, the community pool for MagentoConnect extensions ie. 3rd party extensions and the local code pool used  for local modifications like overriding of core files and custom module development

  • 22 When we have to clear/flush the cache to reflect the chnages in Magento

    We need to clear/flush the magento when we have modified/change some code in Js, phtml , xml or css files

  • 23 How we can enable product custom attribute on frontend

    We can make the custom attribute visible on frontend from Admin->Catalog->Manage attributes
    Select the custom attribute and in Manage Attributes section, select visible on Product View Page and used in Product listing to 'Yes'.

  • 24 Is it mandatory to give Namespace while creating custom module in Magento

    No, we do not need to give Namespace while creating custom module in Magento.

  • 25 Can we have more than one Grid in a module

    Yes, we can make more than one Grid in a module

  • 26 How will you override Block/Model/controllers in Magento

    Coming Soon..

  • 27 What is differnce between Catalog price Rules and Shopping cart Price Rules

    Catalog price rules are applied to products before they are added to cart , whereas Shopping cart rules are applied on the shopping cart

  • 28 How to get simple products of a configurable product.

    $productId = 7; //product id of configurable product

    $_Product         = Mage::getModel('catalog/product')->load($productId);
    $simpleProducts   = Mage::getModel('catalog/product_type_configurable')
                         ->getUsedProducts(null,$_product);
       

              foreach(simpleProducts  as $simple_product){

                 echo $simple_product->getId();   // Print Id's of all simple products
               }
                  

     

  • 29 How to convert price from default currency to some other currency.

    To convert the price to some other currency we need to select that currency in allowed currency and import currency rates from System->Manage currency ->Rates .
    The synatx for currency conversion is currencyConvert($amount, $from, $to=null)
    e.g:
     Suppose we need convert Price from GBP(British Sterling Pound) to INR(Indian    currency) then we need to write below code .
     

    $convertedPrice = Mage::helper('directory')->currencyConvert($price, GBP, INR);

  • 30 How to Format price in Magento

    We get the price in integer format  when fetched from product data. So to display price with currency we use :

    $Price = Mage::helper('core')->currency($_finalPrice,true,false);

  • 31 How to get the current url in Magento

    We can get the current url in magento by :

    $url  = $this->helper('core/url')->getCurrentUrl();

  • 32 Explain design pattern in Magento

    There are 12 design patterns uses in Magento, these are

    1. Model View Controller Pattern
    2. Front Controller Pattern
    3. Factory Pattern
    4. Singleton Pattern
    5. Registry Pattern
    6. Prototype Pattern
    7. Object Pool Pattern
    8. Iterator Pattern
    9. Lazy Loading Pattern
    10. Service Locator Pattern
    11. Module Pattern
    12. Observer Pattern

  • 33 What is Singleton Desing Pattern in Magento

    Mage::getSingleton() is used  to retrieve an instance of a class. Before returning the instance of class it checks the intrenal registry to check whether this class is already instantiated or not, if not then it will create a new object of the class.

  • 34 How to log the collection SQL query in Magento

    If our collection is

    $collection = Mage::getModel('catalog/product')->getCollection();

    then we can log the collection SQl query by  using
    $collection->getSelect()->__toString();
     OR
     $collection->printLogQuery(true);

  • 35 How to enable maintenance mode of Magento website

    We can enable the maintenance mode by creating a file name maintenance.flag and place it on

    magento root folder .

  • 36 Explain Event and Oberver working concept in magento

    Magento works on some design patterns. Using observers on events is one of the design pattern used in magento.A design pattern is reusable solution to a commonly occurring problem.

    When we use this pattern what actually happens is an event is gets dispatched and an observer who is observing that event is get executed.

    This is something useful when working with modules that may not provide services to specific elements that are not available.

    To separate your custom code from the core code we use event driven programming where an event is fired and an observer is listening for specific events and executing certain logics on specific event.

  • 37 Explain magento design patterns

     Coming Soon..

  • 38 What are different Prices types in magento

     Coming Soon..

  • 39 How many database tables will Magento create when registering a new EAV module

     Magento will create 6 tables when we add a  new EAV module in Magento.Eav module cretaes below tables

     -module Table        :- This is the main entity table 
     -module_datetime :- This is to hold the attribute data of DATETIME data type
     -module_decimal   :-This is to hold the attribute data of Float data type eg. Price
     -module_int            :- This is to hold the attribute data of Integer data type eg. quantity
     -module_text          :- This is to hold the attribute data of long text data type e.g Description
     -module_varchar   ;- This is to hold the attribute alpahnumeric data e.g name and address
  • 40 What is Difference between EAV Model and flat Model in Magento

    EAV is Entity Attribute Value database model, where the  data is in normalized form. Each column data value is stored in their respective data type table.
    Example, for a product, product ID is stored in catalog_product_entity_int table, product name in catalog_product_entity_varchar, product price in catalog_product_entity_decimal, product created date in catalog_product_entity_datetime and product description in catalog_product_entity_text table. EAV has  complex structure as it joins 5 to 6 tables even if we want to get just one product’s information.

    Flat model uses just one table, and it is  normalized and uses more database space. It clears the EAV overhead, but not good for dynamic requirements where you may have to add more columns in database table in future. It has better performance than the EAV model.

  • 41 In magento where we will write our Module buisness logic

    We write all buisness logic inside Model.

  • 42 How many types of sessions in Magento? Explain them.

    In magento we have differnt type of sessions e.g. customer/session, checkout/session, core/session.
    Customer session stores all the data related to customer , Checkout session used to store the data related to order but all these actully stored in
    one session . Like Customer session stored in $_SESSION['customer']['firstname'] and checkout session $_SESSION['checkout'], the reason behind using
    seperate session is that sometimes we need to clear only a particular session data, e.g after placing order in Magento we need to clear the
    checkout sesion but not customer session.Thus we just flush $_SESSION['checkout'] and rest of session data still remain in the site.

  • 43 What Magento Compilation feature does.

    The Compilation feature of Magento will allow you to compile all files of a Magento installation in order to create a single include path to increase

    performance. The performance increase is between 25%-50% on page loads. In order to use this tool, the directory ‘includes’ and the file

    ‘includes/config.php’ must both be writable and Magento compilation is an important aspect in increasing the Magento Site speed.
    After compilation if we request the data it will directly go to the certain path instead of renderring from files to files.

    But we need to confirm that  before we make any changes to our Magento installation we should always disable compilation.
     Once the changes are made, run the compilation  process, and then enable it from Magento Backend.
     

  • 44 Can we create our own codePool in Magento

     Yes, we can create our own code pool under app/code directory.

  • 45 What is advantage and disadvantages of EAV Model in Magento.

     Advantage:

     
     EAv database model are flexible and we do not need to change the database structure 
     for adding new attributes .
     
    e.g   if we have different types of products like computer,clothing and phone on the same store then we have to create
            a large number of columns for storing the attributes value like price,memory, ram etc for computer categories. Fabric size
            color etc for clothing categories. Display,battery,camera etc for Phone categories. But in EAv model all the attributes stores as value 
           and we do not need to add large number of columns to add attributes.
     
    Disadvantage:
     - EAV model is inefficient and for returning 20 columns then EAv model consist of 20 self joins and take a lot of 
       resource to fetch the result.
    - No mechanism for relationships between subtypes .
  • 46 What is order states and Order status in Magento

      Order states determine that in which state the order is.These are fixed states and Magento uses these states internally

      to main various order states.
      Some of the fixed states are New, Processing,Pending payment etc.
     
      Order status give more information on states.A status can have only one state but a state can belong to multiple status.
      For example, the pending_review state has both the fraud and payment_review statuses, We can add more order status from
      Admin->System -> Manage Order Statuses.
      Order Status are also defined in sales/config.xml in global -> sales -> order -> states,
      we can also add new order states from here and it will save in ‘sales_order_status’ table.
  • 47 What are Fieldsets in Magento.

     <fieldsets> tag is defined in Mage/Sales/etc/config.xml, <fieldsets> tag define which data is copied across 

     
      orders and quotes when they are converted. For ex. When creating order from a quote shipping info,payment info 
      customer info,items need to be move from quote to order.
     
    e.g 
            <fieldsets>
                <sales_copy_order>
                    <customer_email>
                        <to_edit>*</to_edit>
                    </customer_email>
                    <customer_group_id>
                        <to_edit>*</to_edit>
                    </customer_group_id>
                </sales_copy_order>
          </fieldsets>