I have passing category id through xml i'm trying to check it in block file.but it did not work
foreach ($productCollection as $product) {
// get product id
$productIds[]=$this->getProductData($product->getProductId());
}
// get category // IDEA:
$filterCats = explode(',',$this->getData('parentcat'));
// filter bestselling products using category id
if($filterCats != NULL){
$collection = $objectManager->create('\Magento\Catalog\Model\ResourceModel\Product\Collection')->addIdFilter($productIds)->addCategoriesFilter(array('in' => $filterCats));
}
$collection = $objectManager->create('\Magento\Catalog\Model\ResourceModel\Product\Collection')->addIdFilter($productIds);
xml
<block class="Mageplaza\Productslider\Block\BestSellerProducts" name="product.slider.bestsellerproducts" template="productslider.phtml" after="banner.block.1">
<arguments>
<argument name="products_count" xsi:type="number">8</argument>
<argument name="margin" xsi:type="string">5</argument>
<argument name="parentcat" xsi:type="number">2</argument>
<argument name="heading" xsi:type="string">Best Sellers</argument>
<argument name="description" xsi:type="string">Here is your Best Sellers description </argument>
</arguments>
</block>