Magento Indexers Ivan Chepurnyi Magento Trainer / Lead Developer.

Slides:



Advertisements
Similar presentations
09/04/2015Unit 2 (b) Back-Office processes Unit 2 Assessment Criteria (b) 10 marks.
Advertisements

Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
Computer Monitoring System for EE Faculty By Yaroslav Ross And Denis Zakrevsky Supervisor: Viktor Kulikov.
VBA Modules, Functions, Variables, and Constants
Introduction to Structured Query Language (SQL)
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Chapter 9: Creating Database Conventions & Standards MCITP Administrator: Microsoft SQL Server 2005 Database Server Infrastructure Design Study Guide (70-443)
Empowering EPrints Search with Xapian
Session 5: Working with MySQL iNET Academy Open Source Web Development.
C H A P T E R 4 Designing Database E-Commerce Hassanin M. Al-Barhamtoshy
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
Access 2013 Microsoft Access 2013 is a database application that is ideal for gathering and understanding data that’s been collected on just about anything.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
Pasewark & Pasewark 1 Access Lesson 3 Creating Queries Microsoft Office 2007: Introductory.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
3 Copyright © 2010, Oracle. All rights reserved. Product Data Hub: PIM Functional Training Program Setup Workbench Fundamentals.
Description and exemplification use of a Data Dictionary. A data dictionary is a catalogue of all data items in a system. The data dictionary stores details.
DAY 14: ACCESS CHAPTER 1 RAHUL KAVI October 8,
CSC314 DAY 8 Introduction to SQL 1. Chapter 6 © 2013 Pearson Education, Inc. Publishing as Prentice Hall SQL OVERVIEW  Structured Query Language  The.
Using the Kentico CMS API Thom Robbins Bryan Soltis
Access Lessons 1, 2 and 3 ©2009 M and K Solutions, LLC – All Rights Reserved.
In this session, you will learn to: Create and manage views Implement a full-text search Implement batches Objectives.
Now your store is installed and your configuration settings done, it's time to the heart of your site: the catalog to go up. The catalog is the most important.
Varnish Cache and its usage in the real world Ivan Chepurnyi Owner EcomDev BV.
Core LIMS Training: Entering Experimental Data – Simple Data Entry.
MIKADO – Generation of ISO – SeaDataNet metadata files
Business rules.
A Reusable Framework for Automated Record Creation and Population
British Library Document Supply Service (BLDSS) API
Project Management: Messages
EF Code First (Advanced)
North East Fasteners ERP V1.0
CCS Engineering Tools The tools are used help development and debugging of VLT SW control applications This presentation will provide a general view of.
GO! with Microsoft Office 2016
Sample Registration – Batch Reg
MVC Architecture, Symfony Framework for PHP Web Apps
Oracle Subledger Accounting
Single Sample Registration
SCC P2P – Collaboration Made Easy Contract Management training
Introduction to CodeIgniter (CI)
Web Software Model CS 4640 Programming Languages for Web Applications
Views, Stored Procedures, Functions, and Triggers
GO! with Microsoft Access 2016
Introduction To Codeigniter
Making Magento flying like a rocket
PIC + TransNet.
Microsoft Access Illustrated
Introduction With TimeCard users can tag SharePoint events with information that converts them into time sheets. This way they can report.
test slide
5.8 Presentation.
ALEPH Version 22 Beginning Cataloging
…and web frameworks in general
IBM Kenexa BrassRing on Cloud Responsive Apply: Gateway Questionnaire Configuration April 2017.
ISC440: Web Programming 2 Server-side Scripting PHP 3
Patricia Training - Financial
CIS16 Application Programming with Visual Basic
Topic 1: Problem Solving
Active server pages (ASP.NET)
Spreadsheets, Modelling & Databases
…and web frameworks in general
HP Quality Center 10.0 The Test Plan Module
Database Systems: Design, Implementation, and Management Tenth Edition
Databases This topic looks at the basic concept of a database, the key features and benefits of a Database Management System (DBMS) and the basic theory.
Patricia Training - Financial
PCP – IP Practice.
SQL – Application Persistence Design Patterns
Assignment 3 Querying and Maintaining a Database
Presentation transcript:

Magento Indexers Ivan Chepurnyi Magento Trainer / Lead Developer

Magento Developers Meetup Agenda Overview of Indexes Functionality Creation of own indexes Magento Developers Meetup

Magento Developers Meetup Let Imagine… … that Magento doesn’t have indexes: The prices in product list are calculated on the fly depending on catalog rules, tier prices for customer groups Stock availability for configurable and bundle products can be calculated only after loading the product collection Layered navigation data is build in real-time for product attributes information Anchor categories recursively collects subcategories for filtering product list Magento Developers Meetup

