Skip to content

Commit

Permalink
Merge pull request #226 from EmicoEcommerce/beta
Browse files Browse the repository at this point in the history
Merge beta into master
  • Loading branch information
ah-net authored Oct 16, 2024
2 parents 5d9083b + 092d673 commit ceed641
Show file tree
Hide file tree
Showing 27 changed files with 475 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ protected function getAnchorTagAttributes(Item $item): array
*/
protected function getItemUrl(Item $item)
{
return $this->escapeHtml($item->getUrl());
return $item->getUrl();
}
}
6 changes: 3 additions & 3 deletions Block/LayeredNavigation/RenderLayered/DefaultRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected function getFacetSettings()
*/
public function getCategoryUrl(Item $item): string
{
$catUrl = $this->escapeUrl($item->getUrl());
$catUrl = $item->getUrl();

if (strpos($catUrl, $this->getBaseUrl()) === false) {
$catUrl = $this->getBaseUrl() . $item->getUrl();
Expand Down Expand Up @@ -283,15 +283,15 @@ public function showCheckbox()
*/
public function getItemPrefix()
{
return $this->escapeHtml($this->getFacetSettings()->getPrefix());
return $this->getFacetSettings()->getPrefix();
}

/**
* @return string
*/
public function getItemPostfix()
{
return $this->escapeHtml($this->getFacetSettings()->getPostfix());
return $this->getFacetSettings()->getPostfix();
}

/**
Expand Down
63 changes: 63 additions & 0 deletions Block/LayeredNavigation/RenderLayered/SliderRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,67 @@ public function getCssId()

return 'slider-' . $urlKey;
}

/**
* @return bool
*/
public function containsBuckets(): bool
{
return $this->filter->getFacet()->getFacetSettings()->containsBuckets();
}

/**
* @return bool
*/
public function containsClickpoints(): bool
{
return $this->filter->getFacet()->getFacetSettings()->containsClickpoints();
}

/**
* @return array
*/
public function getBuckets(): array
{
if ($this->containsBuckets()) {
return $this->filter->getFacet()->getBuckets();
}

return [];
}

public function getClickPoints(): array
{
if ($this->containsClickpoints()) {
return $this->filter->getFacet()->getClickpoints();
}

return [];
}

public function getBucketHightFactor(): float
{
$maxRelativeRange = 1;
if ($this->containsBuckets()) {
$buckets = $this->getBuckets();
foreach ($buckets as $bucket) {
//get max range from bucket array
if ($bucket['relativeamount'] > $maxRelativeRange) {
$relativeAmount = ceil($bucket['relativeamount']);
if ($relativeAmount > $maxRelativeRange) {
$maxRelativeRange = $relativeAmount;
}
}
}
}

$bucketHightFactor = 60 / $maxRelativeRange;

return $bucketHightFactor;
}

public function getTotalrange(): float
{
return ($this->getMaxValue() - $this->getMinValue());
}
}
28 changes: 26 additions & 2 deletions Model/Catalog/Layer/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class Filter extends AbstractFilter implements FilterInterface
*/
protected $items;

/**
* @var array
*/
protected $buckets;

/**
* @var Layer
*/
Expand Down Expand Up @@ -174,6 +179,18 @@ public function getItems()
return $this->items;
}

/**
* @return array
*/
public function getBuckets(): array
{
if (!$this->buckets) {
$this->initBuckets();
}

return $this->buckets;
}

/**
* @param AttributeType $item
* @return $this
Expand Down Expand Up @@ -257,8 +274,7 @@ public function getAttributeModel()
*/
public function getName()
{
$title = (string) $this->facet->getFacetSettings()->getTitle();
return htmlentities($title);
return (string) $this->facet->getFacetSettings()->getTitle();
}

/**
Expand Down Expand Up @@ -375,6 +391,14 @@ protected function initItems()
return $this;
}

/**
* @return void
*/
protected function initBuckets(): void
{
$this->buckets = $this->facet->getBuckets();
}

