Magento Design Pattern here
What is the difference between Mage::getSingletone() and Mage::getModel() and Mage::getResourceModel() in Magento
Answer:What is the difference between Mage::getSingletone() and Mage::getModel() and Mage::getResourceModel() 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.
2nd:
The difference between Mage:getSingleton() and Mage::getModel() is that the former one does not create an object if the object for same class is already created, while the later creates new objects every time for the class when it’s called.
Mage::getSingleton() uses the “singleton design pattern” of PHP. If the object is not created, it will create it.
Mage::getSingleton() is mostly used when you want to create an object once, modify it and later fetch from it. Popular example is session, you first create a session object, and then add/remove values from session across different pages, so that it retains your values (e.g. cart values, logged in customer details, etc.) and doesn’t create new session object losing your last changes.
Mage::getModel() is used when you want to have the fresh data from the database. Example is when you want to show records from database.
more
more
Why Magento use EAV database model ?
In EAV database model, data are stored in different smaller tables rather than storing in a single table.
product name is stored in catalog_product_entity_varchar table
product id is stored in catalog_product_entity_int table
product price is stored in catalog_product_entity_decimal table
Magento Use EAV database model for easy upgrade and development as this model gives more flexibility to play with data and attributes.
Q 6. What technology used by Magento?
Ans. Magento uses PHP as a web server scripting
language and the MySQL Database. The data model is based on the
Entity-attribute-value model that stores data objects in tree
structures, thus allowing a change to a data structure without changing
the database definition.
How to improve magento performance?
Or
Q. How to fetch 5 bestsellers products programmatically?
2. Magento’s template system involves a lot of recursive rendering
3. Huge XML trees built up for layout configuration, application configuration settings
How to improve magento performance?
Enabled magento caching
MySQL Query caching
Enable Gzip Compression
Disable any unused modules
Disable the Magento log
Optimise your images
Combine external CSS/JS into one file
Enable Apache KeepAlives:
Make sure your Apache configuratio
has KeepAlives enabled.
Q 8. What is benefit of namespace (package) in magento?
Ans. We can have more than one module with same name but they should be placed in different namespaces. All magento core modules are contained in mage namespace.
core/Mage/Catalog
and all custom modules are placed in
local/CustomModule
Q 9. How to include CMS block in template file(.phtml)?
echo $this->getLayout()->createBlock(‘cms/block’)->setBlockId(‘static_block_id’)->toHTML();
Q 10. How to add an external javascript/css file to Magento?
<action method="addJs"><script>js/yourfile.js</script></action>
<action method="addCss"><stylesheet>css/yourstyle.css</stylesheet></action>
|
<action method="addItem"><type>skin_js</type><name>js/ yourfile.js</name></action>
<action method="addItem"><type>skin_css</type><name>css/yourstyle. css</name></action>
Mage::getResourceModel(‘reports/product_collection’)
->addOrderedQty()
->addAttributeToSelect(‘*’)
->setPage(1, 5)
->load();
Why magento is slow ? Which factors affect performance of magento?
1. EAV structure of magento database, even for retrieving single entity the query becomes very complex .2. Magento’s template system involves a lot of recursive rendering
3. Huge XML trees built up for layout configuration, application configuration settings
How to run custom MySql query in Magento?
$db = Mage::getSingleton('core/resource')->getConnection('core_write');
$result=$db->query("SELECT * FROM PCDSTable");
When will you need to clear cache to see the changes in Magento?
When you have added/modified XML, JS, CSS file(s).
What
are the addAttributeToFilter Conditionals in Magento? - See more at:
http://virallangaliya.blogspot.com/p/magento-interview-questions-and-answers.html#sthash.pTQJ94RY.dpuf
Ans.
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)); - See more at: http://virallangaliya.blogspot.com/p/magento-interview-questions-and-answers.html#sthash.pTQJ94RY.dpuf
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)); - See more at: http://virallangaliya.blogspot.com/p/magento-interview-questions-and-answers.html#sthash.pTQJ94RY.dpuf