Skip to content

Commit

Permalink
Merge branch 'v5' into SW-815_variant_product_is_exported_instead_of_…
Browse files Browse the repository at this point in the history
…the_main_product_although_configured_v5
  • Loading branch information
Radomir98 authored Oct 30, 2024
2 parents 5a2d07f + 372289e commit 11d4a21
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 5.1.2
* [SW-807] Überprüfungen für den Client hinzugefügt und neuen Client erstellt, wenn die base_uri nicht von Findologic stammt oder der Client nicht gesetzt ist.
* [SW-810] Sales Channel Logik für Language-ID angepasst.
* [SW-778] Erlaubt das Pipe-Zeichen im Namen der Property Values.
* [SW-805] Ein Problem behoben, bei dem falsche Preise exportiert wurden.


# 5.1.1

* [SW-804] Ein Problem wurde behoben, wodurch es zu Fehlern bei Filternamen mit "ß" kam.
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG_en-GB.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 5.1.2
* [SW-807] Added checks for Client and create new if client base_uri not from Findologic or client is not set
* [SW-810] Adapted sales channel logic for language id
* [SW-778] Allowing the pipe character in property values name
* [SW-805] Fixed a bug where wrong prices have been exported

# 5.1.1

* [SW-804] Fixed a bug for filter names containing the "ß" character.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "findologic/plugin-shopware-6",
"description": "Findologic plugin for Shopware 6",
"version": "5.1.1",
"version": "5.1.2",
"license": "GPL-3.0-or-later",
"type": "shopware-platform-plugin",
"authors": [
Expand Down
1 change: 0 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 14 additions & 4 deletions src/Export/Services/SalesChannelService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FINDOLOGIC\FinSearch\Export\Services;

use FINDOLOGIC\FinSearch\Findologic\Config\FindologicConfigService;
use FINDOLOGIC\FinSearch\Findologic\Config\FinSearchConfigEntity;
use FINDOLOGIC\FinSearch\Utils\Utils;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
Expand All @@ -22,7 +23,8 @@ class SalesChannelService
public function __construct(
private readonly EntityRepository $findologicConfigRepository,
private readonly AbstractSalesChannelContextFactory $salesChannelContextFactory,
private readonly RequestTransformerInterface $requestTransformer
private readonly RequestTransformerInterface $requestTransformer,
private readonly FindologicConfigService $findologicConfigService,
) {
}

Expand All @@ -40,21 +42,29 @@ public function getSalesChannelContext(
$currentContext->getContext()
);

$salesChannelContext = null;

/** @var FinSearchConfigEntity $systemConfigEntity */
foreach ($systemConfigEntities as $systemConfigEntity) {
if ($systemConfigEntity->getConfigurationValue() === $shopkey) {
return $this->salesChannelContextFactory->create(
$salesChannelContext = $this->salesChannelContextFactory->create(
$currentContext->getToken(),
$systemConfigEntity->getSalesChannelId(),
[
SalesChannelContextService::LANGUAGE_ID => $systemConfigEntity->getLanguageId(),
SalesChannelContextService::CUSTOMER_ID => $customerId
SalesChannelContextService::CUSTOMER_ID => $customerId,
SalesChannelContextService::CURRENCY_ID => $this->findologicConfigService->getDomainCurrencyId(
$currentContext,
$systemConfigEntity->getSalesChannelId(),
$systemConfigEntity->getLanguageId(),
),
]
);
$salesChannelContext->getSalesChannel()->setLanguageId($salesChannelContext->getLanguageId());
}
}

return null;
return $salesChannelContext;
}

/**
Expand Down
22 changes: 21 additions & 1 deletion src/Findologic/Client/ServiceConfigClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,27 @@ public function __construct(
private readonly string $shopkey,
private ?Client $client = null
) {
$this->client = $client ?? new Client(['base_uri' => BaseUrl::CDN]);
$this->initializeClient();
}

private function initializeClient(): void
{
if (!$this->client || $this->isBaseUrlDifferent()) {
$this->client = new Client(['base_uri' => BaseUrl::CDN]);
}
}

private function isBaseUrlDifferent(): bool
{
if (isset($this->client->getConfig()['base_uri'])) {
$scheme = $this->client->getConfig()['base_uri']->getScheme();
$host = $this->client->getConfig()['base_uri']->getHost();
$currentBaseUrl = $scheme . '://' . $host;

return $currentBaseUrl !== BaseUrl::CDN;
}

return false;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions src/Findologic/Config/FindologicConfigService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
use Shopware\Core\Framework\Uuid\Uuid;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Core\System\SystemConfig\Exception\InvalidDomainException;
use Shopware\Core\System\SystemConfig\Exception\InvalidKeyException;
use Shopware\Core\System\SystemConfig\Exception\InvalidSettingValueException;
Expand All @@ -27,6 +28,8 @@

class FindologicConfigService
{
public const DOMAIN_ID = 'FinSearch.config.domain';

private array $configs = [];

public function __construct(
Expand Down Expand Up @@ -277,4 +280,16 @@ private function getConfigValues(array $configValues, array $keys, $value): arra

return $configValues;
}

public function getDomainCurrencyId(SalesChannelContext $context, $channelId = null, $languageId = null): ?string
{
if ($domains = $context->getSalesChannel()->getDomains()) {
$domainId = (string) $this->get(self::DOMAIN_ID, $channelId, $languageId);
$domain = $domains->has($domainId) ? $domains->get($domainId) : $domains->first();

return $domain->getCurrencyId();
}

return null;
}
}
16 changes: 14 additions & 2 deletions src/Findologic/Request/Handler/FilterHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
class FilterHandler
{
public const FILTER_DELIMITER = '|';
public const FILTER_DELIMITER_ENCODED = '%7C';
protected const MIN_PREFIX = 'min-';
protected const MAX_PREFIX = 'max-';
protected const IGNORE_LIST = ['pushAttrib'];
Expand All @@ -36,6 +37,12 @@ public function handleFilters(
): void {
$request = $event->getRequest();
$selectedFilters = $request->query->all();
if (isset($selectedFilters['cat'])) {
$lastSubCategory = strrchr($selectedFilters['cat'], "|");
if ($lastSubCategory) {
$selectedFilters['cat'] = substr($lastSubCategory, 1);
}
}
$availableFilterNames = $this->fetchAvailableFilterNames($event);

if ($selectedFilters) {
Expand Down Expand Up @@ -186,9 +193,14 @@ protected function fetchAvailableFilterNames(ShopwareEvent|ProductListingCriteri
* imploded via a special character (|). The query parameter looks like ?size=20|21.
* This method simply explodes the given string into filter values.
*/
protected function getFilterValues(string $filterValues): array
public function getFilterValues(string $filterValues): array
{
return explode(self::FILTER_DELIMITER, $filterValues);
$filterValues = explode(self::FILTER_DELIMITER, $filterValues);

return array_map(
static fn (string $value) => str_replace(self::FILTER_DELIMITER_ENCODED, self::FILTER_DELIMITER, $value),
$filterValues
);
}

private function isMinRangeSlider(string $name): bool
Expand Down
10 changes: 7 additions & 3 deletions src/Findologic/Response/Json10/Filter/Values/FilterValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace FINDOLOGIC\FinSearch\Findologic\Response\Json10\Filter\Values;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;
use FINDOLOGIC\FinSearch\Findologic\Response\Json10\Filter\TranslatedName;
use Shopware\Core\Framework\Struct\Struct;

Expand All @@ -22,13 +23,16 @@ class FilterValue extends Struct
* The uuid is generated only for the values in which we need a unique ID for selection in storefront
*/
public function __construct(
private readonly string $id,
private readonly string $name,
private string $id,
private string $name,
?string $filterName = null
) {
$this->id = str_replace(FilterHandler::FILTER_DELIMITER, FilterHandler::FILTER_DELIMITER_ENCODED, $id);
$this->name = str_replace(FilterHandler::FILTER_DELIMITER, FilterHandler::FILTER_DELIMITER_ENCODED, $name);

$this->translated = new TranslatedName($name);
if ($filterName !== null) {
$this->uuid = sprintf('%s%s%s', $filterName, self::DELIMITER, $id);
$this->uuid = sprintf('%s%s%s', $filterName, self::DELIMITER, $this->id);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@
@selection-remove="onCategoryRemove"
>
</sw-category-tree-field>

<sw-entity-single-select
:label="$tc('findologic.settingForm.config.domain.label')"
:helpText="$tc('findologic.settingForm.config.domain.helpText')"
labelProperty="url"
valueProperty="id"
:criteria="domainCriteria"
show-clearable-button
entity="sales_channel_domain"
v-model="actualConfigData['FinSearch.config.domain']">
</sw-entity-single-select>
</div>
</sw-container>
</sw-card>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Component.register('findologic-config', {
required: false,
default: null,
},
selectedLanguageId: {
type: String,
required: false,
default: null,
},
isStagingShop: {
type: Boolean,
required: true,
Expand Down Expand Up @@ -146,6 +151,14 @@ Component.register('findologic-config', {

return criteria;
},

domainCriteria() {
const criteria = new Criteria(1, 25);
criteria.addFilter(Criteria.equals('salesChannelId', this.selectedSalesChannelId));
criteria.addFilter(Criteria.equals('languageId', this.selectedLanguageId));

return criteria;
},
},

created() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
:isValidShopkey="isValidShopkey"
:isStagingShop="isStagingShop"
:shopkeyErrorState="shopkeyErrorState"
:selectedSalesChannelId="selectedSalesChannelId">
:selectedSalesChannelId="selectedSalesChannelId"
:selectedLanguageId="selectedLanguageId">
</findologic-config>
{% endblock %}
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
"label": "Preis beim Kauf von einer Einheit"
}
},
"domain": {
"label": "Domain für Währung",
"helpText": "Diese Domain wird für Multi-Domain-Verkaufskanäle verwendet, und die Währung wird aus der ausgewählten Domain verwendet"
},
"exportZeroPricedProducts": {
"label": "Produkte ohne Preis exportieren",
"tooltipText": "Wenn deaktiviert, werden alle Produkte/Varianten mit einem Preis von 0 ausgeschlossen. Wenn das Hauptprodukt einen Preis von 0 hat, werden Varianten mit Preis trotzdem noch berücksichtigt."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
"label": "Price when buying one unit"
}
},
"domain": {
"label": "Domain for currency",
"helpText": "This domain is used for multi-domain sales channels, and the currency will be used from the selected domain"
},
"exportZeroPricedProducts": {
"label": "Export products without price",
"tooltipText": "If deactivated, products and variants with a price of 0 are excluded from the export. When parent products have a price of 0, variants with a price are still considered."
Expand Down
1 change: 1 addition & 0 deletions src/Resources/config/imports/services/export.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<argument type="service" id="finsearch_config.repository" />
<argument type="service" id="Shopware\Core\System\SalesChannel\Context\SalesChannelContextFactory" />
<argument type="service" id="Shopware\Core\Framework\Routing\RequestTransformerInterface" />
<argument type="service" id="FINDOLOGIC\FinSearch\Findologic\Config\FindologicConfigService" />
</service>

<service id="FINDOLOGIC\FinSearch\Export\Search\ProductCriteriaBuilder" public="true" autowire="true" />
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/config/imports/services/shopware6-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<service id="FINDOLOGIC\Shopware6Common\Export\Adapters\SortAdapter" public="true" autowire="true" />
<service id="FINDOLOGIC\Shopware6Common\Export\Adapters\SummaryAdapter" public="true" autowire="true" />
<service id="FINDOLOGIC\Shopware6Common\Export\Adapters\UrlAdapter" public="true" autowire="true" />

<service id="FINDOLOGIC\Shopware6Common\Export\Adapters\OptionsAdapter" public="true" autowire="true" />
<service id="FINDOLOGIC\Shopware6Common\Export\Adapters\VariantConfigurationAdapter" public="true" autowire="true" />
</services>
</container>
4 changes: 3 additions & 1 deletion src/Struct/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ public function initializeBySalesChannel(SalesChannelContext $salesChannelContex
{
$salesChannel = $salesChannelContext->getSalesChannel();
$salesChannelId = $salesChannel->getId();
$languageId = $salesChannel->getLanguageId();
if (!$languageId = $salesChannelContext->getLanguageId()) {
$languageId = $salesChannel->getId();
}

$this->active = $this->getConfig($salesChannelId, $languageId, 'FinSearch.config.active', false);
$this->shopkey = $this->getConfig($salesChannelId, $languageId, 'FinSearch.config.shopkey');
Expand Down
9 changes: 8 additions & 1 deletion src/Struct/QueryInfoMessage/CategoryInfoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace FINDOLOGIC\FinSearch\Struct\QueryInfoMessage;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;

class CategoryInfoMessage extends QueryInfoMessage
{
public function __construct(
protected readonly string $filterName,
protected readonly string $filterValue
protected string $filterValue
) {
$this->filterValue = str_replace(
FilterHandler::FILTER_DELIMITER_ENCODED,
FilterHandler::FILTER_DELIMITER,
$filterValue
);
}

public function getFilterName(): string
Expand Down
9 changes: 8 additions & 1 deletion src/Struct/QueryInfoMessage/VendorInfoMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@

namespace FINDOLOGIC\FinSearch\Struct\QueryInfoMessage;

use FINDOLOGIC\FinSearch\Findologic\Request\Handler\FilterHandler;

class VendorInfoMessage extends QueryInfoMessage
{
public function __construct(
protected readonly string $filterName,
protected readonly string $filterValue
protected string $filterValue
) {
$this->filterValue = str_replace(
FilterHandler::FILTER_DELIMITER_ENCODED,
FilterHandler::FILTER_DELIMITER,
$filterValue
);
}

public function getFilterName(): string
Expand Down
4 changes: 3 additions & 1 deletion tests/Export/Services/SalesChannelServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace FINDOLOGIC\FinSearch\Tests\Export;

use FINDOLOGIC\FinSearch\Export\Services\SalesChannelService;
use FINDOLOGIC\FinSearch\Findologic\Config\FindologicConfigService;
use FINDOLOGIC\FinSearch\Tests\Traits\DataHelpers\PluginConfigHelper;
use FINDOLOGIC\FinSearch\Tests\Traits\DataHelpers\SalesChannelHelper;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -51,7 +52,8 @@ private function getSalesChannelService(): SalesChannelService
return new SalesChannelService(
$configRepository,
$this->getContainer()->get(SalesChannelContextFactory::class),
$this->getContainer()->get(RequestTransformerInterface::class)
$this->getContainer()->get(RequestTransformerInterface::class),
$this->getContainer()->get(FindologicConfigService::class)
);
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Findologic/Request/Handler/FilterHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,15 @@ public function testOnlyStringValuesAreConsidered(): void
]
], $result['attrib']);
}

public function testGetFilterValues(): void
{
$filterHandler = new FilterHandler();
$filterValues = "pipe>1%7C3|pipe>2%7C3|pipe>3%7C3";

$actualFilters = $filterHandler->getFilterValues($filterValues);
$expectedFilters = ["pipe>1|3", "pipe>2|3", "pipe>3|3"];

$this->assertEquals($expectedFilters, $actualFilters);
}
}
Loading

0 comments on commit 11d4a21

Please sign in to comment.