Skip to content

Commit

Permalink
0.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Sep 9, 2019
1 parent a88adda commit 169fba8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
35 changes: 9 additions & 26 deletions Controller/Index/Change.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace Wolf\Filter\Controller\Index;
use Df\Framework\W\Result\Json;
use Magento\Catalog\Model\Category as C;
use Magento\Framework\App\Action\Action as _P;
use Wolf\Filter\Observer\TopMenuGetHTMLBefore as Ob;
// 2019-09-06
Expand All @@ -15,30 +16,12 @@ class Change extends _P {
* https://github.com/magento/magento2/blob/2.2.1/lib/internal/Magento/Framework/App/Action/Action.php#L84-L125
* @return Json
*/
function execute() {return Json::i(df_cache_get_simple('category_filter_' . df_request('selectedValue'), function() {
if (!($tree = wolf_tree_load())) {
$r = [];
}
else {
$levels = (int)df_request('levels'); /** @var int $levels «5» */
$levelValues = [];
for ($i = 0; $i < $levels; $i++) {
$levelValues[$i] = (int)df_request("level_{$i}_value");
if (0 < $levelValues[$i]) {
if (isset($tree[$levelValues[$i]])) {
if (isset($tree[$levelValues[$i]]['children'])) {
$tree = $tree[$levelValues[$i]]['children'];
}
}
}
}
$r = df_sort(
df_map($tree, function($v) {return dfa_select($v, ['id', 'name', 'url']);})
,function($a, $b) {return strcasecmp($a['name'], $b['name']);}
);
// 2019-09-07 We show years in the reverse order.
$r = array_values(1 !== (int)df_request('dataId') ? $r : array_reverse($r));
}
return $r;
}, [Ob::CACHE_TAG]));}
function execute() {$i = (int)df_request('dataId'); return Json::i(df_cache_get_simple(null,
function($id, $rev, $needURL) {return df_sort(
array_values(df_map(function(C $c) use($needURL) {return df_clean([
'id' => (int)$c->getId(), 'name' => $c->getName(), 'url' => $needURL ? $c->getUrl() : null
]);}, df_category($id)->getChildrenCategories()))
,function($a, $b) use($rev) {$r = strcasecmp($a, $b); return $rev ? -$r : $r;}
);}
,[Ob::CACHE_TAG], (int)df_request('selectedValue'), 1 === $i, 4 === $i));}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wolfautoparts.com/filter"
,"version": "0.0.1"
,"version": "0.0.2"
,"description": "A custom product filtering module for wolfautoparts.com (Magento 2)"
,"type": "magento2-module"
,"homepage": "https://github.com/wolfautoparts-com/filter"
Expand Down

0 comments on commit 169fba8

Please sign in to comment.