User Tools

Site Tools


php:magento

Table of Contents

Magento Ecommerce

Analyse code

magento startup

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
  Mage::setIsDeveloperMode(true);
}
self::_setConfigModel($options);
  -> self::$_config = new Mage_Core_Model_Config($options);
    -->$this->_options         = new Mage_Core_Model_Config_Options($sourceData);
      --->
      $this->_data['code_dir']    = $appRoot.DS.'code';
      $this->_data['design_dir']  = $appRoot.DS.'design';
      $this->_data['etc_dir']     = $appRoot.DS.'etc';
      $this->_data['lib_dir']     = $root.DS.'lib';
Mage::run($mageRunCode, $mageRunType);
  -> self::$_app    = new Mage_Core_Model_App();
  -> self::$_app->run(...)
(single class)Mage_Core_Model_App->run()
	-> $this->baseInit($options)
		--> $this->_initBaseConfig();
			--->Varien_Profiler::start('mage::app::init::system_config');
			--->$this->_config->loadBase();
				---->$etcDir = $this->getOptions()->getEtcDir();
					$files = glob($etcDir.DS.'*.xml');
					$this->loadFile(current($files));
					if (in_array($etcDir.DS.'local.xml', $files)) {
						$this->_isLocalConfigLoaded = true;
					}
			--->Varien_Profiler::stop('mage::app::init::system_config');
	-> $this->_cache->processRequest()
	   $this->getResponse()->sendResponse();
	   return;

OR

-> $this->_initModules();
  --> $this->_config->loadModules
    --->$this->_loadDeclaredModules();
      ----> $moduleFiles = $this->_getDeclaredModuleFiles();
        ----->$etcDir = $this->getOptions()->getEtcDir();
           $moduleFiles = glob($etcDir . DS . 'modules' . DS . '*.xml');
    --->$resourceConfig = sprintf('config.%s.xml', $this->_getResourceConnectionModel('core'));
    --->$this->loadModulesConfiguration(array('config.xml',$resourceConfig), $this);
      ----> into etc directory of each module to load all configs
        only load modules is active
  --> $this->_config->loadDb();
    ---> $dbConf = $this->getResourceModel();(Mage_Core_Model_Resource_Config)
          ---> $dbConf->loadToXml($this);
      ----> load tables: core_website, core_store, core_config_data
        $this->getTable('core/website')
        $this->getTable('core/store')
        $this->getMainTable()->get config in database
        default/design/theme/default->f002
      --> $this->_config->saveCache();
-> $this->_initCurrentStore($scopeCode, $scopeType);
  -->load tables: core_store, core_website, core_store_group (all AS main_table)
-> $this->getFrontController()->dispatch();(Mage_Core_Controller_Varien_Front)
  -->Mage::getModel('core/url_rewrite')->rewrite();(Mage_Core_Model_Url_Rewrite)
     load tables: core_url_rewrite
    --->$this->loadByRequestPath($requestCases);
      ---->$this->_getResource()->loadByRequestPath($this, $path);(Mage_Core_Model_Resource_Url_Rewrite)
        ----->$this->getMainTable()(Mage_Core_Model_Resource_Db_Abstract->getMainTable())
  -->$this->rewrite();(load rewrite from config global/rewrite)
  -->Mage_Core_Controller_Varien_Router
    Mage_Core_Controller_Varien_Router_Admin
    Mage_Core_Controller_Varien_Router_Standard
  -->$router->match($this->getRequest())
    ---->$controllerInstance->dispatch($action);
    ---->for default page: 
      Mage_Cms_IndexController
      index

analyse default page controller

Mage_Cms_IndexController in [app/code/core/Mage/cms/controllers/IndexController.php]
index
[app/code/core/Mage/cms/etc/config.xml]

<global>
      <models>
          <cms>
              <class>Mage_Cms_Model</class>
              <resourceModel>cms_resource</resourceModel>
          </cms>
          <cms_resource>
              <class>Mage_Cms_Model_Resource</class>
              <deprecatedNode>cms_mysql4</deprecatedNode>
              <entities>
                  <page>
                      <table>cms_page</table>
                  </page>
                  <page_store>
                      <table>cms_page_store</table>
                  </page_store>
                  <block>
                      <table>cms_block</table>
                  </block>
                  <block_store>
                      <table>cms_block_store</table>
                  </block_store>
              </entities>
          </cms_resource>
      </models>
  .........
</global>

Analyse code select funitures

controller and view

Mage_Catalog_CategoryController in app/code/core/Mage/Catalog/controllers/IndexController.php
Function: view
[app/code/core/Mage/Catalog/etc/config.xml]

<global>
    <models>
        <catalog>
            <class>Mage_Catalog_Model</class>
            <resourceModel>catalog_resource</resourceModel>
        </catalog>
        <catalog_resource>
            <class>Mage_Catalog_Model_Resource</class>
            <deprecatedNode>catalog_resource_eav_mysql4</deprecatedNode>
            <entities>
                <product>
                    <table>catalog_product_entity</table>
                </product>
                <category>
                    <table>catalog_category_entity</table>
                </category>
                <category_product>
                    <table>catalog_category_product</table>
                </category_product>
                <category_product_index>
                    <table>catalog_category_product_index</table>
                </category_product_index>
                <compare_item>
                    <table>catalog_compare_item</table>
                </compare_item>
                <product_website>
                    <table>catalog_product_website</table>
                </product_website>
                .........................
            </entities>
        </catalog_resource>
    </models>

models

  • class Mage_Catalog_Model → all model class in directory: Mage\Catalog\Model\
    • Mage_Catalog_Model_Abstract
    • Mage_Catalog_Model_Catetory
    • Mage_Catalog_Model_Product
  • class Mage_Catalog_Model_Resource → all model resource in directory: Mage\Catalog\Model\Resource\
    • Mage_Catalog_Model_Resource_Abstract
    • Mage_Catalog_Model_Resource_Catetory
    • Mage_Catalog_Model_Resource_Product

instant models

  Mage::getModel('catalog/product');
  ->
    catalog -> Mage_Catalog_Model
    product -> class Mage_Catalog_Model_Product
  Mage::helper('catalog/product');
  ->
    catalog -> Mage_Catalog_helper
    product -> class Mage_Catalog_helper_Product

……………………. [Paramater/Value - id/25]

<frontend>
      <routers>
          <catalog>
              <use>standard</use>
              <args>
                  <module>Mage_Catalog</module>
                  <frontName>catalog</frontName>
              </args>
          </catalog>
      </routers>
..............................

⇒ router:

  • frontname: catalog
  • module: Mage_Catalog → specify the module location with frontend above
    • Mage_Catalog_CategoryController
    • Mage_Catalog_ProductController

- view detail

  • Mage_Catalog_ProductController
  • view

Module customer

app\code\core\Mage\Customer\Helper\Data.php

admin

  • design: app\design\adminhtml\default\default\
  • layout: app\design\adminhtml\default\default\layout\customer.xml
    • admin/customer/new
    • admin/customer/edit

