24

you can inject in your block an instance of \Magento\Catalog\Model\CategoryFactory like this: protected $categoryFactory; public function __construct( .... \Magento\Catalog\Model\CategoryFactory $categoryFactory, ... ){ ... $this->categoryFactory = $categoryFactory; ... } Then create this method in your block: public function ...


16

You need to join the table that holds the category/product relations. A variation of the collection I use to find all products IN a list of categories should do the trick for you: (untested, but should get you in the right track) $productCollection = Mage::getResourceModel('catalog/product_collection') ->setStoreId(0) ->joinField('...


13

$category = Mage::getModel('catalog/category')->load(176); $category->setPostedProducts(array()); $category->save();


12

In your local.xml: <reference name="head"> <action method="addJs" name="jquery" as="jquery"> <script>jquery-1.10.2.js</script> </action> <action method="addJs"> <script>noconflict.js</script> </action> </reference> and noconflict.js would simply be $j = jQuery....


12

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 getCurrentCategory() function which set the current category to root category Path: app\code\Vendor\AllProducts\Block\Category\View.php <?php /** * Copyright © Magento, ...


11

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-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\ConfigurableProduct\Block\Product\View\...


8

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 collection Edit: tested for 750 products $collection->getData() Total Incl. Wall Time (microsec): 67,567 microsecs Total Incl. CPU (microsecs): 67,599 ...


8

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 = $this.parents('.' + $widget.options.classes.attributeClass), $label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),...


7

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 work, given the "exclude" category as $excludeId: $products2->joinTable( ['exclude_category' => 'catalog/category_product'], 'product_id=...


6

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); $category->setPostedProducts(array()); // Removes all old products added to your category $category->save(); $now = Mage::getModel('core/date')->timestamp(...


6

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, $sku) { $category = $this->categoryRepository->get($categoryId); $product = $this->productRepository->get($sku); $productPositions = $...


5

Following code will work for you: $catIds = array(7,8,9); $_productCollection = Mage::getModel('catalog/product') ->getCollection() ->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left') ->addAttributeToFilter('category_id', array('nin' => ...


5

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 observer adds our new products tab and serialized grid in the category management page and listens to the adminhtml_catalog_category_tabs event. ...


5

Use the below code in catalog_category_view.xml <action method="setDefaultGridPerPage"> <argument name="limit" xsi:type="string">all</argument> </action> This will show all products on category pages by default.


5

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 = checking your site 6.Catgories = checking your category. You have to remove var folder from root and try commands using cli: php bin/magento ...


5

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" category_id="4" template="Magento_Catalog::product/list.phtml"}} Here Magento is vendor and Catalog is your module. so you need to call template with Magento:...


5

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 data-role="tocart-form" data-product-sku="<?= $block->escapeHtml($_product->getSku()) ?>" action="<?= /* @NoEscape */ $postParams['action'] ?>" ...


5

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 layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration....


5

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:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="...


4

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 `catalog_category_product` SET `category_id` = category id here `product_id` = product id here `position` = position here ON DUPLICATE KEY UPDATE `...


4

Try this: $categories = $_product->getCategoryCollection() ->addAttributeToSelect('name') ->addUrlRewriteToResult(); Then in your loop try using getUrl() method.


4

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.


4

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 plugins feature is very handy for this purpose. create etc/di.xml in your extension with the following contents: <config xmlns:xsi="http://www.w3.org/2001/...


4

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 (via get or getById ) and then call getCategoryIds on that product.


4

Found Solution for above query, using order by case statement to working same as above query public function getCategoryProductsAscZeroLast($categoryId) { $products = $this->getCategoryData($categoryId)->getProductCollection(); $products->addAttributeToSelect('*')->setOrder('cat_index_position','ASC');; $...


4

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 after load. This seems to be an issue with the x-magento-init scripts that run on page load and therefore do not run on ajax requests. To fix this issue ...


4

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.xml Now add following codes for respective images <?xml version="1.0"?> <!-- /** * Copyright © 2016 Magento. All rights reserved. * See COPYING....


4

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:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd"> <event name="payment_method_is_active"> <observer name="payroll_payment_method_is_active" ...


3

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($_productCollection as $product). It does so via the method getIterator() which mainly returns new ArrayIterator($this->_items); In contrast, a level further up ...


3

This is not a bug, it's a feature. The categories with the attribute Is Anchor set to Yes display the products in the subcategories also. If you don't want this to happen, set Is Anchor to No. You may also need to rebuild your indexes when you are done.


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