Hot answers tagged

52 votes
Accepted

Magento 2 get Parameters in the URL

First, you need to inject \Magento\Framework\App\Request\Http at _construct function then using Magento2 how to getRequest $this->request->getParam('id'),you can your data protected $request;...
Amit Bera's user avatar
  • 76.7k
40 votes
Accepted

Filtering a Magento 2 Object Repository

Check out the following sample class. To filter by SKU, try this: $productFilterDemo->getProducts('sku', 'product_sku_value', 'eq'); To get products created after specific date, this: $...
Alex Paliarush's user avatar
36 votes
Accepted

Magento 2: How to reset filters in product grid?

The filter settings are stored in ui_bookmark table. It has the following columns: bookmark_id, user_id, namespace, identifier, current, title, config, created_at, updated_at You can delete the row ...
Bunyamin Inan's user avatar
33 votes
Accepted

How to filter collection by date range on Magento 2?

Has force to seek and test several solutions I finally found ! Like I use CollectionFactory object I have to use addFieldToFilter() and not addFilter(). $slides = $this->slideCollection->...
Antoine Subit's user avatar
31 votes

addFieldToFilter() with OR Condition in magento2

I assume that in your example, yellow, small and china are options in dropdowns. You will need their ids first, but let's assume the are $yellowId, $smallId and $chinaId. You can try this filtering....
Marius's user avatar
  • 197k
28 votes
Accepted

NotNull not working with AddFieldToFilter in Magento 2

You can try this ->addFieldToFilter( 'ep_image', ['neq' => 'NULL'] )
Priyank's user avatar
  • 7,582
24 votes
Accepted

addFieldToFilter() And Condition in magento2

Try with below code, $multiselectupdate =$multiselect->getCollection() ->addFieldToFilter('customergroup', ['eq' => $categoryname]) ...
Rakesh Jesadiya's user avatar
21 votes
Accepted

Magento 2 Get category id using category title

