\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{DominicXigen} \pdfinfo{ /Title (magento-2-product-repository-cheatsheet.pdf) /Creator (Cheatography) /Author (DominicXigen) /Subject (Magento 2 Product Repository Cheatsheet 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}{89A367} \definecolor{LightBackground}{HTML}{F7F9F5} \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 Product Repository Cheatsheet Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{DominicXigen} via \textcolor{DarkBackground}{\uline{cheatography.com/121447/cs/22284/}}} \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}DominicXigen \\ \uline{cheatography.com/dominicxigen} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 2nd April, 2020.\\ Updated 2nd May, 2020.\\ 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}{Import Statement}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{use Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface; \newline use Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterfaceFactory;} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Constructor}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\bf{ \newline {\emph{ @var \seqsplit{ProductRepositoryInterface} \newline }}/ \newline protected \seqsplit{\$productRepositoryInterface;} \newline \newline /}} \newline {\emph{ @var ProductInterfaceFactory \newline }}/ \newline protected \seqsplit{\$productInterfaceFactory;} \newline \newline /{\emph{* \newline }} @param \seqsplit{ProductRepositoryInterface} \seqsplit{\$productRepositoryInterface} \newline */ \newline public function \_\_construct( \newline \seqsplit{ProductRepositoryInterface} \seqsplit{\$productRepositoryInterface}, \newline ProductInterfaceFactory \seqsplit{\$productInterfaceFactory}, \newline ) \{ \newline \$this-\textgreater{}productRepositoryInterface = \seqsplit{\$productRepositoryInterface;} \newline \$this-\textgreater{}productInterfaceFactory = \seqsplit{\$productInterfaceFactory;} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Product Types}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_SIMPLE \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_BUNDLE \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_VIRTUAL \newline \textbackslash{}Magento\textbackslash{}Downloadable\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_DOWNLOADABLE \newline \textbackslash{}Magento\textbackslash{}ConfigurableProduct\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type\textbackslash{}Configurable::TYPE\_CODE \newline \textbackslash{}Magento\textbackslash{}GroupedProduct\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type\textbackslash{}Grouped::TYPE\_CODE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Get info about product by product SKU}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$product = \$this-\textgreater{}productRepositoryInterface-\textgreater{}get(\$sku);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\emph{* \newline }} @param string \$sku \newline {\emph{ @param bool \$editMode \newline }} @param int|null \$storeId \newline {\emph{ @param bool \$forceReload \newline }} @return \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface \newline {\emph{ @throws \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Exception\textbackslash{}NoSuchEntityException \newline }}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Get info about product by product id}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$product = \$this-\textgreater{}productRepositoryInterface-\textgreater{}getById(\$productId);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\emph{* \newline }} @param int \$productId \newline {\emph{ @param bool \$editMode \newline }} @param int|null \$storeId \newline {\emph{ @param bool \$forceReload \newline }} @return \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface \newline {\emph{ @throws \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Exception\textbackslash{}NoSuchEntityException \newline }}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Delete by SKU}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$this-\textgreater{}productRepositoryInterface-\textgreater{}deleteById(\$sku);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\emph{* \newline }} @param string \$sku \newline {\emph{ @return bool Will returned True if deleted \newline }} @throws \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Exception\textbackslash{}NoSuchEntityException \newline {\emph{ @throws \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Exception\textbackslash{}StateException \newline }}/} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Create New Product}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$product = \$this-\textgreater{}productInterfaceFactory \newline -\textgreater{}create() \newline -\textgreater{}setSku('SKU'); \newline // other required attributes \newline \$product = \$this-\textgreater{}productRepositoryInterface-\textgreater{}save(\$product);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Update Existing Product}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$product = \$this-\textgreater{}productRepositoryInterface-\textgreater{}get('SKU'); \newline \$product-\textgreater{}setStatus(\textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}Product\textbackslash{}Attribute\textbackslash{}Source\textbackslash{}Status::STATUS\_DISABLED); \newline \$updated = \$this-\textgreater{}productRepositoryInterface-\textgreater{}save(\$product);} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Advanced Search Filter Group}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\bf{ \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \newline }}/ \newline private \$productRepository; \newline \newline /}} \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \newline }}/ \newline private \$searchCriteriaBuilder; \newline \newline /{\bf{ \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \newline }}/ \newline private \$filterBuilder; \newline \newline /}} \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}Search\textbackslash{}FilterGroupBuilder \newline }}/ \newline private \$filterGroupBuilder; \newline \newline /{\bf{ \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \newline }}/ \newline private \$sortOrder; \newline \newline /}} \newline {\emph{ @param \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \$productRepository \newline }} @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \$searchCriteriaBuilder \newline {\emph{ @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \$filterBuilder \newline }} @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}Search\textbackslash{}FilterGroupBuilder \$filterGroupBuilder \newline {\emph{ @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \$sortOrder \newline }}/ \newline public function \_\_construct( \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \$productRepository, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \$searchCriteriaBuilder, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \$filterBuilder, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}Search\textbackslash{}FilterGroupBuilder \$filterGroupBuilder, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \$sortOrder \newline ) \{ \newline \$this-\textgreater{}productRepository = \$productRepository; \newline \$this-\textgreater{}searchCriteriaBuilder = \$searchCriteriaBuilder; \newline \$this-\textgreater{}filterBuilder = \$filterBuilder; \newline \$this-\textgreater{}filterGroupBuilder = \$filterGroupBuilder; \newline \$this-\textgreater{}sortOrder = \$sortOrder; \newline \} \newline \newline {[}...{]} \newline \newline \$filter1 = \$this-\textgreater{}filterBuilder \newline -\textgreater{}setField("url") \newline -\textgreater{}setValue("\%magento.com") \newline -\textgreater{}setConditionType("like") \newline -\textgreater{}create(); \newline \newline \$filter2 = \$this-\textgreater{}filterBuilder \newline -\textgreater{}setField("store\_id") \newline -\textgreater{}setValue("1") \newline -\textgreater{}setConditionType("eq") \newline -\textgreater{}create(); \newline \newline \$filterGroup1 = \$this-\textgreater{}filterGroupBuilder \newline -\textgreater{}setFilters({[}\$filter1, \$filter2{]}) \newline -\textgreater{}create(); \newline \newline \$filter3 = \$this-\textgreater{}filterBuilder \newline -\textgreater{}setField("url\_type") \newline -\textgreater{}setValue(1) \newline -\textgreater{}setConditionType("eq") \newline -\textgreater{}create(); \newline \newline \$filterGroup2 = \$this-\textgreater{}filterGroupBuilder \newline -\textgreater{}setFilters({[}\$filter3{]}) \newline -\textgreater{}create(); \newline \newline \$searchCriteria = \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}create(); \newline \$searchCriteria-\textgreater{}setFilterGroups({[}\$filterGroup1, \$filterGroup2{]}); \newline \$this-\textgreater{}productRepository-\textgreater{}getList(\$searchCriteria)-\textgreater{}getItems();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{The code above creates a Search Criteria with the Filters put together in the following way: (url like \%magento.com OR store\_id eq 1) AND (url\_type eq 1)} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Search Criteria}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\bf{ \newline {\emph{ @var \seqsplit{ProductRepositoryInterface} \newline }}/ \newline private \seqsplit{\$productRepositoryInterface;} \newline \newline /}} \newline {\emph{ @var SearchCriteriaBuilder \newline }}/ \newline private \$searchCriteriaBuilder; \newline \newline /{\bf{ \newline {\emph{ @param \seqsplit{ProductRepositoryInterface} \seqsplit{\$productRepositoryInterface} \newline }} @param SearchCriteriaBuilder \$searchCriteriaBuilder \newline {\emph{/ \newline public function \_\_construct( \newline \seqsplit{ProductRepositoryInterface} \seqsplit{\$productRepositoryInterface}, \newline SearchCriteriaBuilder \$searchCriteriaBuilder \newline ) \{ \newline \$this-\textgreater{}productRepository = \seqsplit{\$productRepositoryInterface;} \newline \$this-\textgreater{}searchCriteriaBuilder = \$searchCriteriaBuilder; \newline \} \newline \newline /}} \newline }} Get products by ids \newline {\emph{ @param array \$productIds \newline }} @return ProductInterface{[}{]} \newline */ \newline public function getProducts(array \$productIds): array \newline \{ \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}addFilter('entity\_id', \$productIds, 'in'); \newline \$searchCriteria = \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}create(); \newline \$products = \$this-\textgreater{}productRepositoryInterface-\textgreater{}getList(\$searchCriteria)-\textgreater{}getItems(); \newline \$count = \$products-\textgreater{}getTotalCount(); \newline return \$products; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Useful constants}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::SKU \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::NAME \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::PRICE \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::WEIGHT \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::STATUS \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::VISIBILITY \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::ATTRIBUTE\_SET\_ID \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::TYPE\_ID \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::CREATED\_AT \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::UPDATED\_AT \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::MEDIA\_GALLERY \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}Data\textbackslash{}ProductInterface::TIER\_PRICE} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Advanced Search}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{/{\bf{ \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \newline }}/ \newline private \$productRepository; \newline \newline /}} \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \newline }}/ \newline private \$searchCriteriaBuilder; \newline \newline /{\bf{ \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \newline }}/ \newline private \$filterBuilder; \newline \newline /}} \newline {\emph{ @var \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \newline }}/ \newline private \$sortOrder; \newline \newline /{\bf{ \newline {\emph{ @param \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \$productRepository \newline }} @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \$searchCriteriaBuilder \newline {\emph{ @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \$filterBuilder \newline }} @param \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \$sortOrder \newline {\emph{/ \newline public function \_\_construct( \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Api\textbackslash{}ProductRepositoryInterface \$productRepository, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SearchCriteriaBuilder \$searchCriteriaBuilder, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}FilterBuilder \$filterBuilder, \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrderFactory \$sortOrder \newline ) \{ \newline \$this-\textgreater{}productRepository = \$productRepository; \newline \$this-\textgreater{}searchCriteriaBuilder = \$searchCriteriaBuilder; \newline \$this-\textgreater{}filterBuilder = \$filterBuilder; \newline \$this-\textgreater{}sortOrder = \$sortOrder; \newline \} \newline \newline /}} \newline }} Retrieves products to be sent \newline {\emph{ @param array \$excludedIds \newline }} @param array \$filterIds \newline {\emph{ @param int \$page \newline }} @param int \$pageSize \newline {\emph{ @return ProductInterface{[}{]} \newline }} @throws \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Exception\textbackslash{}InputException \newline */ \newline public function retrieve( \newline array \$excludedIds, \newline array \$filterIds, \newline int \$page = 1, \newline int \$pageSize = 100 \newline ) : array \{ \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}addFilter('type\_id', {[} \newline \textbackslash{}Magento\textbackslash{}Catalog\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_SIMPLE, \newline \textbackslash{}Magento\textbackslash{}Downloadable\textbackslash{}Model\textbackslash{}Product\textbackslash{}Type::TYPE\_DOWNLOADABLE \newline {]}, 'in'); \newline \newline if (count(\$filterIds)) \{ \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}addFilter('entity\_id', \$filterIds, 'in'); \newline \} \newline \newline if (count(\$excludedIds)) \{ \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}addFilter('entity\_id', \$excludedIds, 'nin'); \newline \} \newline \newline \$sortOrder = \$this-\textgreater{}sortOrder-\textgreater{}setField('updated\_at') \newline -\textgreater{}setDirection(\textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrder::SORT\_DESC); \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}setSortOrders({[}\$sortOrder{]}); \newline \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}setCurrentPage(\$page); \newline \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}setPageSize(\$pageSize); \newline \$searchCriteria = \$this-\textgreater{}searchCriteriaBuilder-\textgreater{}create(); \newline return \$this-\textgreater{}productRepository-\textgreater{}getList(\$searchCriteria)-\textgreater{}getItems(); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Useful Constants}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrder::SORT\_ASC \newline \textbackslash{}Magento\textbackslash{}Framework\textbackslash{}Api\textbackslash{}SortOrder::SORT\_DESC} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Print Query String}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\$products = \$this-\textgreater{}productRepositoryInterface-\textgreater{}getList(\$searchCriteria) \newline echo \$products-\textgreater{}getSelect()-\textgreater{}assemble();} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}