====== 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] Mage_Cms_Model cms_resource Mage_Cms_Model_Resource cms_mysql4 cms_page
cms_page_store
cms_block
cms_block_store
.........
==== 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]\\ Mage_Catalog_Model catalog_resource Mage_Catalog_Model_Resource catalog_resource_eav_mysql4 catalog_product_entity
catalog_category_entity
catalog_category_product
catalog_category_product_index
catalog_compare_item
catalog_product_website
.........................
=== 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]\\ standard Mage_Catalog catalog .............................. => 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_address_index * customer_address_view * 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/ ===== Magento layout, pages, blocks and links ===== 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 ......................................................... ......................................................... css/styles.css ......................................................... skin_jsjs/ie6.jslt IE 7 simplecheckout/cart_item_renderer groupedcheckout/cart_item_renderer_grouped configurablecheckout/cart_item_renderer_configurable top-container footer_list bottom-container css/print.cssmedia="print" ......................................................... jslib/ds-sleight.jslt IE 7 skin_jsjs/ie6.jslt IE 7 1 1 1 1 1 === 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] ..... ==== Default config for blocks in each pages ==== === [core.xml] === === CMS Pages: [cms.xml] === footer_links === Catalog Pages: [catalog.xml] === images/media/col_left_callout.jpg Our customer service is available 24/7. Call us at (555) 555-0123. checkout/cart ............................. ............................ ==== 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: skin_jsjs/fancybox/jquery.fancybox-1.3.4.js skin_jsjs/fancybox/jquery.easing-1.3.pack.js skin_jsjs/fancybox/jquery.mousewheel-3.0.6.pack.js jsjquery/noconflict.js js/fancybox/jquery.fancybox-1.3.4.css 12 right.reports.product.viewed right.reports.product.compared showcase ==== New module and update blocks config of each default pages ==== Example config for module ajax: jsjquery/noconflict.js skin_jsjs/script.js skin_jsjs/fancybox/jquery.fancybox-1.3.4.js skin_jsjs/fancybox/jquery.easing-1.3.pack.js skin_jsjs/fancybox/jquery.mousewheel-3.0.6.pack.js jsjquery/noconflict.js js/fancybox/jquery.fancybox-1.3.4.css => This module update below pages: * catalog_product_view: config default of catalog_product_view in layout\catalog.xml ................ ... ................ * catalog_category_default: config default of catalog_category_default in layout\catalog.xml ................ ... ................ ==== Config and edit display of left column from admin ==== - step1: config display template **callouts/left_col.phtml** in left column by editing the layout file **layout/catalog.xml** callouts_left_col ....................................... - step2: change content of template **callouts/left_col.phtml** to get content of block **callouts_left_col**: getLayout()->createBlock('cms/block')->setBlockId('callouts_left_col')->toHtml() ?> - 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
Liên hệ đặt hàng
  1. Phone: 0903 245 543
  2. Địa chỉ: 436/59/37 Cách Mạng tháng 8 , Phường 11, Quận 3, TPHCM  
  3. Xem bản đồ đường đi
  4. Email: sale@babies.vn
Giờ mở cửa
  1. Thứ 2 đến thứ 6:9:00-20:00
  2. Thứ 7,CN : vui lòng gọi điện thoại trước khi đến
- step4: update display chatango in left bar: ==== top.links Header link (Include Login/Logout) ==== * CMS Block to display links in **top.links.phtml**: * Config links in layout customer.xml: My Account10 Log Out100 Log In100 ===== 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] ..... true .... ===== 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 ==== * Refer: * http://www.yireo.com/tutorials/magento/magento-administration/665-disabling-magento-modules\\ * http://sleekd.com/magento/how-to-disable-modules-in-magento/ * remove modules in app\etc\modules\*.xml ==== 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 - 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] .............. singleton core/blockcache_observer customBlockCache - Add the implementation of event handler 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); } } } - Edit the implementation of event handler for shop.babies.vn 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 ==== - re-index data * in admin * manual: php shell/indexer.php reindexall - merger js and css: in admin: System/Config/Developer - 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] core_config_data
core_website
core_store
core_resource
core_cache
core_cache_tag
core_cache_option
{{root_dir}} {{root_dir}}/app {{app_dir}}/code {{app_dir}}/design {{app_dir}}/locale {{app_dir}}/etc {{root_dir}}/media {{root_dir}}/media/upload {{root_dir}}/skin {{var_dir}} {{var_dir}}/cache {{var_dir}}/session {{var_dir}}/tmp {{var_dir}}/pear {{var_dir}}/export
==== 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 === - disable cache: System->Cache Management - 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 === Edit copyright === * 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 === Edit footer === [page.xml] bottom-container => config childhtml of footer - config get information of footer [footer.xml] getChildHtml() ?>
getCopyright() ?>
=== 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**: 3 === config display products on homepage(new products or random products or category) === * display random products: 12 * display new products: * display categories: http://www.magentocommerce.com/wiki/groups/248/display_products_on_home_page === Enable/disable modules or extensions in magento === - Method1: Search module name in **app/etc** and config enable/disable it - 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 === Config related products for module RandomRelatedProducts === 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: - 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 - 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%"; - 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 === - 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 - Step2: Edit config for new shop: **shoptest.babies.vn****Bold Text** in **/usr/local/apache/conf.d/babies.vn.conf** ServerName shoptest.babies.vn DocumentRoot "/data/www/babyshopvnupdate" SetEnv MAGE_IS_DEVELOPER_MODE "false" Options Indexes FollowSymLinks MultiViews AllowOverride all Order Deny,Allow Allow from all ErrorLog logs/babyshopvnupdate-error_log CustomLog logs/babyshopvnupdate-access_log common - Step3: Edit /data/www/babyshopvnupdate/app/etc/local.xml from **babyshopvn** to **babyshopvnupdate** - 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 ==== - Advanced/System/Mail Sending Settings - General/Store Email Address - Sales/Sales Emails: Send Order Email Copy To:anh.vochi@gmail.com, tranvungoctram@gmail.com - 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: * 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: - 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** - 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 | +----------+----------------+--------------+----------+-----------+---------------+ - 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;