You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Is Equal To$collection->addAttributeToFilter('is_active', ['eq' => 1]);
// Is Not Equal To$collection->addAttributeToFilter('is_active', ['neq' => 1]);
// Greater Than$collection->addAttributeToFilter('level', ['gt' => 3]);
// Less Than$collection->addAttributeToFilter('level', ['lt' => 3]);
// Greater Than or Equal To$collection->addAttributeToFilter('entity_id', ['gteq' => 4]);
// Less Than or Equal To$collection->addAttributeToFilter('entity_id', ['lteq' => 4]);
// Contains – with % wildcards$collection->addAttributeToFilter('name', ['like' => 'DVD%']);
// Does Not Contain – with % wildcards$collection->addAttributeToFilter('name', ['nlike' => 'ABC%']);
// In Array$collection->addAttributeToFilter('entity_id', ['in' => [1,3,12]]);
// Not In Array$collection->addAttributeToFilter('entity_id', ['nin' => [1,2,12]]);
// Is NULL$collection->addAttributeToFilter('description', 'null');
$collection->addAttributeToFilter('description', ['null' => true]);
// Is Not NULL$collection->addAttributeToFilter('description', 'notnull');
$collection->addAttributeToFilter('description', ['notnull' => true]);
// Sort Collection// Order by Attribute Ascending$collection->setOrder('price', 'ASC');
// Order by Attribute Descending$collection->setOrder('name', 'DESC');
// Random Order$collection->setOrder('rand()');
// Limit Collection$collection->setPageSize(10);
$collection->setCurPage(1);
// Count Results$collection->count();
Free Up Memory
$collection->clear();
Category Helper
Tree
useMagento\Catalog\Helper\CategoryasHelperCategory;
publicfunction__construct(
HelperCategory$helper
) {
$this->helper = $helper;
}
/** * Retrieve current store categories * @param bool|string $sorted * @param bool $asCollection * @param bool $toLoad * @return \Magento\Framework\Data\Tree\Node\Collection or * \Magento\Catalog\Model\ResourceModel\Category\Collection or array */$categories = $this->helper->getStoreCategories(false, true, true);