Skip to content

Commit

Permalink
FFWEB-3229: Add the ability to set CategoryPath
Browse files Browse the repository at this point in the history
Add the ability to set a name for the CategoryPath field
  • Loading branch information
Rayn93 authored Nov 26, 2024
1 parent 1d00e0b commit 27d41ae
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
## Unreleased
### Improve
- Add the ability to set a name for the CategoryPath field

## [v5.0.1] - 2024.11.07
### Update
- Update FactFinder logo
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ Sending each request to FACT-Finder instance trough Magento, you lose on perform
Module in order to preserve categories URLs and hence SEO get use of standard Magento routing with the combination of FACT-Finder availability to pass custom parameters to search request.
Once user is landed on category page. Search request is performed immediately (thanks to `searchImmediately` parameter usage).
To enable that, turn on corresponding option in *Main Settings* section.

#### Set correct name for CategoryPath field
By default, SDK uses a field named CategoryPath (default category field name for FactFinder instance). If in your FactFinder instance configuration you have a different field name for Category field then you must set this name in the SDK configuration page:

![Main Settings](docs/assets/category-field-name.png "Category field name")

### Tracking
The module uses Web Components API to track following events:
Expand Down
Binary file added docs/assets/category-field-name.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/Test/Unit/ViewModel/CategoryPathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Omikron\Factfinder\ViewModel;

use Magento\Catalog\Model\Category;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Registry;
use Omikron\Factfinder\Model\Config\CommunicationConfig;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -24,6 +25,9 @@ class CategoryPathTest extends TestCase
/** @var MockObject|CommunicationConfig */
private MockObject $communicationConfig;

/** @var MockObject|ScopeConfigInterface */
private MockObject $scopeConfig;

public function test_category_names_are_trimmed()
{
$this->communicationConfig->method('getVersion')->willReturn('ng');
Expand All @@ -39,6 +43,7 @@ public function test_category_names_are_trimmed()
protected function setUp(): void
{
$this->communicationConfig = $this->createMock(CommunicationConfig::class);
$this->scopeConfig = $this->createMock(ScopeConfigInterface::class);
$this->currentCategory = $this->createMock(Category::class);
$this->registry = new Registry();
$this->registry->register('current_category', $this->currentCategory);
Expand All @@ -51,6 +56,6 @@ private function category(string $name, int $level): Category

private function newCategoryPath(): CategoryPath
{
return new CategoryPath($this->registry, $this->communicationConfig);
return new CategoryPath($this->registry, $this->communicationConfig, $this->scopeConfig);
}
}
11 changes: 7 additions & 4 deletions src/ViewModel/CategoryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@
namespace Omikron\Factfinder\ViewModel;

use Magento\Catalog\Model\Category;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Registry;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Store\Model\ScopeInterface as Scope;
use Omikron\Factfinder\Model\Config\CommunicationConfig;

class CategoryPath implements ArgumentInterface
{
private const PATH_CATEGORY_PATH_NAME = 'factfinder/general/category_path_name';

public function __construct(
private readonly Registry $registry,
private readonly Registry $registry,
private readonly CommunicationConfig $communicationConfig,
private readonly string $param = 'CategoryPath',
private readonly array $initial = [],
private readonly ScopeConfigInterface $scopeConfig,
) {
}

Expand All @@ -33,7 +36,7 @@ public function getCategoryPath(): array

public function getCategoryPathFieldName(): string
{
return $this->param;
return $this->scopeConfig->getValue(self::PATH_CATEGORY_PATH_NAME, Scope::SCOPE_STORE) ?? 'CategoryPath';
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/etc/adminhtml/system/general.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
<label>Use FACT-Finder® for category pages?</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="use_ssr" translate="label" type="select" sortOrder="76" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="category_path_name" translate="label" type="text" sortOrder="76" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Category Path field name</label>
<depends>
<field id="use_for_categories">1</field>
</depends>
</field>
<field id="use_ssr" translate="label" type="select" sortOrder="77" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Use server-side rendering?</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
Expand Down
1 change: 1 addition & 0 deletions src/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<logging_enabled>0</logging_enabled>
<ff_api_key backend_model="Magento\Config\Model\Config\Backend\Encrypted" />
<use_for_categories>1</use_for_categories>
<category_path_name>CategoryPath</category_path_name>
<show_add_to_cart_button>1</show_add_to_cart_button>
<ff_enrichment>0</ff_enrichment>
<tracking_product_number_field_role>{"brand":"Brand","deeplink":"Deeplink","description":"Description","ean":"EAN","imageUrl":"ImageURL","masterId":"Master","price":"Price","productName":"Name","productNumber":"ProductNumber"}</tracking_product_number_field_role>
Expand Down
1 change: 1 addition & 0 deletions src/view/frontend/layout/factfinder_category_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<block class="Magento\Framework\View\Element\Template" name="factfinder.category.page" template="Omikron_Factfinder::category/category_page.phtml" after="factfinder.communication" >
<arguments>
<argument name="category_path" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getCategoryPath" />
<argument name="category_path_field_name" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::getCategoryPathFieldName" />
</arguments>
</block>
</referenceBlock>
Expand Down
3 changes: 2 additions & 1 deletion src/view/frontend/templates/category/category_page.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
/** @var Magento\Framework\View\Element\Template $block */
/** @var Magento\Framework\Escaper $escaper */
$categoryPath = (array) $block->getData('category_path');
$categoryPathFieldName = $block->getData('category_path_field_name');
?>

<script>
document.addEventListener(`ffCoreReady`, ({ factfinder }) => {
factfinder.config.setAppConfig({
categoryPage: [
factfinder.utils.filterBuilders.categoryFilter(`CategoryPath`, <?= /* @noEscape */ json_encode($categoryPath); ?>)
factfinder.utils.filterBuilders.categoryFilter('<?= /* @noEscape */ $categoryPathFieldName ?>', <?= /* @noEscape */ json_encode($categoryPath); ?>)
],
});

Expand Down

0 comments on commit 27d41ae

Please sign in to comment.