base

  • design: app\design\frontend\base\default\
  • layout: app\design\frontend\base\default\layout\customer.xml ⇒ Supported layout update handles (action):
    • customer_account_index
      <customer_account_index translate="label">
        <label>Customer My Account Dashboard</label>
        <update handle="customer_account"/>
        <!-- Mage_Customer -->
        <reference name="root">
          <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>
        <reference name="my.account.wrapper">
          <block type="customer/account_dashboard" name="customer_account_dashboard" template="customer/account/dashboard.phtml">
            <block type="customer/account_dashboard_hello" name="customer_account_dashboard_hello" as="hello" template="customer/account/dashboard/hello.phtml"/>
            <block type="core/template" name="customer_account_dashboard_top" as="top" />
            <block type="customer/account_dashboard_info" name="customer_account_dashboard_info" as="info" template="customer/account/dashboard/info.phtml"/>
            <block type="customer/account_dashboard_newsletter" name="customer_account_dashboard_newsletter" as="newsletter" template="customer/account/dashboard/newsletter.phtml"/>
            <block type="customer/account_dashboard_address" name="customer_account_dashboard_address" as="address" template="customer/account/dashboard/address.phtml"/>
          </block>
        </reference>
      </customer_account_index>
       
      • customer_address_index
      • customer_address_view
      • customer_account_login
        <customer_account_login translate="label">
          <label>Customer Account Login Form</label>
          <!-- Mage_Customer -->
          <remove name="right"/>
          <remove name="left"/>
          <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
          </reference>
          <reference name="content">
            <block type="customer/form_login" name="customer_form_login" template="customer/form/login.phtml" />
          </reference>
        </customer_account_login>
      • customer_account_logoutsuccess
      • customer_account_create
      • customer_account_forgotpassword
      • customer_account_confirmation
      • customer_account_edit
  • customer/account/login/
  • customer/account/create/
  • customer/account/edit/

Mangento layout or root template

