33 votes
Accepted

Magento 2.x Elasticsearch Category Products Not Showing

I located an exception in ./magento/var/log/exception.log that showed an issue with the configuration of a custom attribute. The attribute was set to a type of text for the attribute custom_attribute ...
doublesharp's user avatar
28 votes
Accepted

Magento 2: get product collection using category id

you can inject in your block an instance of \Magento\Catalog\Model\CategoryFactory like this: protected $categoryFactory; public function __construct( .... \Magento\Catalog\Model\...
Marius's user avatar
  • 198k
16 votes
Accepted

Remove all products from one category programmatically

$category = Mage::getModel('catalog/category')->load(176); $category->setPostedProducts(array()); $category->save();
Marius's user avatar
  • 198k
13 votes
Accepted

When change a swatch option how to get a selected simple product in category product listing page in magento 2

Create plugin to add quantity to the JS config to get from swatch renderer Vendor/Module/etc/frontend/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-...
Ranganathan's user avatar
  • 3,210
13 votes
Accepted

Magento 2 - All products page with layered navigation and pagination

I recently did the same sort of work. First you need to override Category block because you want the All products page just like category page. In order to, get more understanding check ...
Muhammad Hasham's user avatar
10 votes
Accepted

Products are not showing in category Magento 2

Check below list If below things are done. 1.General->Status = Enabled 2.general->Visibility = Catalog,Search 3.Inventory->Qty > 0 4.Inventory->Stock Availability = In Stock 5.Websites ...
Arjun's user avatar
  • 3,546
9 votes
Accepted

How to check if a collection has items?

You can check the size of your collection: if ($man_collection->getSize()) { //proceed } else { echo "not found"; } Explaination here: Difference between getSize() and count() on ...
sv3n's user avatar
  • 11.6k
9 votes

Magento2: Could not save product "330664" with position 0 to category 3567

I faced the same issue and you can find the exact issue by printing actual error from exception. Temporary replace "deleteByIds" function with following code. public function deleteByIds($categoryId,...
Nitin Vala's user avatar
8 votes

When change a swatch option how to get a selected simple product in category product listing page in magento 2

You can find prodcutId from [Magento_Root]\vendor\magento\module-swatches\view\frontend\web\js\swatch-renderer.js find _OnClick function. _OnClick: function ($this, $widget) { var $parent = ...
Hardik Visa's user avatar
7 votes
Accepted

Exclude Category when showing product collection

You can left join the catalog_category_product table to match products in your "exclude category", then filter your collection to only return products with no matches in the joined table: This should ...
Fabian Schmengler's user avatar
7 votes

Magento2: Could not save product "330664" with position 0 to category 3567

This issue may occur with a duplicate product. I solved this issue using the following way. Set product "Visibility" to "Not Visible Individually" and then remove the category and ...
Vish Vaghela's user avatar
7 votes

catalog_product index does not exist yet. Make sure everything is reindexed

Please check https://github.com/Smile-SA/elasticsuite/issues/318#issuecomment-435322698, that fixed it for me. As this is a bit old, the command should be : bin/magento config:set catalog/search/...
Petar Borisovski's user avatar
6 votes

Can retrieve product category ID but category name is always null

try it like this: $product->getCategoryCollection() ->addAttributeToSelect('name') ->getFirstItem() ->getName();
Marius's user avatar
  • 198k
6 votes
Accepted

Magento 2: get Custom Collection by Asc sort order with position 0 at end of list

Found Solution for above query, using order by case statement to working same as above query public function getCategoryProductsAscZeroLast($categoryId) { $products = $this->...
Rakesh Jesadiya's user avatar
6 votes
Accepted

Assign Products created in last 45 days to specific category

You can use below code to assign products created in last 45 days to your category. $categoryId = 41; // Your category Id $category = Mage::getModel('catalog/category')->load($categoryId); $...
Jaimin Sutariya's user avatar
6 votes
Accepted

Magento 2.2.5 change 'Add To Cart' button to 'View Product' at category page

First you have to do this changes at your theme level. Goto app/design/frontend/{ThemeVendorname}/{ThemeName}/Magento_Catalog/templates/product/ And open list.phtml and delete the code: <form ...
Amit Bera's user avatar
  • 77.2k
6 votes
Accepted

How can I add a column to Category -> Category -> Products in Category grid in magento 2

Try following way to add a column. I have added a product creation time column as an example: app/code/SR/MagentoCommunity/etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="...
Sohel Rana's user avatar
  • 35.6k
6 votes
Accepted

Magento 2.3.2: Active payment method on specific category for the products in cart

Please try this way using payment_method_is_active event observer. Create events.xml file with the below content. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Aasim Goriya's user avatar
  • 5,394
5 votes

How to show all products on category pages in Magento 2

Use the below code in catalog_category_view.xml <action method="setDefaultGridPerPage"> <argument name="limit" xsi:type="string">all</argument> </action> This will show ...
Dimple Patel's user avatar
5 votes

How to show all products on category pages in Magento 2

Dimple Patel's answer is right, but to be more specific, if you need to show all products in all categories and want to do it trough xml you should reference the block product_list_toolbar in the ...
SantiBM's user avatar
  • 1,329
5 votes
Accepted

How to add product collection?

For magento2 you need to use class in your block while calling instead of type. Also the syntax of calling is changed. Try below code: {{block class="\Magento\Catalog\Block\Product\ListProduct" ...
Manthan Dave's user avatar
  • 9,796
5 votes
Accepted

Magento 2 Load More Product Script

As Dava Gordon has suggested i have been using the https://github.com/Strategery-Inc/Magento2-InfiniteScroll which does work however has the problem you are witnessing with ajax add to cart breaking ...
harri's user avatar
  • 5,415
5 votes
Accepted

Magento2 - Show Instant Purchase on product listing

Step 1) Create catalog_product_view.xml file in your Design, Under /app/design/frontend/Vendor_Name/Theme_Name/Magento_Catalog/layout/catalog_product_view.xml <?xml version="1.0"?> <page ...
Nauman m. Mansuri's user avatar
4 votes
Accepted

magento2 Directly to product if only one

It's a bit more complex task in comparison with Magento 1. First of all you need to create a small custom extension and modify the block's method behaviour for getting products collection. Magento 2 ...
Yaroslav Rogoza's user avatar
4 votes
Accepted

Get Category IDs for Product via Service Contract / API

I haven't found such method from the service contracts. The only way I can see this working via a service contract is by using Magento\Catalog\Api\ProductRepositoryInterface to get the product first (...
Raphael at Digital Pianism's user avatar
4 votes

Image sizes in detail page

To change Size of product images and other listing page images or related item image Edit your view.xml at below location in your extended theme /app/design/frontend/vendor-name/theme-name/etc/view....
Manoj Deswal's user avatar
  • 5,765
4 votes
Accepted

Magento 2: How to retrieve a random product from a random category?

The best approach (Good practice) is using Interfaces /** * @param int $categoryId */ public function getRandomProduct(categoryId) { $products = $this->productRepository->getList($this-&...
Thiago Lima's user avatar
4 votes
Accepted

Best seller items in category magento 2

$_objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $catalog_ids = 4; $productCollection = $_objectManager- >create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory'...
Qaisar Satti's user avatar
  • 32.4k
4 votes
Accepted

Magento 2.3 add custom block under each product in category page

Create di.xml file at /app/code/Vendor/Module/etc/frontend/di.xml : <type name="Magento\Catalog\Block\Product\ListProduct"> <plugin name="block-product-list" type="Vender\Module\Plugin\...
Rohan Hapani's user avatar
  • 17.3k
4 votes

Magento 2.3.2: Active payment method on specific category for the products in cart

You can get it with payment_method_is_active event observer. Create events.xml file with below content. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:...
Sumit's user avatar
  • 4,825

Only top scored, non community-wiki answers of a minimum length are eligible