30 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 ...
user avatar
27 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\...
user avatar
  • 195k
16 votes
Accepted

Remove all products from one category programmatically

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

How to remove jQuery Conflict in prototype.js with 1.8.2.jquery.min.js

In your local.xml: <reference name="head"> <action method="addJs" name="jquery" as="jquery"> <script>jquery-1.10.2.js</script> </action> <action ...
user avatar
  • 3,232
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-...
user avatar
  • 3,200
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 ...
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 ...
user avatar
  • 3,446
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 ...
user avatar
  • 11.5k
8 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,...
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 = ...
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 ...
user avatar
6 votes
Accepted

Adding a second product grid in category admin for "featured products"

Overview After scratching my head, i finally built a module. Models Created a model that extends the Category model to avoid having a custom entity. Observers addCategoryEssentialBlock This ...
user avatar
  • 351
6 votes

Can retrieve product category ID but category name is always null

try it like this: $product->getCategoryCollection() ->addAttributeToSelect('name') ->getFirstItem() ->getName();
user avatar
  • 195k
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); $...
user avatar
6 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 ...
user avatar
  • 888
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 ...
user avatar
  • 75.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:...
user avatar
  • 5,244
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 ...
user avatar
5 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->...
user avatar
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" ...
user avatar
  • 9,580
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 ...
user avatar
  • 5,235
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 ...
user avatar
5 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="...
user avatar
  • 34.3k
4 votes

Wrong sort order in category product collection

Looking at the files which are relevant for this, I can identify Varien_Data_Collection which is the base class and implements IteratorAggregate, so you can loop over collections using foreach($...
user avatar
  • 4,660
4 votes
Accepted

How to get product category URL Key?

Try this: $categories = $_product->getCategoryCollection() ->addAttributeToSelect('name') ->addUrlRewriteToResult(); Then in your loop try using getUrl() method.
user avatar
  • 11.5k
4 votes

Faster Way to Assign Products to Categories

the fastest way is with direct queries. And there shouldn't be an issue with that. I've done it a lot of times. The only thing required is to rebuild the indexes when you are done. INSERT INTO `...
user avatar
  • 195k
4 votes
Accepted

How to show categories in left sidebar in accordion view?

This is issue is fixed with custom code in theme. We have tried some code changes in theme and rendered the MENU and with the help of CSS got the exact what i want.
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 ...
user avatar
4 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 ...
user avatar
  • 1,203
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 (...
user avatar

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