/**
* @return int[]
*/
Expand Down
8 changes: 6 additions & 2 deletions Model/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,16 @@ class Client
* @param Logger $log
* @param ResponseFactory $responseFactory
* @param EndpointManager $endpointManager
* @param Timer $timer
* @param ModuleInformation $moduleInformation
*/
public function __construct(
Config $config,
Logger $log,
ResponseFactory $responseFactory,
EndpointManager $endpointManager,
Timer $timer
Timer $timer,
private readonly ModuleInformation $moduleInformation
) {
$this->config = $config;
$this->log = $log;
Expand All @@ -96,7 +99,8 @@ protected function getClient(): HttpClient
RequestOptions::TIMEOUT => self::REQUEST_TIMEOUT,
RequestOptions::HEADERS => [
'user-agent' => $this->config->getUserAgentString(),
'Accept-Encoding' => 'gzip, deflate'
'Accept-Encoding' => 'gzip, deflate',
'TWN-Source' => $this->moduleInformation->getModuleVersion(),
]
];
$this->client = new HttpClient($options);
Expand Down
32 changes: 31 additions & 1 deletion Model/Client/Type/FacetType.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function setAttributes(array $attributes)
$this->data['attributes'] = $values;
return $this;
}

public function getFacetSettings(): ?SettingsType
{
return $this->getValue('facet_settings');
Expand All @@ -64,4 +64,34 @@ public function getAttributes(): ?array
{
return $this->getValue('attributes');
}

/**
* @return array
*/
public function getBuckets(): array
{
//only return buckets if there is more than one bucket
if (isset($this->data['buckets']['bucket'][0]) && is_array($this->data['buckets']['bucket'][0])) {
return $this->data['buckets']['bucket'];
}

return [];
}

/**
* @return array
*/
public function getClickpoints(): array
{
if (
isset($this->data['clickpoints']['clickpoint'][0])
&& is_array($this->data['clickpoints']['clickpoint'][0])
) {
return $this->data['clickpoints']['clickpoint'];
} elseif (isset($this->data['clickpoints']['clickpoint'])) {
return $this->data['clickpoints'];
}

return [];
}
}
16 changes: 16 additions & 0 deletions Model/Client/Type/FacetType/SettingsType.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,20 @@ public function getSearchNoResultsText()
{
return empty($this->getValue('searchnoresultstext')) ? '' : $this->getValue('searchnoresultstext');
}

/**
* @return bool
*/
public function containsBuckets(): bool
{
return $this->getBoolValue('containsbuckets');
}

/**
* @return bool
*/
public function containsClickpoints(): bool
{
return $this->getBoolValue('containsclickpoints');
}
}
35 changes: 35 additions & 0 deletions Model/ModuleInformation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Tweakwise\Magento2Tweakwise\Model;

use Magento\Framework\Composer\ComposerInformation;

class ModuleInformation
{
/**
* @param ComposerInformation $composerInformation
*/
public function __construct(
private readonly ComposerInformation $composerInformation
) {
}

/**
* @return string
*/
public function getModuleVersion(): string
{
$installedPackages = $this->composerInformation
->getInstalledMagentoPackages();
if (!isset($installedPackages['tweakwise/magento2-tweakwise']['version'])) {
// This should never be the case
return '';
}

$version = $installedPackages['tweakwise/magento2-tweakwise']['version'];

return sprintf('Magento2Tweakwise %s', $version);
}
}
2 changes: 2 additions & 0 deletions Model/NavigationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ public function getJsSliderConfig(SliderRenderer $sliderRenderer)
'max' => $sliderRenderer->getMaxValue(),
'currentMin' => $sliderRenderer->getCurrentMinValue(),
'currentMax' => $sliderRenderer->getCurrentMaxValue(),
'containsBuckets' => $sliderRenderer->containsBuckets(),
'containsClickpoints' => $sliderRenderer->containsClickpoints(),
]
]
);
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<section id="tweakwise">
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>General</label>
<comment>Tweakwise version v8.1.0</comment>
<comment>Tweakwise version v8.2.0</comment>
<field id="authentication_key" translate="label,comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Authentication key</label>
<comment>Provided by Tweakwise (8 alphanumeric characters)</comment>
Expand Down
2 changes: 1 addition & 1 deletion etc/crontab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Cron:etc/crontab.xsd">
<group id="default">
<group id="tweakwise">
<job name="Tweakwise_Magento2Tweakwise_version" instance="Tweakwise\Magento2Tweakwise\Cron\Version" method="execute">
<!-- once every day at midnight-->
<schedule>0 0 * * *</schedule>
Expand Down
7 changes: 3 additions & 4 deletions view/frontend/templates/form.mini.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
/**
* @var $block \Tweakwise\Magento2Tweakwise\Block\Autocomplete\FormMini
* @var $escaper Escaper
* phpcs:disable Magento2.Security.XssTemplate.FoundUnescaped
* phpcs:disable Magento2.Legacy.PhtmlTemplate.TextJavascriptTypeFound
*/

