Skip to content

Commit 7fc5f15

Browse files
paulfcddAleksander Laurowski
authored andcommitted
FFWEB-2223: Implement category path
1 parent a77c3fc commit 7fc5f15

File tree

20 files changed

+889
-943
lines changed

20 files changed

+889
-943
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Changelog
22
## [v2.3.0]
3+
### Added
4+
- Category Page
5+
- for NG version implement `category-page` attribute
6+
- Upload
7+
- Implement SFTP upload with public key authentication method
8+
39
### Fix
410
- Tracking
511
- Add to cart tracking throws an error on versions less than 2.4
6-
- Upload
7-
- Implement SFTP upload with public key authentication method
812

913
## [v2.2.0] - 2021.10.01
1014
### Added

src/Model/Config/Communication/BehaviourConfig.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Framework\App\Config\ScopeConfigInterface;
88
use Magento\Store\Model\ScopeInterface;
99
use Omikron\Factfinder\Api\Config\ParametersSourceInterface;
10+
use Omikron\FactFinder\Communication\Version;
1011

1112
class BehaviourConfig implements ParametersSourceInterface
1213
{
@@ -16,6 +17,7 @@ class BehaviourConfig implements ParametersSourceInterface
1617
private const PATH_KEEP_URL_PARAMS = 'factfinder/advanced/keep_url_param';
1718
private const PATH_ONLY_SEARCH_PARAMS = 'factfinder/advanced/only_search_params';
1819
private const PATH_PARAMETER_WHITELIST = 'factfinder/advanced/parameter_whitelist';
20+
private const PATH_VERSION = 'factfinder/general/version';
1921

2022
/** @var ScopeConfigInterface */
2123
private $scopeConfig;
@@ -27,14 +29,23 @@ public function __construct(ScopeConfigInterface $scopeConfig)
2729

2830
public function getParameters(): array
2931
{
30-
return [
32+
$parameters = [
3133
'use-url-parameters' => $this->getFlag(self::PATH_USE_URL_PARAMETER),
3234
'add-params' => $this->getConfig(self::PATH_ADD_PARAMS),
3335
'add-tracking-params' => $this->getConfig(self::PATH_ADD_TRACKING_PARAMS),
3436
'keep-url-params' => $this->getConfig(self::PATH_KEEP_URL_PARAMS),
3537
'only-search-params' => $this->getFlag(self::PATH_ONLY_SEARCH_PARAMS),
3638
'parameter-whitelist' => $this->getConfig(self::PATH_PARAMETER_WHITELIST),
3739
];
40+
41+
if ($this->getVersion() === Version::NG) $parameters['category-page'] = '';
42+
43+
return $parameters;
44+
}
45+
46+
public function getVersion(): string
47+
{
48+
return (string) $this->scopeConfig->getValue(self::PATH_VERSION, ScopeInterface::SCOPE_STORES);
3849
}
3950

4051
private function getConfig(string $path): string

src/Test/Unit/Model/Export/Catalog/Entity/ProductVariationTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
use Magento\Catalog\Model\Product;
99
use Omikron\Factfinder\Model\Export\Catalog\FieldProvider;
1010
use Omikron\Factfinder\Model\Export\Catalog\ProductField\ProductImage;
11+
use Omikron\Factfinder\Model\Export\Catalog\Entity\ProductVariation;
1112
use Omikron\Factfinder\Model\Formatter\NumberFormatter;
1213
use PHPUnit\Framework\TestCase;
1314

1415
/**
15-
* @covers ProductVariationTest
16+
* @covers ProductVariation
1617
*/
1718
class ProductVariationTest extends TestCase
1819
{

src/Test/Unit/ViewModel/CategoryPathTest.php

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,51 @@ class CategoryPathTest extends TestCase
2121
/** @var MockObject|Category */
2222
private $currentCategory;
2323

24-
public function test_category_path_is_correctly_sorted()
24+
/** @var MockObject|CommunicationConfig */
25+
private $communicationConfig;
26+
27+
/** @var MockObject|Registry */
28+
private $registry;
29+
30+
public function test_category_path_for_ng_version()
31+
{
32+
$this->communicationConfig->method('getVersion')->willReturn('ng');
33+
$categoryPath = $this->newCategoryPath($this->communicationConfig);
34+
35+
$this->currentCategory->method('getParentCategories')
36+
->willReturn([$this->category('Men', 1), $this->category('Tops', 2), $this->category('Jackets', 3)]);
37+
38+
$value = 'filter=CategoryPath%3AMen%2FTops%2FJackets';
39+
$this->assertSame($value, (string) $categoryPath->getCategoryPath());
40+
}
41+
42+
public function test_category_path_for_standard_version()
2543
{
44+
$this->communicationConfig->method('getVersion')->willReturn('7.3');
45+
$categoryPath = $this->newCategoryPath($this->communicationConfig);
46+
2647
$this->currentCategory->method('getParentCategories')
27-
->willReturn([$this->category('C', 3), $this->category('A', 1), $this->category('B', 2)]);
48+
->willReturn([$this->category('Jackets', 3), $this->category('Men', 1), $this->category('Tops', 2)]);
2849

29-
$value = 'filterCategoryPathROOT=A,filterCategoryPathROOT%2FA=B,filterCategoryPathROOT%2FA%2FB=C';
30-
$this->assertSame($value, (string) $this->categoryPath->getValue());
50+
$value = 'filterCategoryPathROOT=Men,filterCategoryPathROOT%2FMen=Tops,filterCategoryPathROOT%2FMen%2FTops=Jackets';
51+
$this->assertSame($value, (string) $categoryPath->getAddParams());
3152
}
3253

3354
protected function setUp(): void
3455
{
56+
$this->communicationConfig = $this->createMock(CommunicationConfig::class);
3557
$this->currentCategory = $this->createMock(Category::class);
36-
$registry = new Registry();
37-
$this->categoryPath = new CategoryPath($registry, $this->createMock(CommunicationConfig::class));
38-
$registry->register('current_category', $this->currentCategory);
58+
$this->registry = new Registry();
59+
$this->registry->register('current_category', $this->currentCategory);
3960
}
4061

4162
private function category(string $name, int $level): Category
4263
{
4364
return $this->createConfiguredMock(Category::class, ['getName' => $name, 'getLevel' => $level]);
4465
}
66+
67+
private function newCategoryPath(CommunicationConfig $communicationConfig): CategoryPath
68+
{
69+
return new CategoryPath($this->registry, $this->communicationConfig);;
70+
}
4571
}

src/ViewModel/CategoryPath.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,31 @@ public function __construct(
2929
CommunicationConfig $communicationConfig,
3030
string $param = 'CategoryPath',
3131
array $initial = []
32-
) {
33-
$this->param = $param;
34-
$this->registry = $registry;
32+
)
33+
{
34+
$this->param = $param;
35+
$this->registry = $registry;
3536
$this->communicationConfig = $communicationConfig;
36-
$this->initial = $initial;
37+
$this->initial = $initial;
38+
}
39+
40+
public function __toString()
41+
{
42+
return $this->communicationConfig->getVersion() === Version::NG ? $this->getCategoryPath() : $this->getAddParams();
43+
}
44+
45+
public function getCategoryPath(): string
46+
{
47+
if ($this->communicationConfig->getVersion() === Version::NG) return implode(',', $this->ngPath($this->getCurrentCategory()));
48+
49+
return '';
3750
}
3851

39-
public function __toString(): string
52+
public function getAddParams(): string
4053
{
41-
$path = $this->communicationConfig->getVersion() === Version::NG
42-
? $this->ngPath($this->getCurrentCategory())
43-
: $this->standardPath($this->getCurrentCategory());
54+
if ($this->communicationConfig->getVersion() === Version::NG) return '';
4455

45-
return implode(',', $path);
56+
return implode(',', $this->standardPath($this->getCurrentCategory()));
4657
}
4758

4859
public function getCategoryPathFieldName(): string
@@ -52,36 +63,30 @@ public function getCategoryPathFieldName(): string
5263

5364
private function standardPath(?Category $category): array
5465
{
55-
$path = 'ROOT';
66+
$path = 'ROOT';
5667
$value = $this->initial;
5768
foreach ($this->getParentCategories($category) as $item) {
5869
$value[] = sprintf("filter{$this->param}%s=%s", $path, urlencode(trim($item->getName())));
59-
$path .= urlencode('/' . trim($item->getName()));
70+
$path .= urlencode('/' . trim($item->getName()));
6071
}
6172

6273
return $value;
6374
}
6475

6576
private function ngPath(?Category $category): array
6677
{
67-
$path = implode('/', $this->getCategoryPath($category));
68-
69-
return $this->initial + [sprintf('filter=%s', urlencode($this->param . ':' . $path))];
78+
$path = implode('/', $this->createPathFromCategory($category));
79+
return [sprintf('filter=%s', urlencode($this->param . ':' . $path))];
7080
}
7181

72-
private function getCategoryPath(?Category $category): array
82+
private function createPathFromCategory(?Category $category): array
7383
{
7484
return array_map(function (Category $item): string {
7585
return (string) $item->getName();
7686
}, $category ? $category->getParentCategories() : []
7787
);
7888
}
7989

80-
public function getValue()
81-
{
82-
return $this;
83-
}
84-
8590
/**
8691
* @param Category|null $category
8792
*

src/ViewModel/Communication.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(
3838
public function getParameters(array $blockParams = []): array
3939
{
4040
$params = $this->parametersProvider->getParameters();
41-
return array_filter($this->mergeParameters($blockParams, $params) + $blockParams + $params, 'boolval');
41+
return ['version' => $params['version'] ?? 'ng'] + array_filter($this->mergeParameters($blockParams, $params) + $blockParams + $params, 'boolval');
4242
}
4343

4444
public function getFieldRoles(): string

src/view/frontend/layout/factfinder_category_view.xml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,26 @@
88

99
<referenceBlock name="after.body.start">
1010
<block class="Magento\Framework\View\Element\Template" name="factfinder.history.cb" template="Omikron_Factfinder::category/history_callback.phtml" after="factfinder.communication" />
11-
<block class="Magento\Framework\View\Element\Template" name="factfinder.category-filter.cb" template="Omikron_Factfinder::category/remove_category_filter_callback.phtml" after="factfinder.communication">
12-
<arguments>
13-
<argument name="category_path_field_name" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getCategoryPathFieldName"/>
14-
</arguments>
15-
</block>
1611
</referenceBlock>
1712

1813
<referenceBlock name="factfinder.communication">
1914
<arguments>
2015
<argument name="communication_parameters" xsi:type="array">
21-
<item name="add-params" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getValue" />
16+
<item name="add-params" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getAddParams" />
17+
<item name="category-page" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getCategoryPath" />
2218
</argument>
2319
</arguments>
2420
</referenceBlock>
2521

22+
<referenceBlock name="factfinder.asn">
23+
<arguments>
24+
<argument name="is_category_page" xsi:type="boolean">true</argument>
25+
</arguments>
26+
</referenceBlock>
27+
2628
<referenceBlock name="factfinder.ssr.recordlist">
2729
<arguments>
28-
<argument name="search_params" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getValue" />
30+
<argument name="search_params" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::__toString" />
2931
</arguments>
3032
</referenceBlock>
3133
</body>

src/view/frontend/layout/factfinder_product_list.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
</referenceBlock>
1111

1212
<referenceContainer name="sidebar.main">
13-
<block class="Magento\Framework\View\Element\Template" name="factfinder.asn" template="Omikron_Factfinder::ff/asn.phtml" />
13+
<block class="Magento\Framework\View\Element\Template" name="factfinder.asn" template="Omikron_Factfinder::ff/asn.phtml">
14+
<arguments>
15+
<argument name="category_path_field_name" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getCategoryPathFieldName"/>
16+
<argument name="is_category_page" xsi:type="boolean">false</argument>
17+
</arguments>
18+
<block class="Magento\Framework\View\Element\Template" name="factfinder.asn_group" as="asn_group" template="Omikron_Factfinder::ff/asn-group.phtml" />
19+
</block>
1420
</referenceContainer>
1521

1622
<referenceContainer name="content">

src/view/frontend/templates/category/remove_category_filter_callback.phtml

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php /** @var Magento\Framework\View\Element\Template $block */ ?>
2+
3+
<div slot="groupCaption" class="groupCaption">{{group.name}}</div>
4+
<ff-asn-group-element>
5+
<div slot="selected"><span class="filterName">{{element.name}}</span></div>
6+
<div slot="unselected"><span class="filterName">{{element.name}}</span></div>
7+
</ff-asn-group-element>
8+
9+
<div data-container="detailedLinks"><div data-content="detailedLinks"></div></div>
10+
<div data-container="hiddenLinks"><div data-content="hiddenLinks"></div></div>
11+
12+
<div data-container="removeFilter"><?= $block->escapeHtml(__('Remove Filter')) ?></div>
13+
<div data-container="showMore"><span class="text"><?= $block->escapeHtml(__('Show More')) ?></span></div>
14+
<div data-container="showLess"><span class="text"><?= $block->escapeHtml(__('Show Less')) ?></span></div>

0 commit comments

Comments
 (0)