Showing posts with label Magento Interview Questions with Answers. Show all posts
Showing posts with label Magento Interview Questions with Answers. Show all posts

Explain different types of sessions in Magento (e.g. customer/session, checkout/session, core/session) and the reason why you store data in different session types?

Customer sessions stores data related to customer, checkout session stores data related to quote and order. They are actuall under one session in an array. So firstname in customer/session will be $_SESSION['customer']['firstname'] and cart items count in checkout/session will be $_SESSION['checkout']['items_count']. The reason Magento uses session types separately is because once the order gets placed, the checkout session data information should get flushed which can be easily done by just unsetting $_SESSION['checkout'] session variable. So that the session is not cleared, just session data containing checkout information is cleared and rest all the session types are still intact.

Where will you write your module’s business logic in Magento?

inside Model

How many database tables will Magento create when you make a new EAV module?

Magento creates 6 tables when you create new EAV module. Tables: module, module_datetime, module_decimal, module_int, module_text and module_varchar. one is the main entity table, and rest 5 tables which holds attribute’s data in different data types. So that integer values will go to module_int table, price values to module_decimal, etc.

What are “magic methods” in Magento?

Magento uses __call(), __get(), __set(), __uns(), __has(), __isset(), __toString(), __construct(), etc. magic methods. You can find more details inside class Varien_Object
For more information about magic methods: http://php.net/manual/en/language.oop5.magic.php

How will you enable maintenance mode of your Magento website?

If you want your Magento website to show in maintenance mode, you will have to do two things.

1. Create a file name maintenance.flag in your magento root directory. Contents under this file doesn’t matter, you can keep it empty.

2. Change the maintenance file (located in magento root -> errors -> default directory) to show proper message when user visits your website.  

How will you join flat table and EAV table in Magento?

Joining tables in Magento when it comes to EAV with Flat table is quite complicated. Consider you want to join sales_flat_order table with customer EAV tables to get Customer’s firstname and lastname, it becomes difficult as customer’s name comes from customer_entity_varchar table.

Below code will join sales order flat table with customer EAV to get customer’s full name in the collection along with all the order details.
 

$coll = Mage::getModel('sales/order')->getCollection();

$fn = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'firstname');
$ln = Mage::getModel('eav/entity_attribute')->loadByCode('1', 'lastname');

$coll->getSelect()
    ->join(array('ce1' => 'customer_entity_varchar'), 'ce1.entity_id=main_table.customer_id', array('firstname' => 'value'))
    ->where('ce1.attribute_id='.$fn->getAttributeId())
    ->join(array('ce2' => 'customer_entity_varchar'), 'ce2.entity_id=main_table.customer_id', array('lastname' => 'value'))
    ->where('ce2.attribute_id='.$ln->getAttributeId())
    ->columns(new Zend_Db_Expr("CONCAT(`ce1`.`value`, ' ',`ce2`.`value`) AS fullname"));

print_r($coll->getData());

Can you have more than one Grid in a module?

YES

How will you add/remove content from core’s system.xml file?

<config>
    <sections>
        <catalog>
            <groups>
                <frontend>
                    <label>Overriding Catalog Frontend in system config</label>
                </frontend>
            </groups>
        </catalog>
    </sections>
</config>

<config>
   <sections>
        <payment>
            <groups>
                <cashondelivery>
                    <fields>
                        <!--changing cashondelivery payment method settings-->
                    </fields>
                </cashondelivery>
            </groups>
         </payment>
    </sections>
</config>

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

No

Difference between EAV and flat model

EAV is entity attribute value database model, where data is fully 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 is complex as it joins 5-6 tables even if you want to get just one product’s details. Columns are called attributes in EAV.

Flat model uses just one table, so it’s not 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’s good when comes to performance, as it will only require one query to load whole product instead of joining 5-6 tables to get just one product’s details. Columns are called fields in flat model.

How to change Currency in INR in magento?

In Magento, Currency change is very easy just we need to follow below step: 

1. From the Admin panel, select System > Configuration.

2. From the Configuration panel on the left, under General, select the Currency Setup tab.

