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;...
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:
$...
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 ...
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->...
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....
28
votes
Accepted
NotNull not working with AddFieldToFilter in Magento 2
You can try this
->addFieldToFilter(
'ep_image',
['neq' => 'NULL']
)
24
votes
Accepted
addFieldToFilter() And Condition in magento2
Try with below code,
$multiselectupdate =$multiselect->getCollection()
->addFieldToFilter('customergroup', ['eq' => $categoryname])
...
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\...
17
votes
Filtering a Magento 2 Object Repository
public function __construct(
ProductRepositoryInterface $productRepository,
SearchCriteriaBuilder $searchCriteriaBuilder,
FilterBuilder $filterBuilder,
) {
$this->productRepository =...
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()-&...
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 ...
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" ...
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
$...
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">
&...
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 ...
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 ...
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 ...
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))...
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="...
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=...
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 = ...
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/...
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 ...
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 .....
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" ...
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
9
votes
Magento 2 remove category filter from list page filters?
Better to use as:
<?php if($filter->getRequestVar() != 'cat') {
// ...
}
?>
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->...
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
/**
* ...
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(...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
filter × 762magento2 × 309
layered-navigation × 132
collection × 124
magento-1.9 × 121
attributes × 101
grid × 97
category × 63
product × 45
admin × 38
product-collection × 36
price × 33
uicomponent × 33
magento2.3 × 28
product-attribute × 26
magento-2.1 × 25
magento-1.7 × 25
magento-1 × 22
search × 21
orders × 20
catalog × 18
products × 17
order-grid × 17
module × 16
adminhtml × 15