Expand Down Expand Up @@ -43,7 +42,7 @@ use Magento\Framework\Escaper;
<% } else { %>
<span class="special-price">
<span class="price-container">
<span class="price-label"><?=__('Special Price')?></span>
<span class="price-label"><?=$escaper->escapeHtml(__('Special Price'))?></span>
<span class="price-wrapper">
<span class="price"><%= autocompleteFormatPrice(data.final_price) %></span>
</span>
Expand All @@ -52,7 +51,7 @@ use Magento\Framework\Escaper;

<span class="old-price sly-old-price">
<span class="price-container">
<span class="price-label"><?=__('Regular Price')?></span>
<span class="price-label"><?=$escaper->escapeHtml(__('Regular Price'))?></span>
<span class="price-wrapper">
<span class="price"><%= autocompleteFormatPrice(data.price) %></span>
</span>
Expand Down Expand Up @@ -88,7 +87,7 @@ use Magento\Framework\Escaper;
<script type="text/javascript">
require(['Magento_Catalog/js/price-utils'], function(priceUtils){
window['autocompleteFormatPrice'] = function(price) {
return priceUtils.formatPrice(price, <?=$block->getJsonPriceFormat()?>);
return priceUtils.formatPrice(price, <?= /* @noEscape */($block->getJsonPriceFormat())?>);
};
});
</script>
7 changes: 3 additions & 4 deletions view/frontend/templates/layer/state.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use Magento\Framework\Escaper;
*
* @var $block \Tweakwise\Magento2Tweakwise\Block\LayeredNavigation\Navigation\State
* @var $escaper Escaper
* phpcs:disable Magento2.Security.XssTemplate.FoundUnescaped
*/
?>
<?php /** @var Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\Filter\Item[] $_filters */ ?>
Expand All @@ -27,7 +26,7 @@ use Magento\Framework\Escaper;
role="heading"
aria-level="2"
data-role="title"
data-count="<?= /* @noEscape */ count($_filters) ?>"><?= $escaper->escapeHtml(__('Now Shopping by')) ?>
data-count="<?= count($_filters) ?>"><?= $escaper->escapeHtml(__('Now Shopping by')) ?>
</strong>
<ol class="items">
<?php foreach ($_filters as $_filter): ?>
Expand All @@ -43,8 +42,8 @@ use Magento\Framework\Escaper;
);
?>
<a class="action remove" href="<?= $escaper->escapeUrl($_filter->getRemoveUrl()) ?>"
data-js-filter-id="<?=$block->getActiveFilterCssId($_filter)?>"
title="<?= /* @noEscape */ $escaper->escapeHtmlAttr(__('Remove')) . " " . $currentFilterName ?>">
data-js-filter-id="<?=$escaper->escapeHtmlAttr($block->getActiveFilterCssId($_filter))?>"
title="<?= $escaper->escapeHtmlAttr(__('Remove') . " " . $currentFilterName)?>">
<span><?= $escaper->escapeHtml(__('Remove This Item')) ?></span>
</a>
</li>
Expand Down
Loading

0 comments on commit ceed641

Please sign in to comment.