Click to expand the Currency Options section. Then, do the following:

1. In the Base Currency list, select the primary currency that is used for store transactions.

2. In the Default Display Currency list, select the primary currency that is used to display pricing in your store.

3. In the Allowed Currencies list, select all currencies that are accepted as payment by your store. When finished, click the Save Config button.

To customize currency symbols:

Currency symbols appear in the Admin panel of your store, and are also used throughout your storefront in orders, customer checkout, and so on.

1. From the Admin panel, select System > Manage Currency > Symbols.

2. Each enabled currency for your store appears in the Currency list.

3. Enter a custom symbol to use for each currency, or select the standard symbol selecting the Use Standard checkbox to the right of each currency. When finished, click the Save Currency Symbols button.

What are the add Attribute To Filter Conditionals in Magento?

In Magento we can use addAttributeToFilter Conditions same as WHERE in SQL
Below are the all condtions

Equals: eq
$_products->addAttributeToFilter('status', array('eq' => 1));

Not Equals - neq
$_products->addAttributeToFilter('sku', array('neq' => 'test-product'));

Like - like
$_products->addAttributeToFilter('sku', array('like' => 'UX%'));

One thing to note about like is that you can include SQL wildcard characters such as the percent sign.

Not Like - nlike
$_products->addAttributeToFilter('sku', array('nlike' => 'err-prod%'));

In - in
$_products->addAttributeToFilter('id', array('in' => array(1,4,98)));

When using in, the value parameter accepts an array of values.

Not In - nin
$_products->addAttributeToFilter('id', array('nin' => array(1,4,98)));

NULL - null
$_products->addAttributeToFilter('description', 'null');

Not NULL - notnull
$_products->addAttributeToFilter('description', 'notnull');

Greater Than - gt
$_products->addAttributeToFilter('id', array('gt' => 5));

Less Than - lt
$_products->addAttributeToFilter('id', array('lt' => 5));

Greater Than or Equals To- gteq
$_products->addAttributeToFilter('id', array('gteq' => 5));

Less Than or Equals To - lteq
$_products->addAttributeToFilter('id', array('lteq' => 5));

Difference between Final Class and Abstract Class

Final Class: A Class which Can't be inherited by other class, that class is called final class. You all knows that final class is inbuilt in java. But in C++ you have to create final class.Two types of Final class, you can create . One who want to create object of final class on Heap and other who wants to create object of Final class on stack.

1.It makes use of private constructor, virtual inheritance and friend class.

2.In place of priavte constructor, use private Destructor. Because Constructor can be overloaded and Destructor can'nt be overloaded.

Difference between javascript and jquery?

Javascript: Javascript is Client side scripting/programming language.

Jquery: Jquery is library buit in javascript.

What is Module conflict?

We install one module(Extension Conflict) to findout that Class which is Conflict. We have to written only one config file for both module.

What is the difference between Mage::getSingletone() and Mage::getModel() in Magento?

Mage::getSingletone() always finds for an existing object if not then create that a new object but Mage::getModel() always creates a new object.

How to fetch 5 bestsellers products programmatically?

<!--?php
Mage::getResourceModel(‘reports/product_collection’)--->addOrderedQty()
->addAttributeToSelect(‘*’)->setPage(1, 5)->load();
?>

How to create magento custom module?

Steps to create custom magento module: 

Namespace : Viral

Module Name : Mymodule

1. Create directory Mymodule in app/code/local/Viral

2. Create Block, controllers, etc, Module directories. Create controller, block and module file as required.

3. Create module configuration file (app/code/local/Viral/Mymodule/etc/config.xml).

4. Create xml file (app/etc/modules/Viral_ Mymodule.xml)to enable/disable module and tell magento system from which code pool that module will be taken.

How to set different themes for logged in users?

if(Mage::getSingleton('customer/session')->isLoggedIn()):
Mage::getDesign()->setPackageName('package_name')->setTheme('themename');
endif;

How to get the Total Price of items currently in the Cart?

<!--?php helper(‘checkout’)--->formatPrice(Mage::getSingleton(‘checkout/cart’)->getQuote()->getGrandTot