Skip to main content
34 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
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,220
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,586
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.7k
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
8 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
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
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.6k
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
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,454
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,370
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,856
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,495
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

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,805
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.5k
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.5k
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,930
3 votes
Accepted

Counting amount of products in category not working

Go to admin and edit this category (id=4). Now go to Category Products tab and check how many products are there. I think there will be 3 products. The total you are looking for is the sum of products ...
Anil Suthar's user avatar
  • 4,731
3 votes
Accepted

Add product count to toolbar.phtml

Remove <?php and ?> <p class="amount"> <?php if($this->getLastPageNum()>1): ?> <?php echo $this->__('Items %s to %s of %s total', $this->getFirstNum(), $this->...
Lord Skeletor's user avatar
3 votes

Get only the first level of child categories

use below code to get first level category $categories = Mage::getModel('catalog/category') ->getCollection() ->addAttributeToSelect('*') ->...
Jigs Parmar's user avatar
  • 2,438
3 votes

How to show categories in left sidebar in accordion view?

Open this url once, you will get the solution. http://tejabhagavan.blogspot.in/2016/01/accordion-tabs-in-magento-for-layered.html Open a path as follows: app/design/frontend/default/{your folder}/...
Teja Bhagavan Kollepara's user avatar

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