To enable or disable 1 module and layout ⇒ Change config in app/etc/modules/*.xml

Default layout for all pages in [page.xml]

Default layout, loads most of the pages

<layout version="0.1.0">
<!--
Default layout, loads most of the pages
-->
 
    <default translate="label" module="page">
        <label>All Pages</label>
        <block type="page/html" name="root" output="toHtml" template="page/2columns-left.phtml">
 
            <block type="page/html_head" name="head" as="head">
                <action method="addJs"><script>prototype/prototype.js</script></action>
                <action method="addJs"><script>lib/ccard.js</script></action>
                .........................................................
                <block type="page/js_cookie" name="js_cookies" template="page/js/cookie.phtml"/>
                .........................................................
                <action method="addCss"><stylesheet>css/styles.css</stylesheet></action>
                .........................................................
                <action method="addItem"><type>skin_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>
            </block>
 
            <block type="core/text_list" name="after_body_start" as="after_body_start" translate="label">
                <label>Page Top</label>
            </block>
 
            <block type="page/html_notices" name="global_notices" as="global_notices" template="page/html/notices.phtml" />
 
            <block type="page/html_header" name="header" as="header">
                <block type="checkout/cart_sidebar" name="cart_header" template="checkout/cart/sidebar_header.phtml">
                    <action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
                    <action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
                    <action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
                    <block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
                        <label>Shopping Cart Sidebar Extra Actions</label>
                    </block>
                </block>
 
                <block type="page/template_links" name="top.links" as="topLinks"/>
                <block type="page/template_links" name="top.links.left" as="topLinksLeft"/>
                <block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
                <block type="directory/currency" name="currency" template="directory/currency.phtml"/>
                <block type="core/text_list" name="top.menu" as="topMenu" translate="label">
                    <label>Navigation Bar</label>
                    <block type="page/html_topmenu" name="catalog.topnav" template="page/html/topmenu.phtml"/>
                </block>
                <block type="page/html_wrapper" name="top.container" as="topContainer" translate="label">
                    <label>Page Header</label>
                    <action method="setElementClass"><value>top-container</value></action>
                </block>
            </block>
 
            <block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
 
            <block type="core/text_list" name="left" as="left" translate="label">
                <label>Left Column</label>
            </block>
 
            <block type="core/messages" name="global_messages" as="global_messages"/>
            <block type="core/messages" name="messages" as="messages"/>
 
            <block type="core/text_list" name="content" as="content" translate="label">
                <label>Main Content Area</label>
            </block>
 
            <block type="core/text_list" name="right" as="right" translate="label">
                <label>Right Column</label>
            </block>
 
            <block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
                <block type="cms/block" name="footer_list">
                    <action method="setBlockId"><block_id>footer_list</block_id></action>
                </block>
                <block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
                    <label>Page Footer</label>
                    <action method="setElementClass"><value>bottom-container</value></action>
                </block>
                <block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
                <block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
            </block>
 
            <block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
                <label>Page Bottom</label>
            </block>
        </block>
 
        <block type="core/profiler" output="toHtml" name="core_profiler"/>
    </default>
 
    <print translate="label" module="page">
        <label>All Pages (Print Version)</label>
        <!-- Mage_Page -->
        <block type="page/html" name="root" output="toHtml" template="page/print.phtml">
 
            <block type="page/html_head" name="head" as="head">
                <action method="addJs"><script>prototype/prototype.js</script></action>
                <action method="addCss"><stylesheet>css/print.css</stylesheet><params>media="print"</params></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_js</type><name>js/ie6.js</name><params/><if>lt IE 7</if></action>
 
            </block>
 
            <block type="core/text_list" name="content" as="content" translate="label">
                <label>Main Content Area</label>
            </block>
 
        </block>
    </print>
 
     <!-- Custom page layout handles -->
    <page_empty translate="label">
        <label>All Empty Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/empty.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_empty>
 
    <page_one_column translate="label">
        <label>All One-Column Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_one_column>
 
    <page_two_columns_left translate="label">
        <label>All Two-Column Layout Pages (Left Column)</label>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_two_columns_left>
 
    <page_two_columns_right translate="label">
        <label>All Two-Column Layout Pages (Right Column)</label>
        <reference name="root">
            <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_two_columns_right>
 
    <page_three_columns translate="label">
        <label>All Three-Column Layout Pages</label>
        <reference name="root">
            <action method="setTemplate"><template>page/3columns.phtml</template></action>
            <!-- Mark root page block that template is applied -->
            <action method="setIsHandle"><applied>1</applied></action>
        </reference>
    </page_three_columns>
</layout>

root templates of home,about

one_column, two_columns_left, two_columns_right, three_columns

SELECT `cms_page`.* FROM `cms_page` INNER JOIN `cms_page_store` ON cms_page.page_id = cms_page_store.page_id WHERE (`cms_page`.`identifier`='home') AND (is_active = 1) AND (cms_page_store.store_id IN (0, 1)) ORDER BY `cms_page_store`.`store_id` DESC LIMIT 1

root template of Mage_Catalog_CategoryController/view

[catalog.xml]

  <catalog_product_view translate="label">
    <label>Catalog Product View (Any)</label>
    <!-- Mage_Catalog -->
    <reference name="root">
      <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
    </reference>
    .....

Default config for blocks in each pages

[core.xml]

<default>
  <block name="formkey" type="core/template" template="core/formkey.phtml" />
</default>

CMS Pages: [cms.xml]

<default>
  <reference name="footer">
    <block type="cms/block" name="cms_footer_links" before="footer_links">
      <!--
        The content of this block is taken from the database by its block_id.
        You can manage it in admin CMS -> Static Blocks
      -->
      <action method="setBlockId"><block_id>footer_links</block_id></action>
    </block>
  </reference>
  <cms_index_index translate="label">
        <label>CMS Home Page</label>
    </cms_index_index>
 
    <cms_index_defaultindex>
        <remove name="right"/>
        <remove name="left"/>
 
        <reference name="root">
            <action method="setTemplate"><template>page/1column.phtml</template></action>
        </reference>
        <reference name="content">
            <block type="core/template" name="default_home_page" template="cms/default/home.phtml"/>
        </reference>
    </cms_index_defaultindex>
</default>

Catalog Pages: [catalog.xml]

<default>
  <!-- Mage_Catalog -->
  <reference name="left">
    <block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
      <action method="setImgSrc"><src>images/media/col_left_callout.jpg</src></action>
      <action method="setImgAlt" translate="alt" module="catalog"><alt>Our customer service is available 24/7. Call us at (555) 555-0123.</alt></action>
      <action method="setLinkUrl"><url>checkout/cart</url></action>
    </block>
  </reference>
  <reference name="right">
    .............................
  </reference>
  <reference name="footer_links">
    ............................
  </reference>
  <block type="catalog/product_price_template" name="catalog_product_price_template" />
</default>

Default page with root templates(layout) and blocks

Edit in Admin: Quan ly CMS → Page → Home Edit layout and page config in Design

  • layout:
    • 1 column
    • 2 column with left bar
    • 2 column with right bar
    • 3 columns
  • layout update xml or config of blocks in default page:
    <reference name="head">
    		<action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.fancybox-1.3.4.js</name></action>
    		<action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.easing-1.3.pack.js</name></action>
    		<action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.mousewheel-3.0.6.pack.js</name></action>
    		<action method="addItem"><type>js</type><name>jquery/noconflict.js</name></action>
    		<action method="addCss"><stylesheet>js/fancybox/jquery.fancybox-1.3.4.css</stylesheet></action>
    </reference>
    <reference name="content">
    <block type="catalog/product_list_random" template="catalog/product/list.phtml">
    	<action method="setNumProducts"><count>12</count></action>
    </block>    
    </reference>
        <reference name="right">
            <action method="unsetChild"><alias>right.reports.product.viewed</alias></action>
            <action method="unsetChild"><alias>right.reports.product.compared</alias></action>
        </reference>
    <reference name="top_slider">
      <block type="cms/block"  name="showcase">
        <action method="setBlockId">
          <block_id>showcase</block_id>
        </action>
      </block> 
    </reference>

New module and update blocks config of each default pages

Example config for module ajax:

<catalog_product_view>
    	<reference name="head">
            <action method="addItem"><type>js</type><name>jquery/noconflict.js</name></action>
			<action method="addItem"><type>skin_js</type><name>js/script.js</name></action>
        </reference>
        <reference name='product.info'>
        	<action method='setTemplate'><template>ajax/catalog/product/view.phtml</template></action>
        </reference>
        <reference name='product.info.addtocart'>
	        	<action method='setTemplate'><template>ajax/catalog/product/view/addtocart.phtml</template></action>
	    </reference>
    </catalog_product_view>
    <catalog_category_default>
    	<reference name="head">
            <action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.fancybox-1.3.4.js</name></action>
            <action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.easing-1.3.pack.js</name></action>
            <action method="addItem"><type>skin_js</type><name>js/fancybox/jquery.mousewheel-3.0.6.pack.js</name></action>
            <action method="addItem"><type>js</type><name>jquery/noconflict.js</name></action>
            <action method="addCss"><stylesheet>js/fancybox/jquery.fancybox-1.3.4.css</stylesheet></action>
 
 
        </reference>
    	<reference name='product_list'>
    		<action method='setTemplate'><template>ajax/catalog/product/view/list.phtml</template></action>
    	</reference>
    </catalog_category_default>

⇒ This module update below pages:

  • catalog_product_view: config default of catalog_product_view in layout\catalog.xml
    <default>
    ................
    <catalog_product_view translate="label">...</catalog_product_view>
    ................
    </default>
  • catalog_category_default: config default of catalog_category_default in layout\catalog.xml
    <default>
    ................
    <catalog_category_default translate="label">...</catalog_category_default>
    ................
    </default>

Config and edit display of left column from admin

  1. step1: config display template callouts/left_col.phtml in left column by editing the layout file layout/catalog.xml
    <reference name="left">
                <block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
                    <action method="setBlockId"><block_id>callouts_left_col</block_id></action> 
    .......................................                
  2. step2: change content of template callouts/left_col.phtml to get content of block callouts_left_col:
    <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('callouts_left_col')->toHtml() ?>
  3. step3: add content of block callouts_left_col from admin by go to Quản lý CMS → Static Blocks and create new block with name callouts_left_col and content below
    <div class="block block-banner">
    <div class="block-title"><strong><span>Li&ecirc;n hệ đặt h&agrave;ng</span></strong></div>
    <div class="block-content"><ol class="hotline">
    <li style="text-align: left;"><strong>Phone:&nbsp;</strong><span style="color: #888888; font-size: small;">0903 245 543</span></li>
    <li style="text-align: left;"><strong>Địa chỉ:</strong>&nbsp;<span style="font-size: small;"><span style="color: #b2b2b2;"><span style="color: #b2b2b2;">436/59/37 C&aacute;ch Mạng th&aacute;ng 8 , Phường 11, Quận 3, TPHCM &nbsp;</span></span></span></li>
    <li><span style="font-size: medium;"><a href="https://maps.google.com/maps/ms?msid=202899200564903042773.0004c3609fb3a34b78a53&amp;msa=0&amp;ie=UTF8&amp;ll=10.784228,106.67098&amp;spn=0.002682,0.005284&amp;t=m&amp;source=embed" target="_blank">Xem bản đồ đường đi</a></span></li>
    <li class="icon-address" style="text-align: left;"><strong>Email: </strong><span style="color: #b2b2b2; font-size: small;">[email protected]</span></li>
    </ol></div>
    </div>
    <div class="block block-banner">
    <div class="block-title"><strong><span>Giờ mở cửa</span></strong></div>
    <div class="block-content"><ol class="hotline">
    <li style="text-align: left;"><strong>Thứ 2 đến thứ 6:<span style="font-size: small;"><span style="color: #b2b2b2;">9:00-20:00</span></span></strong></li>
    <li style="text-align: left;"><strong>Thứ 7,CN : </strong><span style="color: #b2b2b2; font-size: small;">vui l&ograve;ng gọi điện thoại trước khi đến</span></li>
    </ol></div>
    </div>
  4. step4: update display chatango in left bar:
    <script id="cid0020000087513494433" data-cfasync="false" async src="//st.chatango.com/js/gz/emb.js" style="width: 210px;height: 350px;">{"handle":"shopbabiesvn","arch":"js","styles":{"b":100,"c":"f97789","d":"006699","e":"fdfdfd","h":"f2f2f2","l":"9ddbf6","m":"FFFFFF","p":"10","q":"9ddbf6","r":100}}</script>
  • CMS Block to display links in top.links.phtml:
    <?php if($toplinks && is_array($toplinks)): ?>
    <ul class="links">
        <?php echo $this->getChildHtml() ?>
        <?php foreach($toplinks as $_toplink): ?>
        <li<?php if($_toplink['first']||$_toplink['last']): ?> class="<?php if($_toplink['first']): ?>first<?php endif; ?><?php if($_toplink['last']): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_toplink['liParams'] ?>><?php echo $_toplink['beforeText'] ?><a <?php echo $_toplink['aParams'] ?>><?php echo $_toplink['innerText'] ?></a><?php echo $_toplink['afterText'] ?></li>
        <?php endforeach; ?>
    </ul>
  • Config links in layout customer.xml:
    <layout version="0.1.0">
     
    <!--
    Default layout, loads most of the pages
    -->
     
        <default>
            <!-- Mage_Customer -->
            <reference name="top.links">
                <action method="addLink" translate="label title" module="customer"><label>My Account</label><url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/><position>10</position></action>
            </reference>
        </default>
     
    <!--
    Load this update on every page when customer is logged in
    -->
     
        <customer_logged_in>
            <reference name="top.links">
                <action method="addLink" translate="label title" module="customer"><label>Log Out</label><url helper="customer/getLogoutUrl"/><title>Log Out</title><prepare/><urlParams/><position>100</position></action>
            </reference>
        </customer_logged_in>
     
    <!--
    Load this update on every page when customer is logged out
    -->
     
        <customer_logged_out>
            <!---<reference name="right">
                <block type="customer/form_login" name="customer_form_mini_login" before="-" template="customer/form/mini.login.phtml"/>
            </reference>-->
            <reference name="top.links">
                <action method="addLink" translate="label title" module="customer"><label>Log In</label><url helper="customer/getLoginUrl"/><title>Log In</title><prepare/><urlParams/><position>100</position></action>
            </reference>
            <remove name="reorder"></remove>
        </customer_logged_out>

Database

Database init

SELECT `core_url_rewrite`.* FROM `core_url_rewrite` WHERE (request_path IN ('/', '')) AND (store_id IN(0, 1))
  -> empty DATA
 
SELECT `main_table`.* FROM `design_change` AS `main_table` WHERE (store_id = '1') AND (date_from <= '2012-05-25 13:49:56' OR date_from IS NULL) AND (date_to >= '2012-05-25 13:49:56' OR date_to IS NULL)
  -> empty DATA
 
SELECT `cms_page`.* FROM `cms_page` INNER JOIN `cms_page_store` ON cms_page.page_id = cms_page_store.page_id WHERE (`cms_page`.`identifier`='home') AND (is_active = 1) AND (cms_page_store.store_id IN (0, 1)) ORDER BY `cms_page_store`.`store_id` DESC LIMIT 1
  (2,"Home page","two_columns_right")
 
SELECT `cms_page_store`.`store_id` FROM `cms_page_store` WHERE (page_id = 2)
  (1|2|3)
 
SELECT `eav_entity_type`.* FROM `eav_entity_type` WHERE (`eav_entity_type`.`entity_type_code`='catalog_category')
  9	catalog_category	catalog/category	catalog/resource_eav_attribute	catalog/category
 
SELECT `catalog_category_entity`.`entity_id` FROM `catalog_category_entity` WHERE (entity_id = '2')
  (2)
 
SELECT `catalog_category_entity`.* FROM `catalog_category_entity` WHERE (`catalog_category_entity`.`entity_id` = '2')
 
SELECT `catalog_category_entity`.* FROM `catalog_category_entity` WHERE (`catalog_category_entity`.`path` LIKE '1/2/%') ORDER BY `catalog_category_entity`.`position` ASC

Manage products

category

catalog_category_entity_varchar
  (`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`)
  (1,9,111,0,3,'Root Catalog'),(2,9,118,0,3,'PRODUCTS'),(3,9,479,0,3,'root-catalog'),(4,9,111,0,4,'Shirts'),(5,9,118,0,4,'PRODUCTS'),(6,9,479,0,4,'shirts'),(7,9,111,0,5,'Shoes'),(8,9,118,0,5,'PRODUCTS'),(9,9,479,0,5,'shoes'),(10,9,111,0,8,'Cell Phones')
 

product

catalog_product_entity(entity_id,entity_type_id,attribute_set_id,type_id,sku)
catalog_product_index_price(entity_id,customer_group_id,website_id,tax_class_id,price,final_price,min_price,max_price)
  16	0	1	2	149.99	149.99	149.99	149.99
  16	1	1	2	149.99	149.99	149.99	149.99

manage customer

customer_entity(entity_id,email,is_active)
	1, anh.[email protected].com
 
customer_entity_varchar(attribute_id,entity_id,VALUE)
	5	1	Anh
	7	1	Vo Chi
	12	1	2646fdab0814a50d2aca365bcfa3dd83:p2
	3	1	DEFAULT Store VIEW

remove load check custom modules of magento

[Mage_Core_Model_App]

  const XML_PATH_SKIP_PROCESS_MODULES_UPDATES = 'global/skip_process_modules_updates';
  return (bool)(string)$this->_config->getNode(self::XML_PATH_SKIP_PROCESS_MODULES_UPDATES);

[local.xml]

<global>
  .....
  <skip_process_modules_updates>true</skip_process_modules_updates>
  ....

Improve Scalability and Performance(optimize)

Remove some modules unused

Magento Block Cache

Cache some data don't change:

  • System(config.xml, local.xml) and modules configuration files(config.xml).
  • Layout
  • Blocks HTML Output
  • Translation files
  • EAV types and attributes

Debug cache in: app\code\core\Mage\Core\Model\Cache.php function load

  • “core_cache_options”
  • “config_global.lock”
  • “config_global”
  • “app_4e4abdd8dc00c3dacb3c1597944a3b6c”
  • “store_admin_config_cache”
  • “app_b1fb6e8f13287c01e5c05063633dda4c”
  • “app_e4d52b98688947405ede639e947ee03d”
  • “store_default_config_cache”
  • “store_french_config_cache”
  • “store_german_config_cache”
  • “config_global_stores_default”
  • “config_global_admin”
  • “translate_vi_VN_frontend_1_default_f002”
  • “LAYOUT_14ba6f2eff95e69218ba655328cbff4db”
  • “javascript_translate_config”

Add module caching optimize for magento blocks

Refer: http://www.jewelsboutique.com/news/systems/magento-performance-optimization-continued-custom-block-cache-in-magento.html
before getting block output Magento will dispatch an Event (core_block_abstract_to_html_before), this is a good place to inject our cache setting for any block we want rather than editing each block independently

  1. Add a new module or editing an existing module’s config.xml, add the following event listening setting: [app\code\core\Mage\Core\etc\config.xml]
    ..............
      <events>
        <core_block_abstract_to_html_before>
         <observers>
        <cacheBlock>
         <type>singleton</type>
         <class>core/blockcache_observer</class>
         <method>customBlockCache</method>
        </cacheBlock>
         </observers>
        </core_block_abstract_to_html_before>
      </events>
    </frontend> 
  2. Add the implementation of event handler
    <?php
    class Mage_Core_Model_Blockcache_Observer{
    	//you can make this to be configurable at Admin Panel
    	const CUSTOM_CACHE_LIFETIME = 9999999999;
    	//the non-CMS Block you want to cache
    	private $cacheableBlocks = array('Mage_Page_Block_Html_Topmenu', 'Mage_Page_Block_Html_Footer');
    	public function customBlockCache(Varien_Event_Observer $observer){
    		try 
    		{
    			$event = $observer->getEvent();
    			$block = $event->getBlock();
    			$class = get_class($block);
    			//Zend_Debug::dump($class);
    			if (('Mage_Cms_Block_Block' == $class) && $block->getBlockId()) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'cms_block_' . $block->getBlockId());
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG, $block->getBlockId()));
    			} elseif (('Mage_Cms_Block_Page' == $class) && $block->getPage()->getIdentifier()) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'cms_page_' . $block->getPage()->getIdentifier());
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG,
    				$block->getPage()->getIdentifier()));
    			} elseif (in_array($class, $this->cacheableBlocks)) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'block_' . $class);
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG, $class));
    			}
    		} catch (Exception $e) {
    			Mage::logException(e);
    		}
    	}
    }
  3. Edit the implementation of event handler for shop.babies.vn
    <?php
    class Mage_Core_Model_Blockcache_Observer{
    	//you can make this to be configurable at Admin Panel
    	const CUSTOM_CACHE_LIFETIME = 9999999999;
    	//the non-CMS Block you want to cache
    	private $cacheableBlocks = array('Mage_Page_Block_Html_Topmenu', 'Mage_Page_Block_Html_Footer');
    	public function customBlockCache(Varien_Event_Observer $observer){
    		try 
    		{
    			$event = $observer->getEvent();
    			$block = $event->getBlock();
    			$class = get_class($block);
    			if (('Mage_Cms_Block_Block' == $class) && $block->getBlockId()) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'cms_block_' . $block->getBlockId());
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG, $block->getBlockId()));
    			} elseif (('Mage_Cms_Block_Page' == $class) && $block->getPage()->getIdentifier()) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'cms_page_' . $block->getPage()->getIdentifier());
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG,
    				$block->getPage()->getIdentifier()));
    			} elseif (('Mage_Catalog_Block_Category_View' == $class) && $block->getCurrentCategory()->getId()) {
    				$request = $block->getRequest();
    				$order = $request->getParam('order');
    				$page = $request->getParam('p');
    				$limit = $request->getParam('limit');
    				$dir = $request->getParam('dir');
    				$mode = $request->getParam('mode');
    				$cache_key = $class . '_' . $block->getCurrentCategory()->getId();
    				$cache_tags = array(Mage_Catalog_Model_Category::CACHE_TAG,$block->getCurrentCategory()->getId());
    				if(!empty($order))
    				{
    					$cache_key = $cache_key . '_' . $order;
    					$cache_tags[] = $order;
    				}
    				if(!empty($page))
    				{
    					$cache_key = $cache_key . '_page' . $page;
    					$cache_tags[] = '_page' .$page;
    				}
    				if(!empty($limit))
    				{
    					$cache_key = $cache_key . '_limit' . $limit;
    					$cache_tags[] = '_limit' . $limit;
    				}
    				if(!empty($dir))
    				{
    					$cache_key = $cache_key . '_' . $dir;
    					$cache_tags[] = $dir;
    				}
    				if(!empty($mode))
    				{
    					$cache_key = $cache_key . '_' . $mode;
    					$cache_tags[] = $mode;
    				}
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', $cache_key);
    				$block->setData('cache_tags', $cache_tags);
    			} elseif (('Mage_Catalog_Block_Product_View' == $class) && $block->getProduct()->getId()) {
    				$cache_key = $class . '_' . $block->getProduct()->getId();
    				$cache_tags = array(Mage_Catalog_Model_Product::CACHE_TAG,$block->getProduct()->getId());
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', $cache_key);
    				$block->setData('cache_tags', $cache_tags);
    			} elseif (('Mage_Catalog_Block_Product_List_Related' == $class) && Mage::registry('product')->getId()) {
    				$cache_key = $class . '_' . Mage::registry('product')->getId();
    				$cache_tags = array(Mage_Catalog_Model_Product::CACHE_TAG, Mage::registry('product')->getId());
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', $cache_key);
    				$block->setData('cache_tags', $cache_tags);
    			} elseif (in_array($class, $this->cacheableBlocks)) {
    				$block->setData('cache_lifetime', self::CUSTOM_CACHE_LIFETIME);
    				$block->setData('cache_key', 'block_' . $class);
    				$block->setData('cache_tags', array(Mage_Core_Model_Store::CACHE_TAG, $class));
    			}
    			else
    			{
    				//Zend_Debug::dump($class);
    			}
    		} catch (Exception $e) {
    			Mage::logException(e);
    		}
    	}
    }

Other optimize methods

  1. re-index data
    • in admin
    • manual: php shell/indexer.php reindexall
  2. merger js and css: in admin: System/Config/Developer
  3. compile magento php
    • config: [etc/modules/Mage_Compiler.xml]
    • compile:
      php.exe compiler help
      php.exe compiler compile
    • enable compiler mode:
      • admin: in system/tools/compile
      • or edit code: includes/config.php

Basic configs and updates

config code

[app\code\core\Mage\Core\Model\Config\Options.php]

$this->_data['app_dir']     = $appRoot;
$this->_data['base_dir']    = $root;
$this->_data['code_dir']    = $appRoot.DS.'code';
$this->_data['design_dir']  = $appRoot.DS.'design';
$this->_data['etc_dir']     = $appRoot.DS.'etc';
$this->_data['lib_dir']     = $root.DS.'lib';
$this->_data['locale_dir']  = $appRoot.DS.'locale';
$this->_data['media_dir']   = $root.DS.'media';
$this->_data['skin_dir']    = $root.DS.'skin';
$this->_data['var_dir']     = $this->getVarDir();
$this->_data['tmp_dir']     = $this->_data['var_dir'].DS.'tmp';
$this->_data['cache_dir']   = $this->_data['var_dir'].DS.'cache';
$this->_data['log_dir']     = $this->_data['var_dir'].DS.'log';
$this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
$this->_data['upload_dir']  = $this->_data['media_dir'].DS.'upload';
$this->_data['export_dir']  = $this->_data['var_dir'].DS.'export';

config.xml

[config.xml]

<entities>
	<config_data>
		<table>core_config_data</table>
	</config_data>
	<website>
		<table>core_website</table>
	</website>
	<store>
		<table>core_store</table>
	</store>
	<resource>
		<table>core_resource</table>
	</resource>
	<cache>
		<table>core_cache</table>
	</cache>
	<cache_tag>
		<table>core_cache_tag</table>
	</cache_tag>
	<cache_option>
		<table>core_cache_option</table>
	</cache_option>
</entities>
<filesystem>
	<base>{{root_dir}}</base>
	<app>{{root_dir}}/app</app>
	<codes>{{app_dir}}/code</codes>
	<design>{{app_dir}}/design</design>
	<locale>{{app_dir}}/locale</locale>
	<etc>{{app_dir}}/etc</etc>
	<media>{{root_dir}}/media</media>
	<upload>{{root_dir}}/media/upload</upload>
	<skin>{{root_dir}}/skin</skin>
	<var>{{var_dir}}</var>
	<cache>{{var_dir}}/cache</cache>
	<session>{{var_dir}}/session</session>
	<tmp>{{var_dir}}/tmp</tmp>
	<pear>{{var_dir}}/pear</pear>
	<export>{{var_dir}}/export</export>
</filesystem>

change domain from localhost to shop.babies.vn

  • config connect to database: local.xml and config.xml
  • config base_url: table core_config_data: replace http://localhost to http://shop.babies.vn
    UPDATE core_config_data SET VALUE = 'http://shop.babies.vn/' WHERE path IN ('web/unsecure/base_url', 'web/secure/base_url','admin/dashboard/enable_charts');
  • update site from https to non https:
    UPDATE core_config_data SET VALUE='0' WHERE  path IN ('web/secure/use_in_frontend', 'web/secure/use_in_adminhtml');
  • Clear all caches for activating new config:
    rm -rf /data/www/babyshopvnupdate/var/cache/*

Basic changes

turn debug mode and log in magento

Config Debug Mode:

  • in apache config
    • SetEnv MAGE_IS_DEVELOPER_MODE ⇒ Turn On Debug
    • Remove “SetEnv MAGE_IS_DEVELOPER_MODE” ⇒ Turn Off Debug
  • Edit in index.php:
    $_SERVER['MAGE_IS_DEVELOPER_MODE'] = True;
    ini_set('display_errors', '1');

Code to log Magento Information:

$info = __FILE__ . ': ' . __LINE__ . "\n";
$info.= 'Block "catalog.topnav" not found';
Mage::log($info, null, 'wp_custommenu.log');

Check the error log in files below:

  • var\log\system.log
  • var\log\exception.log
  • Error log record number: var\report\*

cache and ckeditor

  1. disable cache: System→Cache Management
  2. disable default use ckeditor: System→Configuration→Content Management

change layout and theme

  • change layout for all pages in code:
    app\design\frontend\base\default\template\page\
      1column.phtml, 2columns-right.phtml, 2columns-left.phtml, 3columns.phtml
  • change content of homepage in admin: Admin → CMS → Manage Pages → Homepage
  • change the theme: Admin → System → Configuration → 'Design' tab → Themes'
    • customize content of layout and template in page default
      base: app\design\frontend\base\default\
      update: app\design\frontend\default\f002\
    • customize skin in skin\frontend\default\f002\

custom country and city

directory_country
directory_country_region
SELECT `main_table`.*, `rname`.`name` FROM `directory_country_region` AS `main_table`
LEFT JOIN `directory_country_region_name` AS `rname` ON main_table.region_id = rname.region_id AND rname.locale = 'vi_VN' WHERE (main_table.country_id IN('AD', 'AE', 'AF', 'AG', 'AI', 'AL', 'AM', 'AN', 'AO', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AW', 'AX', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BL', 'BM', 'BN', 'BO', 'BR', 'BS', 'BT', 'BV', 'BW', 'BY', 'BZ', 'CA', 'CC', 'CD', 'CF', 'CG', 'CH', 'CI', 'CK', 'CL', 'CM', 'CN', 'CO', 'CR', 'CU', 'CV', 'CX', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'EH', 'ER', 'ES', 'ET', 'FI', 'FJ', 'FK', 'FM', 'FO', 'FR', 'GA', 'GB', 'GD', 'GE', 'GF', 'GG', 'GH', 'GI', 'GL', 'GM', 'GN', 'GP', 'GQ', 'GR', 'GS', 'GT', 'GU', 'GW', 'GY', 'HK', 'HM', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IM', 'IN', 'IO', 'IQ', 'IR', 'IS', 'IT', 'JE', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KP', 'KR', 'KW', 'KY', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'LY', 'MA', 'MC', 'MD', 'ME', 'MF', 'MG', 'MH', 'MK', 'ML', 'MM', 'MN', 'MO', 'MP', 'MQ', 'MR', 'MS', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NC', 'NE', 'NF', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NU', 'NZ', 'OM', 'PA', 'PE', 'PF', 'PG', 'PH', 'PK', 'PL', 'PM', 'PN', 'PR', 'PS', 'PT', 'PW', 'PY', 'QA', 'RE', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SD', 'SE', 'SG', 'SH', 'SI', 'SJ', 'SK', 'SL', 'SM', 'SN', 'SO', 'SR', 'ST', 'SV', 'SY', 'SZ', 'TC', 'TD', 'TF', 'TG', 'TH', 'TJ', 'TK', 'TL', 'TM', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'UM', 'US', 'UY', 'UZ', 'VA', 'VC', 'VE', 'VG', 'VI', 'VN', 'VU', 'WF', 'WS', 'YE', 'YT', 'ZA', 'ZM', 'ZW')) ORDER BY name ASC, default_name ASC

search module

  • query search:
    SELECT `count_table`.`category_id`, COUNT(DISTINCT count_table.product_id) AS `product_count` FROM `catalog_product_entity` AS `e`
     INNER JOIN `catalogsearch_result` AS `search_result` ON search_result.product_id=e.entity_id AND search_result.query_id='29'
     INNER JOIN `catalog_product_index_price` AS `price_index` ON price_index.entity_id = e.entity_id AND price_index.website_id = '1' AND price_index.customer_group_id = '3'
     INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id='1' AND cat_index.visibility IN(3, 4) AND cat_index.category_id='3'
     INNER JOIN `catalog_category_product_index` AS `count_table` ON count_table.product_id = e.entity_id WHERE (count_table.store_id = 1) AND (count_table.category_id IN ('10', '18', '8', '15', '12')) GROUP BY `count_table`.`category_id`

    → re-index data to fix bug search product:

  • search result in tables: catalogsearch_query, catalogsearch_result
  • index data in tables: catalog_category_product_index, catalogsearch_fulltext
  • refer code in: [app\code\core\Mage\Page\Block\Html\Footer.php]
    public function getCopyright()
    {
        if (!$this->_copyright) {
            $this->_copyright = Mage::getStoreConfig('design/footer/copyright');
        }
     
        return $this->_copyright;
    }
  • change in config: app\code\core\Mage\Page\etc\config.xml
  • change in admin: in system/custom variable → add variable design_footer_copyright and update in db

[page.xml]

<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
	<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
		<label>Page Footer</label>
		<action method="setElementClass"><value>bottom-container</value></action>
	</block>
	<block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
	<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
</block>

⇒ config childhtml of footer - config get information of footer [footer.xml]

<?php echo $this->getChildHtml() ?>
<address><?php echo $this->getCopyright() ?></address>

Google analytics

system/configuration/GoogleAPI

change number of products on row in catalog

  • Edit code app\code\core\Mage\Catalog\Block\Product\Abstract.php:
    protected $_defaultColumnCount = 3;
  • Edit layout config in all layouts with template=catalog/category/view.phtml:
    <action method="setColumnCount"><columns>3</columns></action>                    

config display products on homepage(new products or random products or category)

  • display random products:
    <reference name="content">
    <block type="catalog/product_list_random" template="catalog/product/list.phtml">
    	<action method="setNumProducts"><count>12</count></action>
    </block>    
    </reference>
  • display new products:
    <reference name="content">
    <block type="catalog/product_new" template="catalog/product/new.phtml">
    </block>    
    </reference>  

Enable/disable modules or extensions in magento

  1. Method1: Search module name in app/etc and config enable/disable it
  2. Method2: Or Check module in system/config and config enable/disable output of it

Config remove some information unused in billing

  • System/Config: Choose Customer/Config Customer Information, Edit:
    • Name And Address Optión:
      • Number of Lines in a Street Address:1
      • Show Tax/VAT Number: No
    • Address Template
  • Edit form for create new account in billing: template\checkout\onepage\billing.phtml

Go to “Nhóm Sản Phẩm” → Random Related Products to edit “Number of items to show”

Update all categories to isAnchor

UPDATE catalog_category_entity_int 
SET    VALUE = 1 
WHERE  attribute_id = (SELECT attribute_id 
                       FROM   eav_attribute 
                       WHERE  attribute_code = 'is_anchor' 
                       LIMIT  1); 

Update Manufacture

Research Manufacture database

SELECT attribute_id, entity_type_id, attribute_code FROM eav_attribute WHERE attribute_code="manufacture";
137	4	manufacture
 
SELECT option_id, VALUE FROM eav_attribute_option_value WHERE VALUE LIKE "%KIM%"
40	Kim Home
40	Kim Home
40	Kim Home
 
SELECT entity_id,NAME FROM catalog_product_flat_1 WHERE NAME LIKE "%KIM%";
1960	GỐI LÕM CARA KIM HOME
1955	GỐI ÔM CARA CHO BÉ 60x25cm KIM HOME
 
INSERT INTO `catalog_product_entity_int` (`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES ('4', '137', '0', '1960', '40') ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)--only chage parameter 40(manufacture Kim Home) and 1960(Product Name)
 
--list all products have manufacture with name like "%KIM HOME%"
SELECT catp.entity_type_id, catp.attribute_id, catp.entity_id, catflat.name, catp.value FROM `catalog_product_entity_int` AS catp  JOIN catalog_product_flat_1 AS catflat ON catp.`entity_type_id` = 4 AND catp.`attribute_id`=137 AND catp.`entity_id` = catflat.`entity_id` AND catflat.name LIKE "%KIM HOME%";
 
UPDATE `catalog_product_entity_int` AS catp, catalog_product_flat_1 AS catflat SET catp.value = 40 WHERE catp.`entity_type_id` = 4 AND catp.`attribute_id`=137 AND catp.`entity_id` = catflat.`entity_id` AND catflat.name LIKE "%KIM HOME%";

Update Manufacture from database:

  1. Step1: Check manufacture information with name “Kim Home” from database
    SELECT option_id, VALUE FROM eav_attribute_option_value WHERE VALUE LIKE "%KIM%"
    40	Kim Home
    40	Kim Home
    40	Kim Home

    ⇒ option_id = 40

  2. Step2: Update manufacture for all products with name like “%KIM HOME%” to manufacture value 40(Manufacture “Kim Home”)
    UPDATE `catalog_product_entity_int` AS catp, catalog_product_flat_1 AS catflat SET catp.value = 40 
    WHERE catp.`entity_type_id` = 4 AND catp.`attribute_id`=137 AND catp.`entity_id` = catflat.`entity_id` AND catflat.name LIKE "%KIM HOME%";
  3. Step3: Recheck
    SELECT catp.entity_type_id, catp.attribute_id, catp.entity_id, catflat.name, catp.value FROM 
    `catalog_product_entity_int` AS catp  JOIN catalog_product_flat_1 AS catflat ON catp.`entity_type_id` = 4 AND catp.`attribute_id`=137 AND catp.`entity_id` = catflat.`entity_id` AND catflat.name LIKE "%KIM HOME%";

Magento upgrade

upgrade with magento connect

Go to Admin panel → System → Magento Connect → Magento Connect Manager:

  • Step1: Click Check for Upgrades
  • Step2: Select Mage_All_Latest →

backup and upgrade for testing

  1. Step1: Backup and create new site
    mysqldump -u'root' -p babyshopvn > babyshopvnlatest.sql
    mysqladmin -p create babyshopvnupdate
    mysql -f --default-character-set=utf8 -u'root' -p babyshopvnupdate < babyshopvnlatest.sql
  2. Step2: Edit config for new shop: shoptest.babies.vnBold Text in /usr/local/apache/conf.d/babies.vn.conf
    <VirtualHost *:80>
        ServerName shoptest.babies.vn
        DocumentRoot "/data/www/babyshopvnupdate"
        SetEnv MAGE_IS_DEVELOPER_MODE "false"
        <Directory /data/www/babyshopvnupdate>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order Deny,Allow
            Allow from all
        </Directory>
        ErrorLog logs/babyshopvnupdate-error_log
        CustomLog logs/babyshopvnupdate-access_log common
    </VirtualHost>
  3. Step3: Edit /data/www/babyshopvnupdate/app/etc/local.xml from babyshopvn to babyshopvnupdate
  4. Step4: Update table core_config_data change base_url to http://shoptest.babies.vn
    • Query update
      mysql -u'root' -p babyshopvnupdate <<< "update core_config_data set value = 'http://shop.babies.vn/' where path in ('web/unsecure/base_url', 'web/secure/base_url','admin/dashboard/enable_charts');"
    • Clear all caches for activating new config:
      rm -rf /data/www/babyshopvnupdate/var/cache/*

Magento Email Configure

  1. Advanced/System/Mail Sending Settings
  2. General/Store Email Address
  3. Sales/Sales Emails: Send Order Email Copy To:[email protected], [email protected]
  4. You must sure that we can run cron command of magento

Magento and Wordpress

Performance

Magento relies a lot on its cache tools to get the best out of a website. This is due to several reasons, most notably the sheer amount of stylesheets and javascript libraries loading into the page, and a complex XML layout that involves a lot of querying behind the scenes.

Ideally each page on the website should only query and load in the appropriate content and libraries that the page needs. For example, a generic page might not need to load in a jQuery library or a contact form stylesheet.

Flexibility

Although Magento is one of the leading ecommerce frameworks, it has a fairly poor CMS and its limited fields prevent full customisable product and page templates. For instance, if a client wanted an editable carousel on the website homepage a WYSIWYG or an expensive yet ineffective module will be used.

I am a firm believer that all content on a CMS driven website should be editable via the CMS, from the sites logo to the navigation.

Time

Setting up and building a Magento website takes a lot of time and effort due to the complex XML layout system which requires multiple file changes to determine the appearance of a page. A change request to alter the websites appearance takes too much time which is ineffective if a bug fix is needed.

reports

Show reports

show log

SELECT log_visitor.visitor_id,http_referer,last_url_id,last_visit_at,INET_NTOA(remote_addr) FROM log_visitor LEFT JOIN log_visitor_info AS info ON info.visitor_id=log_visitor.visitor_id WHERE last_visit_at >= '2015-03-20' AND http_referer IS NOT NULL;
 
SELECT log_visitor.visitor_id,last_url_id,last_visit_at,COUNT(*),INET_NTOA(remote_addr) AS addr FROM log_visitor LEFT JOIN log_visitor_info AS info ON info.visitor_id=log_visitor.visitor_id WHERE last_visit_at LIKE '2015-03-20%' GROUP BY addr;
 
SELECT log_visitor.visitor_id,http_referer,last_url_id,last_visit_at,INET_NTOA(remote_addr) FROM log_visitor LEFT JOIN log_visitor_info AS info ON info.visitor_id=log_visitor.visitor_id WHERE last_visit_at LIKE '2015-03-20%' AND INET_NTOA(remote_addr)='115.73.43.228';

show products

Basic show products in products cache of magento:

  • Query to show products
    SELECT entity_id,name,price,special_price,url_path FROM catalog_product_flat_1  WHERE price > 0  ORDER BY name;

    ⇒ Filter all Group Products

  • export products to txt file
     mysql --default-character-set=utf8 -uroot -p babyshopvn <<< "SELECT entity_id,name,price,special_price,url_path,thumbnail FROM catalog_product_flat_1 where price > 0 ORDER BY entity_id;" > /tmp/products.txt
  • show short_description for products with exel query
    =CONCATENATE("select short_description from catalog_product_flat_1 where entity_id = ",$C4,";")
    =CONCATENATE("mysql --default-character-set=utf8 -uroot -p babyshopvn <<<  '",$I4,"' > ",$C4,".txt;")

    And copy all commands to bash file and run it

Show products with barcode:

  1. Check information of barcode attribute:
    SELECT attribute_id, entity_type_id, attribute_code, frontend_input, frontend_label FROM eav_attribute WHERE attribute_code='barcode';

    output:

    +--------------+----------------+----------------+----------------+----------------+
    | attribute_id | entity_type_id | attribute_code | frontend_input | frontend_label |
    +--------------+----------------+----------------+----------------+----------------+
    |          139 |              4 | barcode        | text           | barcode        |
    +--------------+----------------+----------------+----------------+----------------+

    attribute_id = 139

  2. Get all barcode informations:
    SELECT * FROM catalog_product_entity_varchar WHERE attribute_id=139 AND VALUE IS NOT NULL;
    +----------+----------------+--------------+----------+-----------+---------------+
    | value_id | entity_type_id | attribute_id | store_id | entity_id | VALUE         |
    +----------+----------------+--------------+----------+-----------+---------------+
    |    53852 |              4 |          139 |        0 |       718 | 8851989060422 |
    |    53860 |              4 |          139 |        0 |       155 | 8936006854205 |
    |    53868 |              4 |          139 |        0 |       157 | 8938500402357 |
    |    53876 |              4 |          139 |        0 |       713 | 78300058687   |
    +----------+----------------+--------------+----------+-----------+---------------+
  3. List all products with barcode not null:
    SELECT products.entity_id,att_products.value AS barcode,name,price,special_price,url_path,thumbnail FROM catalog_product_flat_1 AS products INNER JOIN catalog_product_entity_varchar AS att_products ON att_products.attribute_id = 139 AND products.entity_id = att_products.entity_id  AND att_products.value IS NOT NULL  WHERE price > 0 ORDER BY name;

    output:

    +-----------+---------------+--------------------------------------------+-------------+---------------+
    | entity_id | barcode       | name                                       | price       | special_price |
    +-----------+---------------+--------------------------------------------+-------------+---------------+
    |       157 | 8938500402357 | B▒NH S?A AGI 60ML                          |  25000.0000 |          NULL |
    |       713 | 78300058687   | B▒NH S?A PLAYTEX 200ML                     | 150000.0000 |          NULL |
    |       155 | 8936006854205 | QU?N L▒T D▒NG 1 L?N M▒U TR?NG( SET 5 C▒I ) |  13000.0000 |          NULL |
    |       718 | 8851989060422 | T?M G?I DNEE 380ML                         |  82000.0000 |          NULL |
    +-----------+---------------+--------------------------------------------+-------------+---------------+

Show products with categories:

  • show products
    SELECT entity_id,name,price,special_price,url_path,cat4.value FROM catalog_product_flat_1 AS flat1 LEFT JOIN (SELECT cat1.product_id, cat1.category_id, cat2.value FROM catalog_category_product AS cat1 LEFT JOIN catalog_category_entity_varchar AS cat2 ON cat1.category_id = cat2.entity_id AND cat2.attribute_id = 41 WHERE cat1.category_id = (SELECT MAX(cat3.category_id) FROM catalog_category_product AS cat3 WHERE cat1.product_id=cat3.product_id)) AS cat4 ON flat1.entity_id=cat4.product_id  WHERE price > 0  ORDER BY name;
  • export products to sql file
    mysql --default-character-set=utf8 -uroot -p babyshopvn <<< "SELECT entity_id,name,price,special_price,url_path,cat4.value FROM catalog_product_flat_1 as flat1 left join (select cat1.product_id, cat1.category_id, cat2.value from catalog_category_product as cat1 left join catalog_category_entity_varchar as cat2 on cat1.category_id = cat2.entity_id and cat2.attribute_id = 41 where cat1.category_id = (select max(cat3.category_id) from catalog_category_product as cat3 where cat1.product_id=cat3.product_id)) as cat4 on flat1.entity_id=cat4.product_id  WHERE price > 0  ORDER BY name;" > /tmp/products.txt

Show Categories of products

  • Show all categories of products
    SELECT cat1.product_id, cat2.value FROM catalog_category_product AS cat1 LEFT JOIN catalog_category_entity_varchar AS cat2 ON cat1.category_id = cat2.entity_id AND cat2.attribute_id = 41;
  • Show only parent categories
    SELECT cat1.product_id, cat1.category_id, cat2.value FROM catalog_category_product AS cat1 LEFT JOIN catalog_category_entity_varchar AS cat2 ON cat1.category_id = cat2.entity_id AND cat2.attribute_id = 41 WHERE cat1.category_id = (SELECT MIN(cat3.category_id) FROM catalog_category_product AS cat3 WHERE cat1.product_id=cat3.product_id);

Show all categories

  • show all categories
    SELECT entity_id, VALUE FROM catalog_category_entity_varchar WHERE store_id = 0 AND attribute_id = 41;
  • export all categories to categories.txt:
    mysql --default-character-set=utf8 -uroot -p babyshopvn <<< "select entity_id, value from catalog_category_entity_varchar where store_id = 0 and attribute_id = 41;" > /tmp/categories.txt

clear logs and reports,search queries

Truncate logs:

TRUNCATE TABLE log_customer;
TRUNCATE TABLE log_quote;
TRUNCATE TABLE log_summary;
TRUNCATE TABLE log_summary_type;
TRUNCATE TABLE log_url;
TRUNCATE TABLE log_url_info;
TRUNCATE TABLE log_visitor;
TRUNCATE TABLE log_visitor_info;
TRUNCATE TABLE log_visitor_online;

Truncate Reports:

TRUNCATE TABLE report_compared_product_index;
TRUNCATE TABLE report_event;
TRUNCATE TABLE report_viewed_product_aggregated_daily;
TRUNCATE TABLE report_viewed_product_aggregated_monthly;
TRUNCATE TABLE report_viewed_product_aggregated_yearly;
TRUNCATE TABLE report_viewed_product_index;

Truncate Search Queries:

TRUNCATE TABLE catalogsearch_query;
TRUNCATE TABLE catalogsearch_fulltext;
TRUNCATE TABLE catalogsearch_result;
php/magento.txt · Last modified: 2018/10/28 22:20 by admin