Skip to content

Commit

Permalink
Implement category path
Browse files Browse the repository at this point in the history
  • Loading branch information
Rayn93 committed Apr 16, 2024
1 parent f701dc3 commit 9e1769d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 55 deletions.
11 changes: 7 additions & 4 deletions src/ViewModel/CategoryPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ public function __toString()
) : $this->getAddParams();
}

public function getCategoryPath(): string
public function getCategoryPath(): array
{
if ($this->communicationConfig->getVersion() === Version::NG) {
return implode(',', $this->ngPath($this->getCurrentCategory()));
$values = [];

foreach ($this->getParentCategories($this->getCurrentCategory()) as $item) {
$categoryName = trim($item->getName());
$values[] = $categoryName;
}

return '';
return $values;
}

public function getAddParams(): string
Expand Down
2 changes: 2 additions & 0 deletions src/view/frontend/layout/default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
<arguments>
<argument name="subscribe" xsi:type="boolean">true</argument>
<argument name="view_model" xsi:type="object">Omikron\Factfinder\ViewModel\ProductBasedComponent</argument>
<argument name="is_search_request" xsi:type="boolean">true</argument>
</arguments>
</block>
<block class="Magento\Framework\View\Element\Template" name="factfinder.recordlist.unsubscribed" template="Omikron_Factfinder::ff/record-list.phtml">
<arguments>
<argument name="subscribe" xsi:type="boolean">false</argument>
<argument name="view_model" xsi:type="object">Omikron\Factfinder\ViewModel\ProductBasedComponent</argument>
<argument name="is_search_request" xsi:type="boolean">false</argument>
</arguments>
</block>

Expand Down
9 changes: 7 additions & 2 deletions src/view/frontend/layout/factfinder_category_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

<referenceBlock name="after.body.start">
<block class="Magento\Framework\View\Element\Template" name="factfinder.history.cb" template="Omikron_Factfinder::category/history_callback.phtml" after="factfinder.communication" />
<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" />
</arguments>
</block>
</referenceBlock>

<referenceBlock name="factfinder.communication">
Expand All @@ -25,9 +30,9 @@
</arguments>
</referenceBlock>

<referenceBlock name="factfinder.ssr.recordlist">
<referenceBlock name="factfinder.recordlist">
<arguments>
<argument name="search_params" xsi:type="helper" helper="Omikron\Factfinder\ViewModel\CategoryPath::__toString" />
<argument name="is_search_request" xsi:type="boolean">false</argument>
</arguments>
</referenceBlock>

Expand Down
15 changes: 15 additions & 0 deletions src/view/frontend/templates/category/category_page.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/** @var Magento\Framework\View\Element\Template $block */
/** @var Magento\Framework\Escaper $escaper */
$categoryPath = (array) $block->getData('category_path');
?>

<script>
document.addEventListener(`ffCoreReady`, ({ factfinder }) => {
factfinder.config.categoryPage = [
factfinder.utils.filterBuilders.categoryFilter(`CategoryPath`, <?php echo json_encode($categoryPath); ?> )
];

factfinder.request.navigation({'filters': factfinder.config.categoryPage}, { requestOptions: { origin: `searchImmediately` } });
});
</script>
38 changes: 0 additions & 38 deletions src/view/frontend/templates/category/history_callback.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,3 @@
<!-- });-->
<!-- });-->
<!--</script>-->
<script>
document.addEventListener(`ffCoreReady`, ({ factfinder }) => {
// const cfg = factfinder.config.defaults.general;
//
// cfg.url = `https://your-instance.fact-finder.de/fact-finder`;
// cfg.channel = `your-channel`;
//
// factfinder.config.apiKey = `your.apiKey`;
//
// factfinder.request.search(
//
// // Typically, you would make your server application insert the query string here
// // before responding to the client.
// { query: `dynamically generated query` },
//
// // Specifying `origin` is optional.
// // You can use it to tell your 'before search' listeners who initiated the request
// // and allow them to react appropriately.
// { requestOptions: { origin: `searchImmediately` } }
// );
// });

factfinder.config.categoryPage = [
factfinder.utils.filterBuilders.categoryFilter(`Category`, ["Women", "Bottoms"]),
];

factfinder.request.navigation(
// Typically, you would make your server application insert the query string here
// before responding to the client.
{ filters: ['CategoryPath': ['Women/Bottoms/Pants'] },
//
// // Specifying `origin` is optional.
// // You can use it to tell your 'before search' listeners who initiated the request
// // and allow them to react appropriately.
{requestOptions: {origin: `searchImmediately`}}
);
});
</script>
3 changes: 2 additions & 1 deletion src/view/frontend/templates/ff/asn.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
/** @var string $categoryPathFieldName */
$categoryPathFieldName = (string) $block->getData('category_path_field_name');
/** @var bool $isCategoryPage */
$isCategoryPage = (bool) $block->getData('is_category_page'); ?>
$isCategoryPage = (bool) $block->getData('is_category_page');
?>

<div class="ff-asn">
<ff-asn align="vertical" unresolved>
Expand Down
2 changes: 0 additions & 2 deletions src/view/frontend/templates/ff/communication.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
$viewModel = $block->getViewModel();
$communicationParameters = (array) $block->getData('communication_parameters');
$parameters = $viewModel->getParameters($communicationParameters);

//dump($communicationParameters); die();
?>

<!--Init webcomponents-->
Expand Down
19 changes: 11 additions & 8 deletions src/view/frontend/templates/ff/record-list.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/** @var Magento\Framework\View\Element\Template $block */
/** @var Omikron\Factfinder\ViewModel\ProductBasedComponent $viewModel */
$viewModel = $block->getViewModel();
$isSearchRequest = (bool) $block->getData('is_search_request');
?>
<div class="products wrapper grid products-grid">
<ff-record-list class="products list items product-items"
Expand Down Expand Up @@ -50,14 +51,16 @@ $viewModel = $block->getViewModel();
</ff-record-list>
</div>

<script>
// Execute search request
document.addEventListener(`ffCoreReady`, ({ factfinder }) => {
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('query');
factfinder.request.search({ query: query }, { requestOptions: { origin: `searchImmediately` } });
});
</script>
<?php if ($isSearchRequest): ?>
<script>
// Execute search request
document.addEventListener(`ffCoreReady`, ({ factfinder }) => {
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('query');
factfinder.request.search({ query: query }, { requestOptions: { origin: `searchImmediately` } });
});
</script>
<?php endif; ?>

<script>
require(['jquery', 'underscore', 'catalogAddToCart'], function ($, _) {
Expand Down

0 comments on commit 9e1769d

Please sign in to comment.