Skip to content

Commit

Permalink
1.2.8: #12
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed May 5, 2020
1 parent 5adbf6b commit 520295d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class Filter {
*/
static function p(C $r) {
self::byDate($r);
self::byProduct($r);
/** @var string $dir */ /** @var string $suffix */
list($dir, $suffix) = $r instanceof PC ? ['DESC', 'Products'] : ['ASC', 'Orders'];
if ($field = df_request("sort$suffix")) { /** @var string $field */
Expand Down Expand Up @@ -46,4 +47,30 @@ private static function byDate(C $c) {
$c->addFieldToFilter('updated_at', ['from' => $d($since), 'to' => $d('2035-01-01 23:59:59')]);
}
}

/**
* 2020-05-06
* "Provide an ability to filter the `jumagext/response/catalog` response by a concrete product":
* https://github.com/justuno-com/m2/issues/12
* @used-by p()
* @param $c $c
*/
private static function byProduct(C $c) {
if ($id = df_request('id')) { /** @var string $id */
$c->addFieldToFilter('entity_id', $id);
}
if ($name = df_request('title')) { /** @var string $name */
/**
* 2020-05-06
* 1) @uses \Magento\Framework\Data\Collection\AbstractDb::addFieldToFilter()
* works even if the Flat Mode is disabled
* despite the `catalog_product_entity` table does not contain the `name` field.
* 2) @see \Magento\Catalog\Model\ResourceModel\Product\Collection::addAttributeToFilter() works too.
*/
$c->addFieldToFilter('name', [['like' => "%$name%"]]);
}
if ($sku = df_request('sku')) { /** @var string $sku */
$c->addFieldToFilter('sku', [['like' => "%$sku%"]]);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "justuno.com/m2"
,"version": "1.2.7"
,"version": "1.2.8"
,"description": "Justuno module for Magento 2"
,"type": "magento2-module"
,"homepage": "https://github.com/justuno-com/m2"
Expand Down

0 comments on commit 520295d

Please sign in to comment.