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 ...
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\...
16
votes
Accepted
Remove all products from one category programmatically
$category = Mage::getModel('catalog/category')->load(176);
$category->setPostedProducts(array());
$category->save();
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-...
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 ...
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 ...
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 ...
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,...
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 = ...
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 ...
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 ...
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/...
6
votes
Can retrieve product category ID but category name is always null
try it like this:
$product->getCategoryCollection()
->addAttributeToSelect('name')
->getFirstItem()
->getName();
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->...
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);
$...
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 ...
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="...
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:...
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 ...
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 ...
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" ...
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 ...
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 ...
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 ...
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 (...
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....
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-&...
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'...
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\...
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:...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
category-products × 555magento2 × 182
category × 135
magento-1.9 × 122
product × 57
products × 42
product-collection × 27
magento2.3 × 26
magento-2.1 × 24
category-tree × 23
collection × 22
catalog × 21
magento-1.7 × 19
product-list × 18
sorting × 17
category-listing × 17
product-attribute × 14
attributes × 13
magento2.4 × 12
php × 11
database × 11
magento-1 × 11
layered-navigation × 11
filter × 11
magento-1.8 × 10