You can do it via collections: First you need to inject a CategoryFactory in your class constructor. Magento 2.0 & 2.1: public function __construct( ... \Magento\Catalog\Model\...
Raphael at Digital Pianism's user avatar
17 votes

Filtering a Magento 2 Object Repository

public function __construct( ProductRepositoryInterface $productRepository, SearchCriteriaBuilder $searchCriteriaBuilder, FilterBuilder $filterBuilder, ) { $this->productRepository =...
LDusan's user avatar
  • 966
15 votes

How to use getFirstItem() in collection into magento 2

Make sure there is data in your collection. The function will return the first item object from your collection and then you can use it directly. $collection = $this->_customFactory->create()-&...
Priyank's user avatar
  • 7,582
15 votes
Accepted

Magento 2: Filter Product Collection by Multiple Categories (Magento 2.1)

You are probably used to the "every method returns $this" paradigm from Magento 1. This is not the case anymore (at least not always). Specifically, addCategoriesFilter() does not return anything and ...
Fabian Schmengler's user avatar
15 votes

How to change date format of magento 2 admin grid filter without using ui component?

Following is the XML configuration that should work as you intended: <filterRange name="created_at" class="Magento\Backend\Block\Widget\Grid\Column\Filter\Date"> <argument name="data" ...
bassplayer7's user avatar
  • 2,158
15 votes
Accepted

Magento 2 Get category active filters name and id in Category page

Please try the below code its working for me: Below code will return the filters which are already applied to the category page or seach result page by customer, In magento you can say State $...
Sukumar Gorai's user avatar
14 votes
Accepted

Filters move to bottom in admin grid

You need to define dependency in your module.xml <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> &...
Priyank's user avatar
  • 7,582
13 votes
Accepted

Magento 2 remove category filter from list page filters?

You have to override core file into your theme, Category layered navigation comes form core file, vendor/magento/module-layered-navigation/view/frontend/templates/layer/view.phtml You have to get ...
Rakesh Jesadiya's user avatar
13 votes

Default filtering in UI Component Grid

You can create your own collection which will provide the items you like. Create a new collection. Sample\Sample\Model\ResourceModel\Posts\Grid\Collection that collection should: a. Implement the ...
Sakis's user avatar
  • 411
13 votes
Accepted

Magento 2 - All products page with layered navigation and pagination

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 ...
Muhammad Hasham's user avatar
12 votes
Accepted

Find value in comma separated string column through query

let's say that the country id you are looking for is $countryId. And the field name is country_id. You can add a filter like this: ->addFieldToFilter('country_id', array('finset' => $countryId))...
Marius's user avatar
  • 197k
12 votes
Accepted

Magento 2 : How can I load an admin grid with pre-defined filter values?

Here is what I found out so far. This is not complete but it can take you on the right path. I conducted my tests by modifying the cms page listing ui component. I added this <item name="...
Marius's user avatar
  • 197k
12 votes
Accepted

Magento2 Filters custom module dropdown in admin

When you define your fields datatype and filter as select. Magento will automatically display your column filter as dropdown. <column name="type"> <argument name="data" xsi:type=...
Priyank's user avatar
  • 7,582
11 votes
Accepted

Magento Filter collection by create times (today, yesterday, week, hour etc)

To add to @Ashvin answer.. I got entries created within the past hour $things = Mage::getModel('things/things')->getCollection(); $things->addFieldToFilter('things_type', 'view'); $fromDate = ...
BENN1TH's user avatar
  • 814
11 votes
Accepted

Magento 2 : Filter Product Grid Using Category In Admin

Even if this is an old thread there is still no free solution... So I've created a free extension that adds the feature of category filter in the admin product grid. https://github.com/utklasad/...
utklasad's user avatar
  • 146
10 votes

addFieldToFilter() with OR Condition in magento2

Try this, It work for me $collection->addAttributeToFilter([ ['attribute' => 'attribute1','null' => true ], ['attribute' => 'attribute1','gteq' => 1 ] ]); // Don't ...
Châu Văn Khánh Nhật's user avatar
10 votes

Default filtering in UI Component Grid

Vanilla out of the box can achieve default filter Inject below configs to your listing component, e.g., your_ui_component.xml <listing ...> <listingToolbar ...> <filters .....
Torrey's user avatar
  • 211
10 votes

(Zend_Db_Statement_Exception): SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'created_at' in where clause is ambiguous

You can achieve this task by below 2 option Option - 1 You need to change 'created_at' column in view/adminhtml/ui-component/sales_order_grid.xml Change column <column name="created_at" ...
Suresh Chikani's user avatar
9 votes
Accepted

REST API - categories by store view code

The answer is quite simple: http://localhost/rest/{store code}/V1/categories Just replace the {store code} with yours. For example English would be: http://localhost/rest/en/V1/categories
Benjamin Steiner's user avatar
9 votes

Magento 2 remove category filter from list page filters?

Better to use as: <?php if($filter->getRequestVar() != 'cat') { // ... } ?>
MagePsycho's user avatar
  • 4,672
9 votes
Accepted

Magento 2 addFieldToFilter equal today for datetime field

You can use below code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $objDate = $objectManager->create('Magento\Framework\Stdlib\DateTime\DateTime'); $now = $objDate->...
Prasanta Hatui's user avatar
8 votes
Accepted

Magento 2 : Rating Filter in Layered Navigation

create one file Called Rating.php as of now i did in core module only which can be implemented in your custom module vendor\magento\module-catalog\Model\Layer\Filter\Rating.php <?php /** * ...
Pradeep Kumar's user avatar
8 votes
Accepted

How to remove a field filter from collection

This is actually a great deal of trouble unless you are willing to parse and reimplement raw SQL. Using the Zend_Db_Select class, you can call: $where = $collection->getSelect()->getPart(...
Phil M's user avatar
  • 748

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