Module Development Part 2 Magento 1 Stenik Group Ltd. Martin Grozdanov

Slides:



Advertisements
Similar presentations
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Advertisements

Sets, Dictionaries SoftUni Team Technical Trainers Software University
Programming Fundamentals (Extended)
Version Control Systems
Magento Basics Getting started developing for Magento
Auto Mapping Objects SoftUni Team Database Applications
Introduction to Entity framework
Databases basics Course Introduction SoftUni Team Databases basics
C# MVC Frameworks – ASP.NET
Web API - Introduction AJAX, Spring Data REST SoftUni Team Web API
Introduction to MVC SoftUni Team Introduction to MVC
Deploying Web Application
Thymeleaf and Spring Controllers
WordPress Introduction
PHP MVC Frameworks Course Introduction SoftUni Team Technical Trainers
PHP Fundamentals Course Introduction SoftUni Team Technical Trainers
C# Database Fundamentals with Microsoft SQL Server
Build a WordPress Site A Real Life Example: Create a Fully Functional WP Business Web Site from Scratch Building a WP Site SoftUni Team Technical Trainers.
Introduction to Entity Framework
ASP.NET Integration Testing
Mocking tools for easier unit testing
Parsing JSON JSON.NET, LINQ-to-JSON
JavaScript Applications
State Management Cookies, Sessions SoftUni Team State Management
EF Code First (Advanced)
PHP MVC Frameworks MVC Fundamentals SoftUni Team Technical Trainers
C# Databases Advanced with Microsoft SQL Server
Database Design and Rules
OOP Course - Virtual Trip
Spring Filters Spring Interceptors SoftUni Team Spring Interceptors
EF Relations Object Composition
Entity Framework: Code First
Parsing XML XDocument and LINQ
Data Definition and Data Types
Databases advanced Course Introduction SoftUni Team Databases advanced
MVC Architecture. Routing
Install and configure theme
Entity Framework: Relations
Fast String Manipulation
Array and List Algorithms
The Right Way Control Flow
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
MVC Architecture, Symfony Framework for PHP Web Apps
JavaScript Fundamentals
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Databases Advanced Course Introduction SoftUni Team Databases Advanced
Best Practices and Architecture
Best practices and architecture
Design & Module Development
Magento Basics part 2 Modules & Themes Stenik Group Ltd. Magento
Web Fundamentals (HTML and CSS)
WordPress Plugins Popular WP Plugins: Sliders, Forms, Contacts, SEO, Forum, Photo Gallery, e-Commerce WordPress Plugins SoftUni Team Technical Trainers.
Data Definition and Data Types
Multidimensional Arrays, Sets, Dictionaries
Extending functionality using Collections
ASP.NET Filters SoftUni Team ASP.NET MVC Introduction
Making big SPA applications
Manual Mapping and AutoMapper Library
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
C# Advanced Course Introduction SoftUni Team C# Technical Trainers
Exporting and Importing Data
JavaScript Fundamentals
CSS Transitions and Animations
Train the Trainers Course
Hibernate (JPA) Code First Entity Relations
Spring Data Advanced Querying
Version Control Systems
JavaScript: ExpressJS Overview
CSS Transitions and Animations
Iterators and Generators
Presentation transcript:

Module Development Part 2 Magento 1 Stenik Group Ltd. Martin Grozdanov <martin@stenik.bg> Software University http://softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 1

Last time Convention URLs’ Structure Design elements & Fallback Module Development - Basic Components © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 2

Table of Contents Set, Get & Save data in model Translations Blocks & Cache Admin Menu Admin Grid + Model Collection Model Create & Update via Admin 3 © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 3

Varien’s Magical Getters & Setters All Blocks and Models are extending Varien_Object Varien_Object contains $_data property - associative array getData(‘key’) and setData(‘key’, ‘value’) are used to manage the $_data Varien_Object contains Magical Getters & Setters which translates setFooBar(‘value’) to setData(‘foo_bar’, ‘value’) and getFooBar() to getData(‘foo_bar’) 4

Set Model Data & Save <?php … $model->setFirstname(‘John’); Model without data change does not save itself <?php … $model->setFooBar(‘barfoo’); $model->setFirstname(‘John’); $model->save(); ... 5

Translations Magento uses English => Lang mapping translates <?php … echo Mage::helper(‘myhelper’)->__(‘Text to translate’); ... Magento uses English => Lang mapping translates Translate mappings are located in several places. 1. Magento first checks the database for the text 2. If not there – checks theme’s translate.csv file 3. If not there – checks modules translate file. 6

Translations The DB translation mapping is located in the core_translate table. Not recommended to be used. Theme’s translation files are located in theme’s …/locale/<store_lang_code>/translate.csv For example …/locale/bg_BG/translate.csv Module’s translate file is located under app/locale/<store_lang_code>/<defined_file.csv> 7

Module Translate Definition Definition - In module’s config.xml in frontend/adminhtml … <translate> <modules> <SoftUni_Submission> <files> <default>SoftUni_Submission.csv</default> </files> </SoftUni_Submission> </modules> </translate> 8

Block Files Extend Mage_Core_Block_Abstract or Mage_Core_Block_Template (or other) Add your own methods which can be used in the template (if there is any) 9

How block cache works + setup If block can be cached – Magento cache’s it’s HTML Uses Cache Key to identify create or fetch the cache. Uses Cache Tags to clear the cache when needed. Setup: 1. Set cache lifetime using cache_lifetime data Number – Seconds FALSE – Forever NULL – No cache. Default. 2. Set Tags if you want invalidation. (cache_tags data) 3. Provide Cache Key info creating getCacheKeyInfo method. The method’s result shall be array of strings. 10

@see Mage_Cms ‘s /etc/adminhtml.xml Admin Menu Define the menu in module’s config.xml Define ACL for that menu. @see Mage_Cms ‘s /etc/adminhtml.xml 11

Admin controllers Must use the adminhtml frontName. Should have unique controller prefix. Should have _isAllowed method in the class The class should extend Mage_Adminhtml_Controller_Action 12

Admin – Creating Grid and Collection Create controller action Create Grid Container Block Create layout and use this block in the content area Create Model Collection Create Grid Block with columns Create gridAction if you want AJAX Reference: Adminhtml_Cms 13

What is registry Magento’s registry is global container for data for the current session. Usage: <?php … Mage::register(‘my_unique_key’, ‘value’); $value = Mage::registry(‘my_unique_key’); ... Registering the same key twice may cause error. 14

Admin – Create & Edit entities Create new and edit controller action. Register the object, so it can be used from the blocks Create Form Container Block Create Form Block Define them in the layout. Create save & delete actions Reference: Adminhtml_Cms 15

Event Bus – things you can do Dispatch event Register for event and process it’s data. Magento Events Cheat Sheet (1.9) - Nick Jones https://www.nicksays.co.uk/magento-events-cheat-sheet-1-9/ 16

© Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 17

Thank you 18

License This course (slides, examples, demos, videos, homework, etc.) is licensed under the "Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International" license 19 © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 19

Trainings @ Software University (SoftUni) Software University – High-Quality Education, Profession and Job for Software Developers softuni.bg Software University Foundation softuni.org Software University @ Facebook facebook.com/SoftwareUniversity Software University Forums forum.softuni.bg © Software University Foundation – http://softuni.org This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike license. 20