{"id":1130,"date":"2020-01-10T01:55:50","date_gmt":"2020-01-10T01:55:50","guid":{"rendered":"https:\/\/www.magetop.com\/blog\/?p=1130"},"modified":"2021-07-22T02:58:47","modified_gmt":"2021-07-22T02:58:47","slug":"how-to-get-product-collection-in-magento-2","status":"publish","type":"post","link":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/","title":{"rendered":"How To Get Product Collection In Magento 2"},"content":{"rendered":"\n\n\n<p>In the previous article, we learned about <a href=\"https:\/\/www.magetop.com\/blog\/how-to-make-custom-page-layout-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"How To Make Custom Page Layout In Magento 2 (opens in a new tab)\">How To Make Custom Page Layout In Magento 2<\/a>. Today, we will introduce you about <strong>How to get product collection in Magento 2<\/strong>.<\/p>\n\n\n\n<p>I think you should read <a href=\"https:\/\/www.magetop.com\/blog\/how-to-create-new-theme-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\"How To Create New Theme In Magento 2 (opens in a new tab)\">How To Create New Theme In Magento 2<\/a> first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Make block get product collection<\/h2>\n\n\n\n<p>Create file <code>app\/code\/&lt;vendor_name&gt;\/&lt;module_name&gt;\/Block\/Products.php<\/code> should look like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;?php\nnamespace Magetop\\Themes\\Block;\nuse Magento\\Framework\\View\\Element\\Template;\n \nclass Products extends Template\n{\n    public function __construct(\n        \\Magento\\Catalog\\Block\\Product\\Context $context,\n        \\Magento\\Catalog\\Model\\ProductFactory $productFactory,\n        \\Magento\\Catalog\\Model\\Product\\Visibility $visibility,\n        \\Magento\\Catalog\\Block\\Product\\ListProduct $abstractProduct,\n        array $data = &#x5B;]\n    ) {\n        $this-&gt;_productModelFactory = $productFactory;\n        $this-&gt;_productVisible = $visibility;\n        parent::__construct($context, $data);\n        $this-&gt;absblock = $abstractProduct;\n    }\n    public function getBestSellerProducts($categoryID = null)\n    {\n        $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();    \n        $collection = $objectManager-&gt;get('\\Magento\\Sales\\Model\\ResourceModel\\Report\\Bestsellers\\CollectionFactory')-&gt;create()-&gt;setModel('Magento\\Catalog\\Model\\Product');\n        $producIds = array();\n        foreach ($collection as $product) {\n            $producIds&#x5B;] = $product-&gt;getProductId();\n        }\n        $model = $this-&gt;_productModelFactory-&gt;create();\n        $storeId = $model-&gt;getStoreId();\n        $collection = $model-&gt;getCollection();\n        $collection-&gt;setVisibility($this-&gt;_productVisible-&gt;getVisibleInCatalogIds());\n        $collection-&gt;setStoreId($storeId)\n            -&gt;addAttributeToSelect('*')\n            -&gt;addStoreFilter($storeId);\n \n        $collection = $collection-&gt;addStoreFilter()-&gt;addAttributeToFilter('entity_id', array('in' =&gt; $producIds));\n        if($categoryID &amp;&amp; $categoryID != 0){\n            \/**\n             * @var \\Magento\\Catalog\\Model\\Category $catModel\n             *\/\n            $catModel = $this-&gt;_categoryFactory-&gt;create();\n            $catCollection = $catModel-&gt;load($categoryID);\n            $collection-&gt;addCategoryFilter($catCollection);\n        }\n        $collection-&gt;setPageSize(10);\n        return $collection;\n    }\n}\n<\/pre><\/div>\n\n\n<p> We\u2019ll get BestSeller products on the home page. So go to backend then paste below code to content home page. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n{{block class=&quot;Magetop\\Themes\\Block\\Products&quot; name=&quot;bestseller.colection&quot; template=&quot;Magetop_Themes::product\/bestseller.phtml&quot;}}\n<\/pre><\/div>\n\n\n<p>After create file <code>&lt;theme_dir&gt;\/Magento_Theme\/templates\/product\/bestseller.phtml<\/code> should look like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&lt;?php\n$_productCollection = $block-&gt;getBestSellerProducts();\n$_helper = $this-&gt;helper('Magento\\Catalog\\Helper\\Output');\n?&gt;\n&lt;?php if ($_productCollection-&gt;count()): ?&gt;\n    &lt;div class=&quot;products wrapper grid products-grid&quot;&gt;\n        &lt;ol class=&quot;products list items product-items&quot;&gt;\n            &lt;?php foreach ($_productCollection as $_product): ?&gt;\n            &lt;li class=&quot;item product product-item&quot;&gt;\n                &lt;div class=&quot;product-item-info&quot; data-container=&quot;product-grid&quot;&gt;\n                    &lt;a href=&quot;&lt;?= \/* @escapeNotVerified *\/ $_product-&gt;getProductUrl() ?&gt;&quot; class=&quot;product photo product-item-photo&quot; tabindex=&quot;-1&quot;&gt;\n                        &lt;?php echo $block-&gt;absblock-&gt;getImage($_product,'category_page_grid')-&gt;toHtml(); ?&gt;\n                    &lt;\/a&gt;\n                    &lt;div class=&quot;product details product-item-details&quot;&gt;\n                        &lt;?php\n                            $_productNameStripped = $block-&gt;stripTags($_product-&gt;getName(), null, true);\n                        ?&gt;\n                        &lt;strong class=&quot;product name product-item-name&quot;&gt;\n                            &lt;a class=&quot;product-item-link&quot;\n                               href=&quot;&lt;?= \/* @escapeNotVerified *\/ $_product-&gt;getProductUrl() ?&gt;&quot;&gt;\n                                &lt;?= \/* @escapeNotVerified *\/ $_helper-&gt;productAttribute($_product, $_product-&gt;getName(), 'name') ?&gt;\n                            &lt;\/a&gt;\n                        &lt;\/strong&gt;\n                        &lt;?= $block-&gt;absblock-&gt;getReviewsSummaryHtml($_product,'short',true) ?&gt;\n                        &lt;?= \/* @escapeNotVerified *\/ $block-&gt;absblock-&gt;getProductPrice($_product) ?&gt;\n                        &lt;div class=&quot;product-item-inner&quot;&gt;\n                            &lt;div class=&quot;product actions product-item-actions&quot;&gt;\n                                &lt;div class=&quot;actions-primary&quot;&gt;\n                                    &lt;?php if ($_product-&gt;isSaleable()): ?&gt;\n                                        &lt;?php $postParams = $block-&gt;absblock-&gt;getAddToCartPostParams($_product); ?&gt;\n                                        &lt;form data-role=&quot;tocart-form&quot; data-product-sku=&quot;&lt;?= $block-&gt;escapeHtml($_product-&gt;getSku()) ?&gt;&quot; action=&quot;&lt;?= \/* @NoEscape *\/ $postParams&#x5B;'action'] ?&gt;&quot; method=&quot;post&quot;&gt;\n                                            &lt;input type=&quot;hidden&quot; name=&quot;product&quot; value=&quot;&lt;?= \/* @escapeNotVerified *\/ $postParams&#x5B;'data']&#x5B;'product'] ?&gt;&quot;&gt;\n                                            &lt;?= $block-&gt;absblock-&gt;getBlockHtml('formkey') ?&gt;\n                                            &lt;button type=&quot;submit&quot;\n                                                    title=&quot;&lt;?= __('Add to Cart') ?&gt;&quot;\n                                                    class=&quot;action tocart primary&quot;&gt;\n                                                &lt;span&gt;&lt;?= \/* @escapeNotVerified *\/ __('Add to Cart') ?&gt;&lt;\/span&gt;\n                                            &lt;\/button&gt;\n                                        &lt;\/form&gt;\n                                    &lt;?php else: ?&gt;\n                                        &lt;?php if ($_product-&gt;isAvailable()): ?&gt;\n                                            &lt;div class=&quot;stock available&quot;&gt;&lt;span&gt;&lt;?= \/* @escapeNotVerified *\/ __('In stock') ?&gt;&lt;\/span&gt;&lt;\/div&gt;\n                                        &lt;?php else: ?&gt;\n                                            &lt;div class=&quot;stock unavailable&quot;&gt;&lt;span&gt;&lt;?= \/* @escapeNotVerified *\/ __('Out of stock') ?&gt;&lt;\/span&gt;&lt;\/div&gt;\n                                        &lt;?php endif; ?&gt;\n                                    &lt;?php endif; ?&gt;\n                                &lt;\/div&gt;\n                                &lt;div data-role=&quot;add-to-links&quot; class=&quot;actions-secondary&quot;&gt;\n                                    &lt;?php if ($addToBlock = $block-&gt;absblock-&gt;getChildBlock('addto')): ?&gt;\n                                        &lt;?= $addToBlock-&gt;setProduct($_product)-&gt;getChildHtml() ?&gt;\n                                    &lt;?php endif; ?&gt;\n                                &lt;\/div&gt;\n                            &lt;\/div&gt;\n                        &lt;\/div&gt;\n                    &lt;\/div&gt;\n                &lt;\/div&gt;\n            &lt;\/li&gt;\n            &lt;?php endforeach; ?&gt;\n        &lt;\/ol&gt;\n    &lt;\/div&gt;\n&lt;?php endif; ?&gt;\n<\/pre><\/div>\n\n\n<p>We updated our file structure looks as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app\/code\/Magetop\/\n  \u251c\u2500\u2500 Themes\/\n  \u2502   \u251c\u2500\u2500 Block\/\n  \u2502   \u2502     \u251c\u2500\u2500 Products.php\n  app\/design\/frontend\/Magetop\/\n  \u251c\u2500\u2500 Default\/\n  \u2502   \u251c\u2500\u2500 Magetop_themes\/\n  \u2502   \u2502     \u251c\u2500\u2500 templates\/\n  \u2502   \u2502     \u2502   \u251c\u2500\u2500 product\/       \n  \u2502   \u2502     \u2502   \u2502   \u251c\u2500\u2500 bestseller.phtml<\/code><\/pre>\n\n\n\n<p>Good luck!<\/p>\n\n\n\n<p>This is   <strong>How to get product collection in Magento 2<\/strong>.<\/p>\n\n\n\n<p>You can see the next post: <a href=\"https:\/\/www.magetop.com\/blog\/add-custom-category-attributes-in-magento-2\/\" target=\"_blank\" rel=\"noreferrer noopener\">Add Custom Category Attributes In Magento 2<\/a>.<\/p>\n\n\n\n<p>Follow us for more helpful tutorial!<\/p>\n\n\n\n<p>We hope this is useful blog for you.<\/p>\n\n\n\n<p>Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article, we learned about How To Make Custom Page Layout In Magento 2. Today, we will introduce you about How To Get Product Collection In Magento 2. I think you should read How To Create New Theme In Magento 2 first.<\/p>\n","protected":false},"author":1,"featured_media":1132,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[215,214,213,212,107],"class_list":["post-1130","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-magento-2-tutorials","tag-get-product-collection","tag-get-product-collection-in-magento-2","tag-how-to-get-product-collection","tag-how-to-get-product-collection-in-magento-2","tag-magento-2-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.9 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How To Get Product Collection In Magento 2 - Magetop Blog<\/title>\n<meta name=\"description\" content=\"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Get Product Collection In Magento 2 - Magetop Blog\" \/>\n<meta property=\"og:description\" content=\"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Magetop Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/MagetopStore\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/MagetopStore\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-10T01:55:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-07-22T02:58:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i1.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"750\" \/>\n\t<meta property=\"og:image:height\" content=\"445\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Adam Roger\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/MagetopStore\" \/>\n<meta name=\"twitter:site\" content=\"@MagetopStore\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Adam Roger\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\"},\"author\":{\"name\":\"Adam Roger\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411\"},\"headline\":\"How To Get Product Collection In Magento 2\",\"datePublished\":\"2020-01-10T01:55:50+00:00\",\"dateModified\":\"2021-07-22T02:58:47+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\"},\"wordCount\":134,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1\",\"keywords\":[\"Get Product Collection\",\"Get Product Collection In Magento 2\",\"How To Get Product Collection\",\"How To Get Product Collection In Magento 2\",\"magento 2 tutorials\"],\"articleSection\":[\"Magento 2 Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\",\"url\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\",\"name\":\"How To Get Product Collection In Magento 2 - Magetop Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1\",\"datePublished\":\"2020-01-10T01:55:50+00:00\",\"dateModified\":\"2021-07-22T02:58:47+00:00\",\"description\":\"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...\",\"breadcrumb\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1\",\"width\":750,\"height\":445,\"caption\":\"How To Get Product Collection In Magento 2\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.magetop.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How To Get Product Collection In Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#website\",\"url\":\"https:\/\/www.magetop.com\/blog\/\",\"name\":\"Magetop Blog\",\"description\":\"Exploring Magento Tips, Tricks, and Trends\",\"publisher\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.magetop.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#organization\",\"name\":\"Magetop.com\",\"url\":\"https:\/\/www.magetop.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1\",\"width\":475,\"height\":475,\"caption\":\"Magetop.com\"},\"image\":{\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/MagetopStore\",\"https:\/\/x.com\/MagetopStore\",\"https:\/\/www.linkedin.com\/company\/magetop\",\"https:\/\/www.pinterest.com\/magetop\",\"https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411\",\"name\":\"Adam Roger\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g\",\"caption\":\"Adam Roger\"},\"description\":\"CEO and Founder of Magetop. A friend, a husband and a dad of two children. Adam loves to travel to experience new cultures and discover what is happening with ecommerce all around the world.\",\"sameAs\":[\"https:\/\/www.magetop.com\",\"https:\/\/www.facebook.com\/MagetopStore\",\"https:\/\/www.instagram.com\/magetopstore\",\"https:\/\/www.linkedin.com\/company\/magetop\",\"https:\/\/www.pinterest.com\/magetop\",\"https:\/\/x.com\/https:\/\/twitter.com\/MagetopStore\",\"https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA\",\"https:\/\/magetop.tumblr.com\"],\"url\":\"https:\/\/www.magetop.com\/blog\/author\/admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Get Product Collection In Magento 2 - Magetop Blog","description":"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/","og_locale":"en_US","og_type":"article","og_title":"How To Get Product Collection In Magento 2 - Magetop Blog","og_description":"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...","og_url":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/","og_site_name":"Magetop Blog","article_publisher":"https:\/\/www.facebook.com\/MagetopStore","article_author":"https:\/\/www.facebook.com\/MagetopStore","article_published_time":"2020-01-10T01:55:50+00:00","article_modified_time":"2021-07-22T02:58:47+00:00","og_image":[{"width":750,"height":445,"url":"https:\/\/i1.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","type":"image\/png"}],"author":"Adam Roger","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/MagetopStore","twitter_site":"@MagetopStore","twitter_misc":{"Written by":"Adam Roger","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#article","isPartOf":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/"},"author":{"name":"Adam Roger","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411"},"headline":"How To Get Product Collection In Magento 2","datePublished":"2020-01-10T01:55:50+00:00","dateModified":"2021-07-22T02:58:47+00:00","mainEntityOfPage":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/"},"wordCount":134,"commentCount":0,"publisher":{"@id":"https:\/\/www.magetop.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","keywords":["Get Product Collection","Get Product Collection In Magento 2","How To Get Product Collection","How To Get Product Collection In Magento 2","magento 2 tutorials"],"articleSection":["Magento 2 Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/","url":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/","name":"How To Get Product Collection In Magento 2 - Magetop Blog","isPartOf":{"@id":"https:\/\/www.magetop.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","datePublished":"2020-01-10T01:55:50+00:00","dateModified":"2021-07-22T02:58:47+00:00","description":"In this article, we will introduce you about How To Get Product Collection In Magento 2. I think you should read it. It is very helpful for you...","breadcrumb":{"@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#primaryimage","url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","width":750,"height":445,"caption":"How To Get Product Collection In Magento 2"},{"@type":"BreadcrumbList","@id":"https:\/\/www.magetop.com\/blog\/how-to-get-product-collection-in-magento-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.magetop.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How To Get Product Collection In Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/www.magetop.com\/blog\/#website","url":"https:\/\/www.magetop.com\/blog\/","name":"Magetop Blog","description":"Exploring Magento Tips, Tricks, and Trends","publisher":{"@id":"https:\/\/www.magetop.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.magetop.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.magetop.com\/blog\/#organization","name":"Magetop.com","url":"https:\/\/www.magetop.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2021\/11\/logo.png?fit=475%2C475&ssl=1","width":475,"height":475,"caption":"Magetop.com"},"image":{"@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/MagetopStore","https:\/\/x.com\/MagetopStore","https:\/\/www.linkedin.com\/company\/magetop","https:\/\/www.pinterest.com\/magetop","https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA"]},{"@type":"Person","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/1bf4d5d0c4f280303345970448feb411","name":"Adam Roger","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.magetop.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2ea543086258299e700cc48d893c02653c4a87b5466f23de66240a677d192811?s=96&d=mm&r=g","caption":"Adam Roger"},"description":"CEO and Founder of Magetop. A friend, a husband and a dad of two children. Adam loves to travel to experience new cultures and discover what is happening with ecommerce all around the world.","sameAs":["https:\/\/www.magetop.com","https:\/\/www.facebook.com\/MagetopStore","https:\/\/www.instagram.com\/magetopstore","https:\/\/www.linkedin.com\/company\/magetop","https:\/\/www.pinterest.com\/magetop","https:\/\/x.com\/https:\/\/twitter.com\/MagetopStore","https:\/\/www.youtube.com\/channel\/UCXoiJsz88OfPmwa8QpUkwOA","https:\/\/magetop.tumblr.com"],"url":"https:\/\/www.magetop.com\/blog\/author\/admin\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Product-Collection.png?fit=750%2C445&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/paOdw5-ie","jetpack-related-posts":[{"id":1119,"url":"https:\/\/www.magetop.com\/blog\/how-to-make-custom-page-layout-in-magento-2\/","url_meta":{"origin":1130,"position":0},"title":"How To Make Custom Page Layout In Magento 2","author":"Adam Roger","date":"January 8, 2020","format":false,"excerpt":"In the previous article, we learned about How to get store config value in Magento 2. Today, we will introduce you about How to make custom page layout in Magento 2.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"How To Make Custom Page Layout In Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Make-Custom-Page-Layout-1.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Make-Custom-Page-Layout-1.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Make-Custom-Page-Layout-1.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Make-Custom-Page-Layout-1.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1664,"url":"https:\/\/www.magetop.com\/blog\/how-to-get-items-to-storefront-magento\/","url_meta":{"origin":1130,"position":1},"title":"How To Get Items To Storefront In Magento 2","author":"Aaron LX","date":"April 1, 2020","format":false,"excerpt":"In the previous lesson, we learned together How To Use Model In Magento 2. Continuing that lesson, I will introduce How To Get Items To Storefront In Magento 2. You should read the Magento 2 Extension Tutorial step by step to be able to understand this lesson.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Magento 2 How To Get Items To Storefront","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/04\/Magento-2-How-To-Get-Items-To-Storefront.png?fit=813%2C450&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/04\/Magento-2-How-To-Get-Items-To-Storefront.png?fit=813%2C450&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/04\/Magento-2-How-To-Get-Items-To-Storefront.png?fit=813%2C450&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/04\/Magento-2-How-To-Get-Items-To-Storefront.png?fit=813%2C450&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1098,"url":"https:\/\/www.magetop.com\/blog\/how-to-get-store-config-value-in-magento-2\/","url_meta":{"origin":1130,"position":2},"title":"How To Get Store Config Value In Magento 2","author":"Adam Roger","date":"January 6, 2020","format":false,"excerpt":"In the previous article, we learned about How To Create Simple Module To Configure Options For Theme In Magento 2. Today, we will introduce you about How To Get Store Config Value In Magento 2.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"How To Get Store Config Value M2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Store-Config-Value.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Store-Config-Value.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Store-Config-Value.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/How-To-Get-Store-Config-Value.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1138,"url":"https:\/\/www.magetop.com\/blog\/add-custom-category-attributes-in-magento-2\/","url_meta":{"origin":1130,"position":3},"title":"Add Custom Category Attributes In Magento 2","author":"Adam Roger","date":"January 12, 2020","format":false,"excerpt":"In the previous article, we learned about How to get product collection in Magento 2. Today, we will introduce you about Add custom category attributes in Magento 2. I think you should read How To Create New Theme In Magento 2 first.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Add Custom Category Attributes In Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Add-Custom-Category-Attributes.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1067,"url":"https:\/\/www.magetop.com\/blog\/customize-cover-illustration-layout-in-magento-2\/","url_meta":{"origin":1130,"position":4},"title":"Customize Cover, Illustration Layout In Magento 2","author":"Adam Roger","date":"January 2, 2020","format":false,"excerpt":"Our previous post is How to create new theme in Magento 2. I think you guys should read it. To continue the previous post, we will introduce you to Customize cover, illustration layout in Magento 2.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Customize Cover, Illustration Layout Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Customize-Cover-Illustration-Layout.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]},{"id":1144,"url":"https:\/\/www.magetop.com\/blog\/make-default-system-config-value-in-magento-2\/","url_meta":{"origin":1130,"position":5},"title":"Make Default System Config Value In Magento 2","author":"Adam Roger","date":"January 12, 2020","format":false,"excerpt":"In the previous article, we learned about Add Custom Category Attributes In Magento 2. Today, we will introduce you about Make default system config value in Magento 2. I think you should read How To Create New Theme In Magento 2 first.","rel":"","context":"In &quot;Magento 2 Tutorials&quot;","block_context":{"text":"Magento 2 Tutorials","link":"https:\/\/www.magetop.com\/blog\/magento-2-tutorials\/"},"img":{"alt_text":"Make Default System Config Value In Magento 2","src":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Make-Default-System-Config-Value.png?fit=750%2C445&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Make-Default-System-Config-Value.png?fit=750%2C445&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Make-Default-System-Config-Value.png?fit=750%2C445&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.magetop.com\/blog\/wp-content\/uploads\/2020\/01\/Make-Default-System-Config-Value.png?fit=750%2C445&ssl=1&resize=700%2C400 2x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/1130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/comments?post=1130"}],"version-history":[{"count":6,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/1130\/revisions"}],"predecessor-version":[{"id":4139,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/posts\/1130\/revisions\/4139"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/media\/1132"}],"wp:attachment":[{"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/media?parent=1130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/categories?post=1130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.magetop.com\/blog\/wp-json\/wp\/v2\/tags?post=1130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}