Table of Contents

Magento Ecommerce

refer: http://www.boostingecommerce.com/10-magento-front-end-development-best-practices
http://www.magentocommerce.com/wiki/
http://www.magentocommerce.com/knowledge-base
http://www.youtube.com/watch?v=r44z5OMHk6A
https://www.ebayopensource.org
http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento-architecture
http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-1-introduction-to-magento#5
http://www.alrayeswebsolutions.com/blog/e-commerce/block-caching-vs-page-caching-on-magento/
http://www.magentocommerce.com/wiki/2_-_magento_concepts_and_architecture/magento_database_diagram
http://www.magereverse.com/index/magento-database-diagram/version/1-7-0-0-beta
http://www.magentocommerce.com/wiki/import-export_and_data_manipulation/removing_products_through_the_database
http://www.magentocommerce.com/wiki/4_-_themes_and_template_customization/0_-_theming_in_magento/package
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table#custom_module_with_custom_database_table
http://inchoo.net/
sites: http://www.geeksucks.com/inspiration/25-awesome-online-store-built-with-magento.htm

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

http://example.com/catalog/category/view/id/25

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

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:

- view detail

Module customer

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

admin

base

refer: http://www.magentocommerce.com/knowledge-base/entry/magento-for-dev-part-4-magento-layouts-blocks-and-templates

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

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:

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>

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.vochi@gmail.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)

Refer: http://ultimento.com/wiki/blog/speed-up-magento-with-these-simple-admin-settings/
http://www.magentocommerce.com/knowledge-base/entry/understanding-magento-scalability-and-performance
http://www.magentocommerce.com/blog/category/performance/
http://www.magentocommerce.com/wiki/groups/168/optimising_your_web_stack_performance_for_magento

Remove some modules unused

Magento Block Cache

Cache some data don't change:

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

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

Basic changes

turn debug mode and log in magento

Config Debug Mode:

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:

cache and ckeditor

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

change layout and theme

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

[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

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

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

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:

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

refer: http://www.thetomorrowlab.com/2014/03/integrating-wordpress-magento-build-ecommerce-website/

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:

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 Categories of products

Show all categories

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;