It’s all about performance… The main goal is minimizing amount of operations to display products to a customer Magento Developers Meetup

Magento Developers Meetup Definitions Indexed Data Aggregated data for entity representation on the frontend lists. Indexer Generates index data on event or manual by process. Index Event The moment when entity or related to it information is changed and that affects its index data. Index Process Wrapper for indexer and contains information about its mode and status Main Controller Forwards events to Index Process Magento Developers Meetup

Magento Developers Meetup Index Workflow Event Main Controller Event Events Manual Invoke Process Indexer Indexed Data Magento Developers Meetup

Magento Developers Meetup Event Types Save When indexed entity or related to it information was changed Delete When indexed entity or related to it one was deleted Mass Update When batch of entities was updated. (Update Attributes on Product Grid) Magento Developers Meetup

Magento Developers Meetup Observed Entities Indexed Entities Product Product Inventory Category Tag Entities Scope Customer Group Website Store Group Store View Magento Developers Meetup

Magento Developers Meetup Index Process Available Statuses Pending Indicates that indexer is up to date Running Index currently in process of full rebuilding index data. Require Reindex Status for notifying admin user, that index is not up to date and should be rebuild. Magento Developers Meetup

Magento Developers Meetup Index Process Indexing Modes Real-time Manual Update Index Data Event Event Require Reindex Magento Developers Meetup

Magento Developers Meetup Indexer Flow Match Event Main Controller Index Process Register Event Data Reindex Data Magento Developers Meetup

Mage_Index Module Main Controller Process Indexer Base Mage_Index_Model_Indexer Process Mage_Index_Model_Process Indexer Base Mage_Index_Model_Indexer_Abstract Magento Developers Meetup

… Indexers Modularity Mage_Index_Model_Indexer_Abstract Index Module Mage_Index_Model_Indexer_Abstract Catalog Module Mage_Catalog_Model_Product_Indexer_Eav Mage_Catalog_Model_Product_Indexer_Flat Mage_Catalog_Model_Product_Indexer_Price Inventory Module Mage_CatalogIndex_Model_Indexer_Stock … Magento Developers Meetup

Indexer Structure Model Resource Model Mage_Index_Model_Indexer_Abstract Resource Model Mage_Index_Model_Mysql4_Abstract Matches event data and runs appropriate method in resource model for re-indexing Works directly with database for generation of the indexed data. Usually all the data operated via MySQL queries. Magento Developers Meetup

What can you use? Mage_Index_Model_Indexer getProcessByCode($indexerCode) getProcessCollection() processEntityAction($entity, $entityType, $eventType) Mage_Index_Model_Process reindexAll() reindexEverything() setMode($mode) Magento Developers Meetup

Magento Developers Meetup What you shouldn’t do… Invoke reindexAll method from index model/resource model, because it is better to let admin user know when the index was rebuild. Process entity events directly with indexer, instead of passing data through the main controller. You never know which index may depend on this event. Magento Developers Meetup

Magento Developers Meetup Creating own indexer Defining indexer in configuration Designing index data table Implementing model Implementing resource model Applying index on the frontend Magento Developers Meetup

Magento Developers Meetup Featured Products There is easier way to create featured products functionality, but it is a simple example on what should be done for creation own indexer. Magento Developers Meetup

Defining index in configuration etc/config.xml <config> <!-- …. module configurtaions --> <global> <index> <indexer> <featured_products> <model>your_module/indexer_featured</model> </featured_products> </indexer> </index> </global> </config> Indexer Code Indexer Model Magento Developers Meetup

Designing index data table Adding new attribute to catalog product entity called is_featured Creating table that will contain product ids of products that are marked as featured products. Magento Developers Meetup

Designing index data table Attribute Code Setup Script $this->addAttribute('catalog_product', 'is_featured', array( 'type' => 'int', 'label' => 'Is featured', 'input' => 'select', 'source' => 'eav/entity_attribute_source_boolean', 'user_defined' => false, 'required' => false )); Yes/No Dropdown Magento Developers Meetup

