Skip to content

Commit

Permalink
RelatedItemsPro Support
Browse files Browse the repository at this point in the history
  • Loading branch information
sisilvic committed Nov 2, 2021
1 parent f36534b commit c66d1b2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
27 changes: 24 additions & 3 deletions plugin/src/AlgoliaSync.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ private function algoliaData(\Item $item): ?array
/** @var Type $type */
$type = $item->getType();

$config = new Registry($this->renderer->getConfig('root:plugins/system/zooalgolia/renderer/item')->get($application->getGroup() . '.' . $type->identifier . '.algolia'));
$config = $config->get('search', []);

if (!count($config)) {
return null;
}

$this->categories = $application->getCategoryTree();
$data = [
'id' => $item->id,
Expand All @@ -155,9 +162,6 @@ private function algoliaData(\Item $item): ?array
$data['url'][$lang] = $this->getItemUrls($item, $lang);
};


$config = new Registry($this->renderer->getConfig('root:plugins/system/zooalgolia/renderer/item')->get($application->getGroup() . '.' . $type->identifier . '.algolia'));
$config = $config->get('search', []);
foreach ($config as $elementConfig) {
$element = $item->getElement($elementConfig['element']);

Expand Down Expand Up @@ -307,6 +311,23 @@ private function elementValueFor(\Element $element, array $params)
return $values ? array_shift($values) : null;
}

if ($element instanceof \ElementRelatedItemsPro) {
$related_items = $element->getRelatedItems(true);

$items = [];

foreach ($related_items as $item)
{
$data = $this->algoliaData($item);
if ($data) {
$items[] = $this->algoliaData(($item));
}
}

return $items;

}

if ($element instanceof \ElementOption) {

$values = $element->get('option', []);
Expand Down
2 changes: 1 addition & 1 deletion plugin/zooalgolia.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="system" method="upgrade" version="3.0">
<name>ZOO - Algolia Integration</name>
<version>2.0.1</version>
<version>2.1.0</version>
<creationDate>October 2021</creationDate>
<copyright>(C) 2021 Weble Srl</copyright>
<license>GNU GPLv2 or later</license>
Expand Down

0 comments on commit c66d1b2

Please sign in to comment.