\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Abdellatif EL MIZEB (latmiz)} \pdfinfo{ /Title (magento-2.pdf) /Creator (Cheatography) /Author (Abdellatif EL MIZEB (latmiz)) /Subject (Magento 2 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{3F2875} \definecolor{LightBackground}{HTML}{F3F1F6} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Magento 2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Abdellatif EL MIZEB (latmiz)} via \textcolor{DarkBackground}{\uline{cheatography.com/34770/cs/10914/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Abdellatif EL MIZEB (latmiz) \\ \uline{cheatography.com/latmiz} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 21st February, 2017.\\ Updated 21st February, 2017.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-cogs\}\} Design Patterns In Magento}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Model View Controller Pattern (MVC)}}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Design pattern where business, presen​tation and coupling logic are separated} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Front Controller Pattern}}} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Makes sure that there is one and only one point of entry. All requests are invest​igated, routed to the designated controller and then processed accord​ingly to the specif​ication} \tn % Row Count 9 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Factory Pattern}}} \tn % Row Count 10 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Respon​sible of factor​izing (insta​nti​ating) classes} \tn % Row Count 12 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Sing​leton Pattern}}} \tn % Row Count 13 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Checks the whether this class has already been instan​tiated before, this results in a shared instance.} \tn % Row Count 16 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Registry Pattern}}} \tn % Row Count 17 (+ 1) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{Internal registry: a global scoped container for storing data} \tn % Row Count 19 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Prot​otype Pattern}}} \tn % Row Count 20 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{It defines that instances of classes can retrieve a specific other class instance depending on its parent class (the prototype)} \tn % Row Count 23 (+ 3) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Object Pool Pattern}}} \tn % Row Count 24 (+ 1) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{A box with objects so that they do not have to be allocated and destroyed over and over again} \tn % Row Count 26 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Iterator Pattern}}} \tn % Row Count 27 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{The iterator pattern defines that there is a shared way to iterate over a container with objects} \tn % Row Count 29 (+ 2) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Lazy Loading Pattern}}} \tn % Row Count 30 (+ 1) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-cogs\}\} Design Patterns In Magento (cont)}} \tn % Row 17 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{Lazy loading ensures that loading data is delayed until the point when it is actually needed} \tn % Row Count 2 (+ 2) % Row 18 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Service Locator Pattern}}} \tn % Row Count 3 (+ 1) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The service locator pattern abstracts away the retrieval of a certain service. This allows for changing the service without breaking anything} \tn % Row Count 6 (+ 3) % Row 20 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Module Pattern}}} \tn % Row Count 7 (+ 1) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{An implem​ent​ation of the module pattern would make sure that each element can be removed or swapped} \tn % Row Count 10 (+ 3) % Row 22 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Observer Pattern}}} \tn % Row Count 11 (+ 1) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{By defining observers (or listen​ers), extra code can be hooked which will be called upon as the observed event fires} \tn % Row Count 14 (+ 3) % Row 24 \SetRowColor{white} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-tags\}\} {\bf{Proxy Pattern}}} \tn % Row Count 15 (+ 1) % Row 25 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\{\{fa-hand-o-right\}\}Provide a surrogate or placeholder for another object to control access to it.\{\{nl\}\}\{\{fa-hand-o-right\}\}Use an extra level of indirection to support distributed, controlled, or intelligent access.\{\{nl\}\}\{\{fa-hand-o-right\}\}Add a wrapper and delegation to protect the real component from undue complexity.} \tn % Row Count 22 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} MODULE.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{A component declares itself (that is, defines its name and existence) in the {\bf{module.xml}} file, located in the Magento install directory at {\bf{\textless{}ComponentName\textgreater{}/etc/}}} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\textless{}?xml version="1.0"?\textgreater{}\{\{nl\}\}\textless{}config \seqsplit{xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"} \seqsplit{xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module}.xsd"\textgreater{}\{\{nl\}\}\textless{}module \seqsplit{name="Vendor\_ComponentName"} setup\_version="2.0.0"/\textgreater{}\{\{nl\}\}\textless{}sequence\textgreater{}\textless{}module name="Magento\_Sales"/\textgreater{}\textless{}/sequence\textgreater{}\{\{nl\}\}\textless{}/config\textgreater{}`} \tn % Row Count 11 (+ 7) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} CONFIG.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Used to configure module. The responsibilities of the {\bf{config.xml}} configuration file used in earlier versions of Magento is now divided between several files, located in various module directories.} \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example}}} \tn % Row Count 5 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}config \seqsplit{xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"} \seqsplit{xsi:noNamespaceSchemaLocation="urn:magento:module:Magento\_Store:etc/config}.xsd"\textgreater{}\textless{}default\textgreater{}\{\{nl\}\}\textless{}customsetting\textgreater{}\textless{}general\textgreater{}\textless{}enable\textgreater{}1\textless{}/enable\textgreater{}\textless{}title\textgreater{}Module Title\textless{}/title\textgreater{}\textless{}/general\textgreater{}\{\{nl\}\}\textless{}/customsetting\textgreater{}\textless{}/default\textgreater{}\textless{}/config\textgreater{}`} \tn % Row Count 11 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} DI.XML File}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{What case we use di.xml ?}} & \{\{fa-bolt\}\}We can use di.xml for (rewrite) preference of a particular class. \tn % Row Count 4 (+ 4) % Row 1 \SetRowColor{white} & \{\{fa-bolt\}\}We can send a new or replace the existing class arguments. \tn % Row Count 7 (+ 3) % Row 2 \SetRowColor{LightBackground} & \{\{fa-bolt\}\}Use plugins to do some stuff before, after and around a function \tn % Row Count 11 (+ 4) % Row 3 \SetRowColor{white} & \{\{fa-bolt\}\}By using virtua​lTypes creating a sub-class of another class. \tn % Row Count 15 (+ 4) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example for Prefer​ence}}} \tn % Row Count 16 (+ 1) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\textless{}p​ref​erence for="Ma​gen​to​\textbackslash{}Cus​tom​er​\textbackslash{}Api​\textbackslash{}Ad​dre​ssR​e \seqsplit{po​sit​ory​Int​erf​ace​"} type="M​age​nto​\textbackslash{}Cu​sto​mer​\textbackslash{}Mo​del​\textbackslash{}Re​sou​r ce​Mod​el​\textbackslash{}Add​res​sRe​pos​ito​ry" /\textgreater{}`} \tn % Row Count 21 (+ 5) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Above code, When someone asks to instan​tiate a Magent​o\textbackslash{}C​ust​ome​r\textbackslash{}A​pi​\textbackslash{}Add​res​sRe​pos​ito​ryI​nte​rface it will instan​tiate a Magent​o\textbackslash{}C​ust​ome​r\textbackslash{}M​ode​l\textbackslash{}R​eso​urc​eMo​del​\textbackslash{}Ad​dre​ ssR​epo​sitory object (the type attrib​ute).} \tn % Row Count 27 (+ 6) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example for Argume​nts}}} \tn % Row Count 28 (+ 1) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}type name="M​age​nto​\textbackslash{}Cu​sto​mer​\textbackslash{}Mo​del​\textbackslash{}Re​sou​r ce​Mod​el​\textbackslash{}Gro​up" shared​="fa​lse​"\textgreater{} \textless{}ar​gum​ent​s\textgreater{} \textless{}ar​gument \seqsplit{name="g​rou​pMa​nag​eme​nt"} xsi:ty​pe=​"​obj​ect​"​\textgreater{}Ma​gen​to​\textbackslash{}Cus​tom​er​\textbackslash{} Api​\textbackslash{}Gr​oup​Man​age​men​tIn​ter​fac​e\textbackslash{}P​rox​y\textless{} /​arg​ume​nt\textgreater{} \textless{}/a​rgu​men​ts\textgreater{} \textless{}/t​ype​\textgreater{}`} \tn % Row Count 36 (+ 8) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} DI.XML File (cont)}} \tn % Row 9 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{In the above code, We are sending object as an argument, we are saying system to insert {\bf{"P​rox​y"}} class as an object with the name of groupM​ana​gement. Also we can use Arguments for replacing the existing argument too.} \tn % Row Count 5 (+ 5) % Row 10 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example for Plugin}}} \tn % Row Count 6 (+ 1) % Row 11 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}type name="M​age​nto​\textbackslash{}Cu​sto​mer​\textbackslash{}Mo​del​\textbackslash{}Re​sou​r ce​Mod​el​\textbackslash{}Vis​ito​r"\textgreater{} \textless{}plugin \seqsplit{name="c​ata​log​Log​"} type="M​age​nto​\textbackslash{}Ca​tal​og​\textbackslash{}Mod​el​\textbackslash{}Plu​gin​\textbackslash{} Lo​g" /\textgreater{} \textless{}/t​ype​\textgreater{}`} \tn % Row Count 11 (+ 5) % Row 12 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{In the above code , public function clean(​\$ob​ject) in visitor class is called after public function \seqsplit{afterC​lea​n(V​isitor} \$subject, \seqsplit{\$logRe​sou​rce​Model)} which is in Log class.} \tn % Row Count 15 (+ 4) % Row 13 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example for Virtual Types}}} \tn % Row Count 16 (+ 1) % Row 14 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\textless{}vi​rtu​alType \seqsplit{name="o​urV​irt​ual​Typ​eNa​me"} type="P​uls​est​orm​\textbackslash{}Tu​tor​ial​Vir​tua​lTy​pe​\textbackslash{}Mod​el​\textbackslash{}Arg​u me​nt1​"\textgreater{} \textless{}/v​irt​ual​Typ​e\textgreater{}`} \tn % Row Count 20 (+ 4) % Row 15 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Creating a virtual type is sort of like creating a sub-class for an existing class. With virtual types, the only behavior you can change in your virtual sub-class is which depend​encies are injected.} \tn % Row Count 25 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.52 cm} x{4.48 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} EVENTS.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{Custom events can be dispatched by simply passing in a unique event name to the event manager when you call the dispatch function. The unique event name is referenced in your module's {\bf{even​ts.x​ml}} file where you specify which observers will react to that event.} \tn % Row Count 6 (+ 6) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\emph{The observer xml element has the following properties:}}} \tn % Row Count 8 (+ 2) % Row 2 \SetRowColor{LightBackground} {\bf{name (required)}}\{\{noshy\}\} & The name of the observer for the event definition \tn % Row Count 11 (+ 3) % Row 3 \SetRowColor{white} {\bf{instance (required)}}\{\{noshy\}\} & The fully qualified class name of the observer \tn % Row Count 14 (+ 3) % Row 4 \SetRowColor{LightBackground} {\bf{disabled}}\{\{noshy\}\} & Determines whether this observer is active or not. Default value is false \tn % Row Count 18 (+ 4) % Row 5 \SetRowColor{white} {\bf{shared}}\{\{noshy\}\} & Etermines the lifestyle of the class. Default is false \tn % Row Count 21 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\bf{Exam​ple}}} \tn % Row Count 22 (+ 1) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\textless{}event name="my\_module\_event\_before"\textgreater{}\{\{nl\}\}\textless{}observer \seqsplit{name="m​yOb​ser​ver​Nam​e"} instan​ce=​"​MyC​omp​any​\textbackslash{}My​Mod​ule​\textbackslash{}Ob​ser​v er​\textbackslash{}My​Obs​erv​er" /\textgreater{}\{\{nl\}\}\textless{}/event\textgreater{}`} \tn % Row Count 27 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} ACL.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{file is where we define our module access control list resources. Access control list resources are visible under the Magento admin System | Permissions | User Roles area, when we click on the Add New Role button.} \tn % Row Count 5 (+ 5) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example}}} \tn % Row Count 6 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}?xml version="1.0"?\textgreater{}\{\{nl\}\}\textless{}config \seqsplit{xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"} \seqsplit{xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl}.xsd"\textgreater{}\{\{nl\}\}\textless{}acl\textgreater{}\textless{}resources\textgreater{}\textless{}resource id="Magento\_Backend::admin"\textgreater{}\{\{nl\}\}\textless{}resource \seqsplit{id="Maxime\_Jobs::job\_head"} title="Jobs" sortOrder="100" \textgreater{} \textless{}resource \seqsplit{id="Maxime\_Jobs::department"} title="Departments" sortOrder="10"\textgreater{}\textless{}resource \seqsplit{id="Maxime\_Jobs::department\_save"} title="Save Department" sortOrder="10" /\textgreater{}\textless{}resource \seqsplit{id="Maxime\_Jobs::department\_delete"} title="Delete Department" sortOrder="20" /\textgreater{}\textless{}/resource\textgreater{}\textless{}/resource\textgreater{}\{\{nl\}\}\textless{}/resource\textgreater{}\textless{}/resources\textgreater{}\textless{}/acl\textgreater{}\{\{nl\}\}\textless{}/config\textgreater{}`} \tn % Row Count 19 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} SYSTEM.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{The {\bf{system.xml}} is a configuration file which is used to create configuration fields in Magento 2 System Configuration. You will need this if your module has some settings which the admin needs to set} \tn % Row Count 5 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.04 cm} x{4.96 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} MENU.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{A {\bf{menu.xml}} file is a collection of \textless{}add/\textgreater{} nodes. Each of these nodes adds a Menu Item to Magento's backend} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example}}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}config \seqsplit{xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"} \seqsplit{xsi:noNamespaceSchemaLocation="urn:magento:module:Magento\_Backend:etc/menu}.xsd"\textgreater{}\{\{nl\}\}\textless{}menu\textgreater{}\textless{}add \seqsplit{id="Example\_MenuTutorial::my\_menu\_example"} title="Title Example" \seqsplit{module="Example\_MenuTutorial"} sortOrder="9999" \seqsplit{resource="Magento\_Backend::content"} /\textgreater{}\textless{}/menu\textgreater{}\{\{nl\}\}\textless{}/config\textgreater{}`} \tn % Row Count 11 (+ 7) % Row 3 \SetRowColor{white} {\bf{id}}\{\{nobreak\}\} & Attribute defines a unique identifier for this node. By convention, (but not required) this should the the name of the module \tn % Row Count 17 (+ 6) % Row 4 \SetRowColor{LightBackground} {\bf{title}}\{\{nobreak\}\} & Attribute controls the text an end users sees for the Menu Item \tn % Row Count 20 (+ 3) % Row 5 \SetRowColor{white} {\bf{module}}\{\{nobreak\}\} & Attribute should match the current module \tn % Row Count 22 (+ 2) % Row 6 \SetRowColor{LightBackground} {\bf{sortOrder}}\{\{nobreak\}\} & Attribute controls how this Menu Item is sorted with the other Menu Items in the system \tn % Row Count 26 (+ 4) % Row 7 \SetRowColor{white} {\bf{resource}}\{\{nobreak\}\} & attribute defines the ACL rule a user must have in order to access this Menu Item \tn % Row Count 30 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} WIDGET.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{The file that is responsible for widgets in Magento is placed in {\bf{{[}module\_dir{]}/etc/widget.xml}}} \tn % Row Count 2 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-file-code-o\}\} WEBAPI.XML File}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{The {\bf{webapi.xml}} is used to configure access rights and API Interface which specify method that will be used.} \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{{\bf{Example}}} \tn % Row Count 4 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`\textless{}?xml version="1.0"?\textgreater{}\{\{nl\}\}\textless{}routes \seqsplit{xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"} \seqsplit{xsi:noNamespaceSchemaLocation="urn:magento:module:Magento\_Webapi:etc/webapi}.xsd"\textgreater{}\{\{nl\}\}\textless{}route \seqsplit{url="/V1/hello/name/:name"} method="GET"\textgreater{}\{\{nl\}\}\textless{}service class="Inchoo\textbackslash{}Hello\textbackslash{}Api\textbackslash{}HelloInterface" method="name"/\textgreater{}\textless{}resources\textgreater{}\{\{nl\}\}\textless{}resource ref="anonymous"/\textgreater{}\{\{nl\}\}\textless{}/resources\textgreater{}\textless{}/route\textgreater{}\textless{}/routes\textgreater{}`} \tn % Row Count 12 (+ 8) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Resource tag defines what resources user needs to have to be able to access this api call. Possible options are self, anonymous or Magento resource like {\bf{Magento\_Catalog::products}} or {\bf{Magento\_Customer::group}}} \tn % Row Count 17 (+ 5) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-check-square-o\}\} Magento 2 Modes}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{p{8.4cm}}{\vspace{1px}\centerline{\includegraphics[width=5.1cm]{/web/www.cheatography.com/public/uploads/latmiz_1487203375_images.png}}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{4.16 cm} x{3.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-terminal\}\} Command line}} \tn % Row 0 \SetRowColor{LightBackground} {\bf{Cache Management}} & {\bf{Commands}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} {\emph{Clear all caches:}} & php magento cache:clean \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} {\emph{Clearing a single cache:}} & php magento cache:clean config \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} {\emph{Flush all caches:}} & php magento cache:flush \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} {\emph{Flushing a single cache:}} & php magento cache:flush config \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} {\bf{Index Management}} & {\bf{Commands}} \tn % Row Count 10 (+ 1) % Row 6 \SetRowColor{LightBackground} {\emph{Runs all available indexes:}} & php magento indexer:reindex \tn % Row Count 12 (+ 2) % Row 7 \SetRowColor{white} {\bf{Cron}} & {\bf{Commands}} \tn % Row Count 13 (+ 1) % Row 8 \SetRowColor{LightBackground} {\emph{Runs all cron jobs by schedule:}} & php magento cron:run \tn % Row Count 15 (+ 2) % Row 9 \SetRowColor{white} {\bf{Help \& Knowledge}} & {\bf{Commands}} \tn % Row Count 16 (+ 1) % Row 10 \SetRowColor{LightBackground} {\emph{Display help/infos about a command}} & php magento help indexer:reindex \tn % Row Count 18 (+ 2) % Row 11 \SetRowColor{white} {\emph{Lists all available CLI commands}} & php magento list \tn % Row Count 20 (+ 2) % Row 12 \SetRowColor{LightBackground} {\bf{Developement \& Production}} & {\bf{Commands}} \tn % Row Count 22 (+ 2) % Row 13 \SetRowColor{white} {\emph{Set to the production mode to harden your setup}} & php magento \seqsplit{deploy:mode:setproduction} \tn % Row Count 25 (+ 3) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{(exceptions are not displayed to the user, only logged to log files)}}} \tn % Row Count 27 (+ 2) % Row 15 \SetRowColor{white} {\emph{Developer mode is less secure than Production mode}} & php magento \seqsplit{deploy:mode:setdeveloper} \tn % Row Count 30 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4.16 cm} x{3.84 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-terminal\}\} Command line (cont)}} \tn % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{provides verbose logging (errors displayed in browser) enhanced debuggingand disables static view file caching}}} \tn % Row Count 3 (+ 3) % Row 17 \SetRowColor{white} {\bf{Recompile Store}} & {\bf{Commands}} \tn % Row Count 4 (+ 1) % Row 18 \SetRowColor{LightBackground} Recompile the Magento 2 codebase & php magento setup:di:compile \tn % Row Count 6 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-recycle\}\} Useful Code Snippets and Tips}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to get product collection in custom template block }}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\$objectManager = \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}App\textbackslash{}ObjectManager::getInstance(); \{\{nl\}\} {\bf{/** @var \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}ResourceModel\textbackslash{}Product\textbackslash{}Collection \$productCollection */}} \{\{nl\}\}\$productCollection = \$objectManager-\textgreater{}create('Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}ResourceModel\textbackslash{}Product\textbackslash{}Collection'); \{\{nl\}\}{\bf{/** Apply filters here */}} \{\{nl\}\}\$productCollection-\textgreater{}load();`} \tn % Row Count 10 (+ 8) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to use Mage::log method in Magento 2}}} \tn % Row Count 12 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`protected \$logger; \{\{nl\}\}public function \_\_construct(\textbackslash{}Psr\textbackslash{}Log\textbackslash{}LoggerInterface \$logger) \{\$this-\textgreater{}logger = \$logger; \}`} \tn % Row Count 15 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{You use debug, exception, system for psr logger for example} \tn % Row Count 17 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`\$this-\textgreater{}logger-\textgreater{}info(\$message); \{\{nl\}\}\$this-\textgreater{}logger-\textgreater{}debug(\$message);`} \tn % Row Count 19 (+ 2) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to retrieve product information in Magento 2}}} \tn % Row Count 21 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{In Magento 2 proposed to use service layer for this. Try use `\textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}ProductRepository::getById` method to get product by id} \tn % Row Count 24 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to get a store in Magento 2 programmatically?}}} \tn % Row Count 26 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Magento 1.x} \tn % Row Count 27 (+ 1) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`Mage::app()-\textgreater{}getStore()`} \tn % Row Count 28 (+ 1) % Row 11 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`function rm\_store(\$id = null) \{\{\{nl\}\}/** @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}ObjectManagerInterface \$om */\{\{nl\}\}\$om = \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}App\textbackslash{}ObjectManager::getInstance(); \{\{nl\}\}/** @var \textbackslash{}Magento\textbackslash{}Store\textbackslash{}Model\textbackslash{}StoreManagerInterface \$manager */\{\{nl\}\}\$manager = \$om-\textgreater{}get('Magento\textbackslash{}Store\textbackslash{}Model\textbackslash{}StoreManagerInterface');\{\{nl\}\}return \$manager-\textgreater{}getStore(\$id); \}`} \tn % Row Count 35 (+ 7) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-recycle\}\} Useful Code Snippets and Tips (cont)}} \tn % Row 12 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to make JavaScript strings translatable (localizable)}}} \tn % Row Count 2 (+ 2) % Row 13 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{To make JavaScript strings translatable or localizable in Magento 2, use : `\$.mage.\_\_`} \tn % Row Count 4 (+ 2) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{{\emph{Example}} : \$.mage.\_\_('Select type of option.')} \tn % Row Count 5 (+ 1) % Row 15 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Some Magento 2 core modules use another way to translate JavaScript strings: they define/require the mage/translate library} \tn % Row Count 8 (+ 3) % Row 16 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to call theme images from a static block}}} \tn % Row Count 10 (+ 2) % Row 17 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{You call theme images from static block as follows: {\bf{\{\{view url="images/demo.jpg"\}\}}}} \tn % Row Count 12 (+ 2) % Row 18 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to instantiate a model in Magento 2}}} \tn % Row Count 14 (+ 2) % Row 19 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{Magento strictly discourages the use of ObjectManager directly. It provides service classes that abstract it away for all scenarios. \{\{nl\}\} For all non-injectables (models) you have to use factory:} \tn % Row Count 18 (+ 4) % Row 20 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`protected \$pageFactory;\{\{nl\}\}public function \_\_construct(\textbackslash{}Magento\textbackslash{}Cms\textbackslash{}Model\textbackslash{}PageFactory \$pageFactory) \{\{\{nl\}\}\$this-\textgreater{}pageFactory = \$pageFactory; \{\{nl\}\}\} \{\{nl\}\}public function someFunc() \{ \{\{nl\}\}... \$page = \$this-\textgreater{}pageFactory-\textgreater{}create(); ... \{\{nl\}\}\}`} \tn % Row Count 23 (+ 5) % Row 21 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to get the сollection of custom Magento 2 modules}}} \tn % Row Count 25 (+ 2) % Row 22 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{`protected \$mymodulemodelFactory; \{\{nl\}\}public function \_\_construct( .... \textbackslash{}{[}Namespace{]}\textbackslash{}{[}Module{]}\textbackslash{}Model\textbackslash{}ResourceModel\textbackslash{}{[}Entity{]}\textbackslash{}CollectionFactory \$mymodulemodelFactory, ... ) \{ \{\{nl\}\} ... \$this-\textgreater{}mymodulemodelFactory = \$mymodulemodelFactory; ... \{\{nl\}\}\}`} \tn % Row Count 31 (+ 6) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{p{0.8 cm} p{0.8 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{\{\{fa-recycle\}\} Useful Code Snippets and Tips (cont)}} \tn % Row 23 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{and you can use in any one of the class methods:} \tn % Row Count 1 (+ 1) % Row 24 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{\$collection = \$this-\textgreater{}mymodulemodelFactory-\textgreater{}create();} \tn % Row Count 3 (+ 2) % Row 25 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{fa-info-circle\}\} {\bf{How to get POST and GET requests in Magento 2}}} \tn % Row Count 5 (+ 2) % Row 26 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{In a case of a controller that extends {\bf{Magento\textbackslash{}Framework\textbackslash{}App\textbackslash{}Action\textbackslash{}Action}}, it is possible to get the request with the aid of `\$this-\textgreater{}getRequest()-\textgreater{}getPost()`.} \tn % Row Count 9 (+ 4) % Row 27 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{For a custom class, inject the request in the constructor:} \tn % Row Count 11 (+ 2) % Row 28 \SetRowColor{white} \mymulticolumn{2}{x{8.4cm}}{`namespace Namespace\textbackslash{}Module\textbackslash{}Something; \{\{nl\}\}class ClassName \{ \{\{nl\}\}protected \$request;\{\{nl\}\}public function \_\_construct( \{\{nl\}\}\textbackslash{}Magento\textbackslash{}Framework\textbackslash{}App\textbackslash{}Request\textbackslash{}Http \$request, \{\{nl\}\} ....//rest of parameters here ) \{\{\{nl\}\}\$this-\textgreater{}request = \$request; \{\{nl\}\}...//rest of constructor here \{\{nl\}\}\} \{\{nl\}\}public function getPost() \{ \{\{nl\}\}return \$this-\textgreater{}request-\textgreater{}getPost(); \{\{nl\}\}\} \{\{nl\}\}\}`} \tn % Row Count 19 (+ 8) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}