Designing index data table Setup Script Table Alias $table = new Varien_Db_Ddl_Table(); $table->setName($this->getTable(‘module/featured')); $table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array( 'unsigned' => true, 'nullable' => false, 'primary' => true )); $this->getConnection()->createTable($table); Table Column Magento Developers Meetup

Designing index data table Setup Script Table Alias $table = new Varien_Db_Ddl_Table(); $table->setName($this->getTable(‘module/featured')); $table->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 11, array( 'unsigned' => true, 'nullable' => false, 'primary' => true )); $this->getConnection()->createTable($table); Table Column Magento Developers Meetup

Magento Developers Meetup Implementing Model Defining Matching Events class Your_Module_Model_Indexer_Featured extends Mage_Index_Model_Indexer_Abstract { protected $_matchedEntities = array( Mage_Catalog_Model_Product::ENTITY => array( Mage_Index_Model_Event::TYPE_SAVE, Mage_Index_Model_Event::TYPE_MASS_ACTION ) ); } Entity Type Event Types Event Type Magento Developers Meetup

Magento Developers Meetup Implementing Model Defining Indexer Resource Model class Your_Module_Model_Indexer_Featured extends Mage_Index_Model_Indexer_Abstract { // … other code protected function _construct() $this->_init(‘your_module/indexer_featured'); } Resource model Magento Developers Meetup

Implementing Model Defining Indexer Information class Your_Module_Model_Indexer_Featured extends Mage_Index_Model_Indexer_Abstract { // … other code public function getName() return Mage::helper(‘your_module')->__('Featured Product'); } public function getDescription() return Mage::helper(‘‘your_module')->__('Indexes something'); Indexer Name in the admin Indexer Description in the admin Magento Developers Meetup

Implementing Model Register Event for Processing class Your_Module_Model_Indexer_Featured extends Mage_Index_Model_Indexer_Abstract { // … other code protected function _registerEvent(Mage_Index_Model_Event $event) /* @var $entity Mage_Catalog_Model_Product */ $entity = $event->getDataObject(); if ($entity->dataHasChangedFor('is_featured')) { $event->setData('product_id', $entity->getId()); } elseif ($entity->getAttributesData()) { $attributeData = $entity->getAttributesData(); if (isset($attributeData['is_featured'])) { $event->setData('product_ids', $entity->getProductIds()); } Product Save Registering Mass Action Registering Magento Developers Meetup

Implementing Model Processing Event class Your_Module_Model_Indexer_Featured extends Mage_Index_Model_Indexer_Abstract { // … other code protected function _processEvent(Mage_Index_Model_Event $event) if ($event->getData('product_id') || $event->getData('product_ids')) { $this->callEventHandler($event); } Calling processor in resource model Entity Type Event Type catalogProductSave($event) catalogProductMassAction($event) Magento Developers Meetup

Implementing Resource Model Define resource connection class Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract { protected function _construct() $this->_setResource(‘your_module'); } Your module resource prefix Magento Developers Meetup

Implementing Resource Model Indexing Method class Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract { // … other code protected function _reindexEntity($productId = null) $select = $this->_getReadAdapter()->select(); /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ $attribute = Mage::getSingleton('eav/config') ->getAttribute('catalog_product', 'is_featured'); $select->from($attribute->getBackendTable(), 'entity_id') ->where('value = ?', 1) ->where('attribute_id = ?', $attribute->getId()); Retrieving only featured product ids Magento Developers Meetup

Implementing Resource Model Indexing Method If it is partial re-index, then delete only related indexed data if ($productId !== null) { if (!is_array($productId)) { $productId = array($productId); } $select->where('entity_id IN(?)', $productId); $this->_getWriteAdapter()->delete( $this->getTable(‘your_module/featured'), array( 'product_id IN(?)' => $productId ) ); } else { $this->_getWriteAdapter()->truncate($this->getTable(‘your_module/featured')); Otherwise clear all indexed data Magento Developers Meetup

Implementing Resource Model Fulfill index data from select we created before Indexing Method $sqlStatement = $select->insertIgnoreFromSelect( $this->getTable(‘your_module/featured'), array('product_id') ); $this->_getWriteAdapter()->query($sqlStatement); } Magento Developers Meetup

Implementing Resource Model Handling Events class Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract { // … other code public function reindexAll() $this->_reindexEntity(); } Full index re-build Magento Developers Meetup

Implementing Resource Model Reindexing Events class Your_Module_Model_Mysql4_Indexer_Featured extends Mage_Index_Model_Mysql4_Abstract { // … other code public function catalogProductSave($event) $this->_reindexEntity($event->getData('product_id')); } public function catalogProductMassAction($event) $this->_reindexEntity($event->getData('product_ids')); Single Save Product Event Mass Save Product Event Magento Developers Meetup

Applying Index for the frontend Observing and event catalog_product_collection_apply_limitations_after Joining index table to product collection select Create sub-select filter for collection Magento Developers Meetup

Magento Developers Meetup Liked it? Checkout our advanced training programs: http://www.ecomdev.org/magento- development-training-programs/advanced Follow our blog posts: http://www.ecomdev.org/blog Magento Developers Meetup

Questions?