Magento Certification Preparation / Interview Questions Answers
Hi guys, here is the stuff I collected and created from myriad number of websites/blogs/forums/ magento source codebase during my Magento certification preparation. I have put all the things I found and studied during my preparation in one place, so that other developers who are preparing for the exam can benefit from it.
Credits to all who have contributed these things over the web from where I copied for study purpose. Few credits to me as well as I also have contributed many things in it š This may contain errors and wrong information and I don’t guarantee it to be completely correct. But this should be a good resource if you want a heads up! Please be aware that you need to go through the study guide and fundamental videos yourself in order to pass this exam.
If you are here to prepare for Interview, then I would recommend you to also go through these links:
Magento Interview questions and answers
Magento Advanced Interview questions/
The below stuff alone will definitely not going to help you much in passing the exam. Not to mention, these resource can also be used for Magento interview preparation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 | Magento supports and loads translations in the following order:
- Module Translation CSV in /app/locale
- Theme Translation CSV in /app/design/<area>/<package>/<theme>/locale (theme folder translate)
- DB Translation Database (table core_translate)
-------
How many options exist to add a custom translation for any given string?
As mentioned above, there are three options in Magento to add a custom translation to a text string: module translation, theme translation and inline translation.
1. Module translation
Module translations are stored in app/locale/languagecode_COUNTRYCODE/ folder in form of csv files, named as Namespace_Modulename.csv All string in extensions that are inside __() method can be translated this way
2. Theme translation
Strings can be translated inside your theme, for that you just need to set locale via Magento admin area, then create translate.csv in app/design/frontend/<package>/<theme>/locale/ languagecode_COUNTRYCODE and put your translated strings inside this CSV
āMy Cartā,āMy Basketā
āMy Accountā,āAccountā
3. Inline translation
To enable inline translation you need to log into Admin panel and go to System -> Configuration -> Developer.
You need to select Store view from scope select and enable inline translation for this desired store view there.
-------
Magento uses the Front Controller pattern for the following purposes:
Receiving and processing browser data, transferring it to other system elements;
Defining controller and proper action to perform using routes;
Displaying browser-requested data using blocks, templates and model data.
-------
(Front Controller) Routes processing order
- admin
- standard
- cms
- default
-------
Mage::getModel() => getModelInstance() => getModelClassName() => new ClassNameInitializes...
Mage :: getModel($modelClass, $arguments){
Mage_Core_Model_Config :: getModelInstance($modelClass, $arguments){
$className = $this->getModelClassName($modelClass){
return $this->getGroupedClassName('model', $modelClass)
}
...
$obj = new $className($arguments);
}
}
-------
Front Controller events... Mage_Core_Controller_Varien_Front
controller_front_init_before
controller_front_init_routers
controller_front_send_response_before
controller_front_send_response_after
-------
Mage_Core_Controller_Varien_Action fires events...
controller_action_layout_load_before
controller_action_layout_generate_xml_before
controller_action_layout_generate_blocks_before
controller_action_layout_generate_blocks_after
controller_action_layout_render_before
controller_action_layout_render_before_{getFullActionName}
controller_action_predispatch
controller_action_predispatch_{getRouteName}
controller_action_predispatch_{getFullActionName}
controller_action_postdispatch
controller_action_postdispatch_{getFullActionName}
controller_action_postdispatch_{getRouteName}
controller_action_noroute
controller_action_nocookies
-------
http://blog.belvg.com/magento-front-controller-pattern.html
http://magebase.com/magento-tutorials/digging-deeper-into-magentos-layout-xml-part-2/
-------
The layout initialization happens as follows:
1. Instances of the Layout and Layout Update are created.
2. Layout handles are added according to the $handles argument if passed.
3. Store layout handle STORE_[store_code] is added to the Layout Update Instance. For example, if code of current store is en, then layout handle STORE_en is added.
4. Theme layout handle THEME_[area]_[package]_[layout_theme] is added to the Layout Update Instance. For example, if the page rendered is for the frontend area, the current theme package name is magebase and theme name for layout is modern, then the layout handle THEME_frontend_magebase_modern is added.
5. Action layout handle is added to the Layout Update Instance. For example, if the page rendered is a category detail page, then Magento is executing catalog moduleās category controllerās view action. So it will add an action handle catalog_category_view.
6. All Layout XML files defined for all active modules are loaded
7. If a layout file named local.xml exists in the current themeās layout folder, it is loaded last
8. Layout updates of all added layout handles from the loaded layout XML are merged
9. Layout updates of all added layout handles from the database are merged
10. If the $generateXML argument of loadLayout() method is passed as false, the initialization is finished.
11. The layout update data is refined by removing all blocks and block references defined with the remove tag. (As discussed in Part 1)
12. If $generateBlocks argument is passed as false, the initialization is finished.
13. The instances of block classes are created according to the block definitions in the Layout XML
14. The methods are called with specified arguments on the blocks where action tags are defined. (As discussed in Part 1)
-------
A layout should have at least one *output* block. Normally, the root block is the only output block in a layout but there can be multiple output blocks for a single page. In that case, the output of each output block is merged and returned in the response.
The *non-output* blocks are child blocks of output blocks and are normally rendered with the getChildHtml() method. There are also two other methods: getChildChildHtml() and getBlockHtml() also used to render non-output blocks.
-------
Blocks can be instantiated via layout xml (<block type=āgroupName/setupāā¦), createBlock(), addBlock(), and getBlock() methods, located in Mage_Core_Model_Layout
-------
After initialization of config file for crontab section Magento finally invokes Mage_Cron_Model_Observer->dipatch() that does the following:
Process scheduled cron queue: Magento reads the cron schedule table for jobs that need to be executed this very second and jobs that should have already been executed, i.e. with timestamps in the past, that havenāt expired. The expiry limit is also a parameter, configurable in the admin panel. After all the work, dispatch method calls two generate() and cleanup() methods
Generate tasks schedule: Mage_Cron_Model_Observer->generate(), this method searches final configuration file for content of <crontab> nodes ($config = Mage::getConfig()->getNode(ācrontab/jobsā); ), reading <schedule><cron_expr> elements to find out when and how often they need to be executed and pulls this data into the cron_schedule table.
Cleanup: Mage_Cron_Model_Observer->cleanup(), this method deletes completed (with āsuccessā status) or missed ($time < $now ā $scheduleLifetime, where $scheduleLifetime are set in Magento admin area) jobs from cron_schedule DB table.
-------
1. All .xml files are collected into one big simpleXmlElement object
2. First, data is loaded from app/etc/*.xml and then from app/etc/modules/*.xml. Based on the module loaded information, config.xml is loaded from the etc directory of the module. If we load backend to check ACL and build menu elements, adminhtml.xml and system.xml are loaded as well. Configuration data from the database is the last one to load.
3. Any parameters, except the ones stored in app/etc/local.xml, can be overridden in config.xml of a custom module.
P.S. Even though Magento provides us with such convenient methods as Mage:: getStoreConfig() and Mage:: getStoreConfigFlag(), we can reach any element of the configuration tree with the help of Mage::getConfig()->getNode($path, $scope, $scopeCode);
-------
Difference: A Website, a Store and a Store View.
Each websites has its unique customer and order base, base currency and prices.
Stores can be used to define for example different (looking) stores with the same information.
Store Views are mostly used to handle different languages on your website. You will typically have one Store View per language.
----------
Setting And Getting Cookies
To set cookies:
Mage::getModel('core/cookie')->set('cookie_name', 'cookie_value', 0); # session cookie
Mage::getModel('core/cookie')->set('cookie_name', 'cookie_value', 60); #lasts 60 seconds
To get cookies:
Mage::getModel('core/cookie')->get('made_productalerts_stock');
----------
Sending Transactional E-Mails
$email = Mage::getModel('core/email_template');
$email->sendTransactional(
'some_email_template', // template
array('name' => 'Your Company', 'email' => 'contact@yourcompany.com'), // sender details
'joe@joebloggs.com', // recipient email
'Joe Bloggs', // recipient name
array('customerName' => 'Joe Bloggs'), // merge vars
Mage::app()->getStore()->getStoreId() // store id
);
----------
Resizing A Product Image
$helper = Mage::helper('catalog/image');
$helper->init($product, 'image');
$helper->resize(216, 161);
----------
Adding A Layout Handle From A Controller
If you really need to add a handle to a controller, you need to replace the call to $this->loadLayout() with:
$update = $this->getLayout()->getUpdate();
$update->addHandle('default');
$this->addActionLayoutHandles();
$update->addHandle('your_handle');
$this->loadLayoutUpdates();
$this->generateLayoutXml();
$this->generateLayoutBlocks();
$this->_isLayoutLoaded = true;
------------
Config URL Rewrite Definition
xpath: global/rewrite/module/from&to
<config>
<global>
<rewrite>
<namespace_module>
<from><![CDATA[#^/some/regex/([a-z]*/?$#]]></from>
<to><![CDATA[/frontname/whatever/whatever/blah/$1]]></to>
</namespace_module>
</rewrite>
</global>
</config>
----------
Config Model Rewrite Definition
xpath: global/models/catalog/rewrite/product
<config>
<global>
<models>
<catalog>
<rewrite>
<product>Namespace_Module_Catalog_Product</product>
</rewrite>
</catalog>
</models>
</global>
</config>
----------
Overriding A Controller
xpath: frontend/routers/checkout/args/modules/
<config>
<frontend>
<routers>
<checkout>
<args>
<modules>
<your_module before="Mage_Checkout">Your_Module_Checkout</your_module>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
----------
Config Transactional Email Template Definition
<config>
<global>
<template>
<email>
<your_module_email_something_template translate="label" module="namespace_module">
<label>Something</label>
<file>namespace/module/something.html</file>
<type>html</type>
</your_module_email_something_template>
</email>
</template>
</global>
</config>
----------
Block Caching
To cache a block individually, add this method to the blocks class:
protected function _construct()
{
$this->addData(array(
'cache_lifetime' => 3600,
'cache_tags' => array(Mage_Cms_Model_Block::CACHE_TAG),
'cache_key' => 'CACHE_KEY',
));
}
-----------
Config Two-Level Memcached & DB Definition
<config>
<global>
<cache>
<backend>memcached</backend>
<slow_backend>database</slow_backend>
<id_prefix>cache_</id_prefix>
<memcached>
<servers>
<server1>
<host><![CDATA[localhost]]></host>
<port><![CDATA[11211]]></port>
<persistent><![CDATA[0]]></persistent>
<weight><![CDATA[1]]></weight>
<timeout><![CDATA[60]]></timeout>
<retry_interval><![CDATA[10]]></retry_interval>
</server1>
</servers>
<compression><![CDATA[0]]></compression>
<cache_dir><![CDATA[]]></cache_dir>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</memcached>
</cache>
<full_page_cache>
<backend>memcached</backend>
<slow_backend>database</slow_backend>
<id_prefix>fullpagecache_</id_prefix>
<memcached>
<servers>
<server1>
<host><![CDATA[localhost]]></host>
<port><![CDATA[11211]]></port>
<persistent><![CDATA[0]]></persistent>
<weight><![CDATA[1]]></weight>
<timeout><![CDATA[60]]></timeout>
<retry_interval><![CDATA[10]]></retry_interval>
</server1>
</servers>
<compression><![CDATA[0]]></compression>
<cache_dir><![CDATA[]]></cache_dir>
<hashed_directory_level><![CDATA[]]></hashed_directory_level>
<hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
<file_name_prefix><![CDATA[]]></file_name_prefix>
</memcached>
</full_page_cache>
</global>
</config>
-----------
Add comment to form input in admin
$afterElementHtml = '<p class="nm"><small>' . ' this is the hint! ' . '</small></p>';
$linkFieldset->addField('field_name', 'text', array(
'after_element_html' => $afterElementHtml,
));
-----------
Category Product Collection
This snippet provides a collection of products within a category
$cat = Mage::getModel('catalog/category')->load(1);
$coll = Mage::getResourceModel('catalog/product_collection');
$coll->addCategoryFilter($cat);
----------
Adding BreadCrumbs
Via code (usually in a controller):
$crumbs = Mage::app()->getLayout->getBlock('breadcrumbs');
$crumbs->addCrumb('home', array(
'label' => 'Home',
'title' => 'Go to Home Page',
'link' => Mage::getUrl('')
));
Via Layout XML:
<reference name="breadcrumbs">
<action method="addCrumb">
<crumbname>Home</crumbname>
<crumbinfo>
<label>Home</label>
<title>Go to Home Page</title>
<link>/</link>
</crumbinfo>
</action>
</reference>
----------
Adding new Total Collector Model....
extends... Mage_Sales_Model_Quote_Address_Total_Abstract
config... config/global/sales/quote/totals/custom...
<config>
<global>
<sales>
<quote>
<totals>
<custom_total>
<class>mynamespace_mymodule/total</class>
<before>grand_total</before>
<after>subtotal,tax_subtotal</after>
</custom_total>
</totals>
</quote>
</sales>
</global>
</config>
priority of total collector models can be changed by before and after tags..
The method *collect* is used to calculate total for the shopping cart, and the method *fetch* is used to fetch data to display in frontend
--------------
custom product type..
xpath: global/catalog/product/type/custom_product_type/model&price_model&allow_product_types&price_indexer
<catalog>
<product>
<type>
<configurable translate="label" module="catalog">
<label>Configurable Product</label>
<model>catalog/product_type_configurable</model>
<price_model>catalog/product_type_configurable_price</price_model>
<composite>1</composite>
<allow_product_types>
<simple/>
<virtual/>
</allow_product_types>
<index_priority>30</index_priority>
<price_indexer>catalog/product_indexer_price_configurable</price_indexer>
</configurable>
</type>
</product>
</catalog>
--------------
custom indexer..
xpath: global/index/indexer/custom_indexer/model&depends
<config>
<global>
<index>
<indexer>
<test_indexer>
<model>test/indexer</model>
<depends>
<catalog_url />
</depends>
</test_indexer>
</indexer>
</index>
</global>
</config>
class Blah.. extends Mage_Index_Model_Indexer_Abstract
getName: get custom indexer name
getDescription: get custom indexer description
_registerEvent: custom registered event
_processEvent: used when processing the index event
reindexAll: reindex all items of your entity
Mage::getModel('index/indexer')->
--------------
Getting A Database Adapter (Read or Write)
To read:
Mage::getSingleton('core/resource')->getConnection('core_read');
To write:
Mage::getSingleton('core/resource')->getConnection('core_write');
----------
Add Product attribute
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
if (!$installer->getAttributeId(Mage_Catalog_Model_Product::ENTITY, 'attribute_name')) {
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'attribute_name', array( // TABLE.COLUMN: DESCRIPTION:
'label' => 'Label', // eav_attribute.frontend_label --- admin input label
'group' => 'General', // (not a column) tab in product edit screen
'sort_order' => 0, // eav_entity_attribute.sort_order sort order in group
'backend' => 'module/class_name', // eav_attribute.backend_model --- backend class (module/class_name format)
'type' => 'varchar', // eav_attribute.backend_type --- backend storage type (varchar, text etc)
'frontend' => 'module/class_name', // eav_attribute.frontend_model --- admin class (module/class_name format)
'note' => null, // eav_attribute.note --- admin input note (shows below input)
'default' => null, // eav_attribute.default_value --- admin input default value
'wysiwyg_enabled' => false, // catalog_eav_attribute.is_wysiwyg_enabled --- (products only) admin input wysiwyg enabled
'input' => 'input_name', // eav_attribute.frontend_input --- admin input type (select, text, textarea etc)
'input_renderer' => 'module/class_name', // catalog_eav_attribute.frontend_input_renderer --- (products only) admin input renderer
(otherwise input is used to resolve renderer)
'source' => null, // eav_attribute.source_model --- admin input source model (for selects) (module/class_name format)
'required' => true, // eav_attribute.is_required --- required in admin
'user_defined' => false, // eav_attribute.is_user_defined --- editable in admin attributes section, false for not
'unique' => false, // eav_attribute.is_unique --- unique value required
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // catalog_eav_attribute.is_global ---
(products only) scope
'visible' => true, // catalog_eav_attribute.is_visible --- (products only) visible on admin, setting to false stops import
of this attribute
'visible_on_front' => false, // catalog_eav_attribute.is_visible_on_front --- (products only) visible on frontend (store)
attribute table
'used_in_product_listing' => false, // catalog_eav_attribute.used_in_product_listing --- (products only) made available in
product listing
'searchable' => false, // catalog_eav_attribute.is_searchable --- (products only) searchable via basic search
'visible_in_advanced_search' => false, // catalog_eav_attribute.is_visible_in_advanced_search (products only) searchable via
advanced search
'filterable' => false, // catalog_eav_attribute.is_filterable --- (products only) use in layered nav
'filterable_in_search' => false, // catalog_eav_attribute.is_filterable_in_search --- (products only) use in search results
layered nav
'comparable' => false, // catalog_eav_attribute.is_comparable --- (products only) comparable on frontend
'is_html_allowed_on_front' => true, // catalog_eav_attribute.is_visible_on_front --- (products only) seems obvious, but also see
visible
'apply_to' => 'simple,configurable', // catalog_eav_attribute.apply_to --- (products only) which product types to apply to
'is_configurable' => false, // catalog_eav_attribute.is_configurable --- (products only) used for configurable products
or not
'used_for_sort_by' => false, // catalog_eav_attribute.used_for_sort_by --- (products only) available in the 'sort by' menu
'position' => 0, // catalog_eav_attribute.position --- (products only) position in layered naviagtion
'used_for_promo_rules' => false, // catalog_eav_attribute.is_used_for_promo_rules --- (products only) available for use in
promo rules
));
}
---------------
mage_sales_model_quote
* Supported events:
* sales_quote_load_after
* sales_quote_save_before
* sales_quote_save_after
* sales_quote_delete_before
* sales_quote_delete_after
------------
The "->getTypeInstance(true)" allows you to retrieve an object that describes the type of the product, where type is the internal magento type. So, you can use this method to determine if a products is a simple product, a bundled product, a configurable product, etc.
------------
Magento translate trace...
Mage::helper(ācoreā)->__()
Mage::app()->getTranslator()
Mage_Core_Model_Translate::translate()
------------------------------------------------
Show custom total...
sales_order_view - frontend order view page
sales_order_invoice
sales_order_creditmemo
sales_order_print - print page
sales_email_order_items - email template
sales_email_order_invoice_items
sales_email_order_creditmemo_items
adminhtml_sales_order_view - backend order view page
adminhtml_sales_order_invoice_new - backend new invoice view page
adminhtml_sales_order_invoice_view - backend invoice view page
adminhtml_sales_order_creditmemo_new - backend new creditmemo view page
adminhtml_sales_order_creditmemo_view - backend creditmemo view page
--------------
Different from catalog cart rules, shopping cart rules define the promotion for customer only when customer checks out product. They can be specified by either coupon code or others.
--------------
http://magento-quickies.tumblr.com/post/14272607486/configurable-product-research
--------------
*catalog_product_super_link* table only contains data related to configurable products.
*catalog_product_relation* contains the relation information for bundled and grouped products, in addition to the configurable relations.
*eav_entity_store* contains increment id information of orders, invoices, creditmemos, shipments, etc..
--------------
*tier prices* works with website, customer group, price and quantity (price_qty).
--------------
admin menu, render navigation items by class Mage_Adminhtml_Block_Page_Menu
_isAllowed() checks navigation permission acl,
User: the entity that has an authority to use the system. The user that we mention in Magento is the backend user.
Role: the role of the user when logging in to the system. In Magento, a user has only a role.
Rule: the rule set of user and role. It defines userās permission or roleās permission to access the resource.
Assert: the condition to active an item in ACL. It is used for a special control when checking permission by ACL.
----------------
- Accessing Magento API via SOAP ā basic steps
Create appropriate role (Magento Admin)
Create web services user (Magento Admin)
Assign created role to the user (Magento Admin)
Log-in to web service and retrieve Session Id (Soap Client)
Call appropriate method (Soap Client)
-----------------
Different ways to instantiate block:
- $block = new Packagename_Modulename_Block_Foo;
- $class = Mage::getConfig()->getBlockClassName('groupname/foo');
$block = new $class;
- $layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('groupname/foo');
OR $blockĀ = $this->getLayout()->createBlock('groupname/foo');
- <block type="groupname/foo" name="baz" />
- Call block outside Magento
require_once 'app/Mage.php';
Mage::init();
$layout = Mage::app()->getLayout();
$layout->getUpdate()
->addHandle('default')
->addHandle('some_other_handle')
->load();
/*
* Generate blocks, but XML from previously loaded layout handles must be
* loaded first.
*/
$layout->generateXml()
->generateBlocks();
$cart = $layout->getBlock('cart_sidebar')->toHtml();
echo $cart;
----------
To create new attribute in customer frontend, these three tables will be affected:
- eav_attribute
- customer_eav_attribute : id of eav_attribute here..
- customer_form_attribute : 3 entries here too, for adminhtml_customer, customer_account_create and customer_account_edit
--------------------
simple models have a resource that inherits from Mage_Core_Model_Mysql4_Abstract
EAV models inherits from Mage_Eav_Model_Entity_Abstract
Mage_Eav_Model_Entity_Abstract, there is no _init method
Mage_Eav_Model_Entity_Abstract :: _construct is not an abstract method
----------------
EAV setup: Mage_Eav_Model_Entity_Setup
//to add in eav_entity_type table...
$installer->addEntityType('complexworld_eavblogpost', array(
//entity_mode is the URI you'd pass into a Mage::getModel() call
'entity_model' => 'complexworld/eavblogpost',
//table refers to the resource URI complexworld/eavblogpost
//<complexworld_resource>...<eavblogpost><table>eavblog_posts</table>
'table' =>'complexworld/eavblogpost',
));
//to create eav tables for int, varchar, text, datetime, decimal...
$installer->createEntityTables(
$this->getTable('complexworld/eavblogpost')
);
-------------
if you have an order with three items and you refund one item the order don“t change the state, only when you refund all item of the order this change to closed state
--------------
to render a block, Mage_Core_Block_Template::renderView() is called
to render a block HTML, Mage_Core_Block_Template::_toHtml() is called
---------------
In addAttribute(), if attribute is system, it will add to all existing attribute sets
---------------
in Mage_Adminhtml_Block_Widget_Grid_Container
$_blockGroup is your module's name.
$_controller is the path to your grid block.
-------------
Direct SQL queries:
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$writeConnection = $resource->getConnection('core_write');
$tableName = $resource->getTableName('catalog_product_entity');
$tableName = $resource->getTableName('catalog/product');
$readConnection->fetchAll(......
fetchAll() - Fetches all SQL result rows as a sequential array.
fetchCol() - Fetches the first column of all SQL result rows as an array.
fetchOne() - Fetches the first column of the first row of the SQL result.
fetchRow() - Fetches the first row of the SQL result.
fetchAssoc() - Fetches all SQL result rows as an associative array.
fetchPairs() - Fetches all SQL result rows as an array of key-value pairs.
----------------------
Varien_Db_Adapter_Pdo_Mysql::prepareSqlCondition($fieldname, $condition)
If $condition integer or string - exact value will be filtered ('eq' condition)
*
* If $condition is array - one of the following structures is expected:
* - array("from" => $fromValue, "to" => $toValue)
* - array("eq" => $equalValue)
* - array("neq" => $notEqualValue)
* - array("like" => $likeValue)
* - array("in" => array($inValues))
* - array("nin" => array($notInValues))
* - array("notnull" => $valueIsNotNull)
* - array("null" => $valueIsNull)
* - array("moreq" => $moreOrEqualValue)
* - array("gt" => $greaterValue)
* - array("lt" => $lessValue)
* - array("gteq" => $greaterOrEqualValue)
* - array("lteq" => $lessOrEqualValue)
* - array("finset" => $valueInSet)
* - array("regexp" => $regularExpression)
* - array("seq" => $stringEqual)
* - array("sneq" => $stringNotEqual)
*
* If non matched - sequential array is expected and OR conditions
* will be built using above mentioned structure
-------------------------
reindex via code....
$indexer = Mage::getSingleton('index/indexer');
$process = $indexer->getProcessByCode('catalog_product_price');
$process->reindexEverything();
The following are indexer codes which you can use instead of the catalog_product_price index above:
catalog_product_attribute Product Attributes
catalog_product_price Product Prices
catalog_url Catalog URL Rewrites
catalog_product_flat Product Flat Data
catalog_category_flat Category Flat Data
catalog_category_product Category Products
catalogsearch_fulltext Catalog Search Index
cataloginventory_stock Stock Status
tag_summary Tag Aggregation Data
------------------------
Mage::getSingleton('core/session')->addError('An Error');
Mage::getSingleton('core/session')->addWarning('A Warning');
Mage::getSingleton('core/session')->addNotice ('A Notice');
Mage::getSingleton('core/session')->addSuccess('A Success');
---------------
display "out of stock" uses these indexes:
Product Attributes (catalog_product_attribute)
Product Prices (catalog_product_price)
----------------
Altering Config Data During Setup:
Setting a value in the default scope:
$installer->setConfigData('some/path', 'value');
Setting a value in a specific store:
$installer->setConfigData('some/path', 'value', 'stores', 1);
Deleting a value from all scopes:
$installer->deleteConfigData('some/path');
Deleting a value from a certain scope (unfortunately you cannot choose which scope ID though:
$installer->deleteConfigData('some/path', 'stores');
-------------------
Clearing cache:
Clean everything (use either):
Mage::app()->getCacheInstance()->flush();
Mage::app()->getCache()->clean();
Clean specific types:
Mage::app()->getCacheInstance()->cleanType('config');
instead of config, we can use layout, block_html, translate, collections, eav, config_api
-------------------
Get all declared cache types:
Mage::app()->getCacheInstance()->getTypes();
-------------------
source model in backend Adminhtml module, *requires to return* toOptionArray()
source model in EAV while adding attributes *requires to return* getAllOptions()
The core/template block is the foundation of the template system, allowing us the ability to load .phtml files from our themes.
The page/html_pager block provides generic methods for paginating collections, such as isLastPage().
cron/observer::dispatch handles the cron schedule's creation, cleanup and execution of the jobs defined in the various config.xml files
----------------
required fields when creating a new category in backend:
name, is_active, include_in_menu, available_sort_by, default_sort_by
required fields when creating a new product in backend:
name, sku, weight, status, visibility, tax class, price, short_desc, description, qty
-----------------
The shipping rate is upon Weight vs. Destination, Price vs. Destination, or # of Items vs. Destination (site admin can configurate for that)
-----------------
Mage_Shipping_Model_Carrier_Abstract:: collectRates()
Mage_Shipping_Model_Carrier_Interface:: isTrackingAvailable(), getAllowedMethods()
-------------
while adding new attributes in $setup->addAttribute('order', ...
| catalog_category |
| catalog_product |
| creditmemo |
| creditmemo_comment |
| creditmemo_item |
| customer |
| customer_address |
| customer_payment |
| invoice |
| invoice_comment |
| invoice_item |
| invoice_shipment |
| order |
| order_address |
| order_item |
| order_payment |
| order_status |
| order_status_history |
| quote |
| quote_address |
| quote_address_item |
| quote_address_rate |
| quote_item |
| quote_payment |
| shipment |
| shipment_comment |
| shipment_item |
| shipment_track |
----------------------------------
Adding JS, Skin JS and CSS files...
<action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>
<action method="addItem"><type>js</type><name>lib/ds-sleight.js</name><params/><if>lt IE 7</if></action>
<action method="addItem"><type>skin_css</type><name>css/styles-ie.css</name><params/><if>lt IE 8</if></action>
<action method="addJs"><script>mage/cookies.js</script></action>
<action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></action>
-----------
CMS Directives.....
can be used in CMS, static blocks or emails
{{block id='block_id'}}
{{block type='module/package_classname' template='path/to/template.phtml'}}
{{config path='section/group/field'}}
{{htmlescape var='' allowed_tags=''}}
{{htmlescape var='<a href="javascript:alert(1);">Hello</a>'}}
//this outputs <a href="javascript:alert(1);">Hello</a> and doesn't interpreted by browsers
{{layout handle=''}}
{{media url=''}}
{{skin url=''}}
{{store url=''}}
{{block type='namespace_custom/test' my_param1='value 1' my_param2='value 2'}} |
BEST LUCK! š
6 Comments
Leave a comment
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)
Thanks a ton, Kalpesh for sharing this! will certainly help.
awesome list. very useful.
very nice…….
Great!
great!!!
Helpful post , I loved the insight – Does anyone know if my business can get a sample a form form to edit ?