0

I need to filter values based on and condition in my custom table


id status categoryid


and i have to filter data according to status and categoryid my current code is

$collection = $this->collectionFactory->create()->addFieldToFilter('status', 1); 

how can i filter data based on status and categoryid

1

Magento 2.2:

public function __construct(
    ...
    \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory $collecionFactory
) {
    $this->_collectionFactory = $collecionFactory;
    parent::__construct(...);
}

Then anywhere else in your class you can do:

$collection = $this->collecionFactory
                ->create()
                ->addAttributeToFilter('status', 1)
                ->setPageSize(1);

if ($collection->getSize()) {
    $categoryId = $collection->getFirstItem()->getId();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.