Skip to content

how to special_price magento 2 collection it’s not taking parent product

special_price magento 2 collection it’s not taking parent product

in there if product collection i will take visible product collection then it’s not taking variation collection

if i will take invisible product then is take all variation product but not taking parent product

$productCollection = $this->_productCollectionFactory->create();

    $productCollection
        //->setVisibility($this->_catalogProductVisibility->getVisibleInCatalogIds())
        ->addMinimalPrice()
        ->addFinalPrice()
        ->addTaxPercents()
        ->addAttributeToSelect($this->catalogConfig->getProductAttributes())
        ->addUrlRewrite()
        ->addStoreFilter();
        
    if ($sortby == 'best_selling') {
        $productCollection->getSelect()->join(
            'sales_order_item',
            'e.entity_id = sales_order_item.product_id',
            array('qty_ordered'=>'(select sum(soi.qty_ordered) from sales_order_item soi where soi.product_id = e.entity_id)'))
            ->distinct(true)->order('qty_ordered '.$listdesc);
    } else {  
        $productCollection->addAttributeToSort(
            $sortby,
            $listdesc
        );
    }
    if($cat){
        $productCollection->addCategoriesFilter(['in' => array($cat)]);
    }
    
    $productCollection->getSelect()->where(
        'price_index.final_price < price_index.price'
    );
    $productCollection->setPageSize($pageSize);
    $productCollection->setCurPage($page);
    
    return $productCollection;