Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Export/Adapters/AbstractSalesFrequencyAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\SalesFrequency;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

abstract class AbstractSalesFrequencyAdapter
abstract class AbstractSalesFrequencyAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?SalesFrequency
{
Expand Down
12 changes: 12 additions & 0 deletions src/Export/Adapters/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public function __construct(
private readonly ImagesAdapter $imagesAdapter,
private readonly KeywordsAdapter $keywordsAdapter,
private readonly NameAdapter $nameAdapter,
private readonly OptionsAdapter $optionsAdapter,
private readonly OrderNumberAdapter $orderNumberAdapter,
private readonly OverriddenPriceAdapter $overriddenPriceAdapter,
private readonly PriceAdapter $priceAdapter,
Expand All @@ -24,6 +25,7 @@ public function __construct(
private readonly SummaryAdapter $summaryAdapter,
private readonly ShopwarePropertiesAdapter $shopwarePropertiesAdapter,
private readonly UrlAdapter $urlAdapter,
private readonly VariantConfigurationAdapter $variantConfigurationAdapter,
) {
}

Expand Down Expand Up @@ -72,6 +74,11 @@ public function getNameAdapter(): NameAdapter
return $this->nameAdapter;
}

public function getOptionsAdapter(): OptionsAdapter
{
return $this->optionsAdapter;
}

public function getOrderNumbersAdapter(): OrderNumberAdapter
{
return $this->orderNumberAdapter;
Expand Down Expand Up @@ -111,4 +118,9 @@ public function getUrlAdapter(): UrlAdapter
{
return $this->urlAdapter;
}

public function getVariantConfigurationAdapter(): VariantConfigurationAdapter
{
return $this->variantConfigurationAdapter;
}
}
12 changes: 12 additions & 0 deletions src/Export/Adapters/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace FINDOLOGIC\Shopware6Common\Export\Adapters;

use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

interface AdapterInterface
{
public function adapt(ProductEntity $product);
}
74 changes: 10 additions & 64 deletions src/Export/Adapters/AttributeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
use FINDOLOGIC\Shopware6Common\Export\Services\AbstractDynamicProductGroupService;
use FINDOLOGIC\Shopware6Common\Export\Services\AbstractCatUrlBuilderService;
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use FINDOLOGIC\Shopware6Common\Traits\AdapterHelper;
use Symfony\Contracts\Translation\TranslatorInterface;
use Vin\ShopwareSdk\Data\Entity\Category\CategoryCollection;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;
use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionCollection;
use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionEntity;

class AttributeAdapter
class AttributeAdapter implements AdapterInterface
{
use AdapterHelper;

public function __construct(
protected readonly AbstractDynamicProductGroupService $dynamicProductGroupService,
protected readonly AbstractCatUrlBuilderService $catUrlBuilderService,
Expand Down Expand Up @@ -138,68 +141,24 @@ protected function getManufacturerAttributes(ProductEntity $product): array
}

/**
* @return Attribute[]
*/
protected function getPropertyAttributes(ProductEntity $product): array
{
if (!$product->properties?->count()) {
return [];
}

return $this->getPropertyGroupOptionAttributes($product->properties);
}

/**
* @deprecated tag:6.0.0 - Logic was moved to the OptionsAdapter
* @return Attribute[]
*/
protected function getOptionAttributes(ProductEntity $product): array
{
if (!$product->options?->count()) {
return [];
}

return $this->getPropertyGroupOptionAttributes($product->options);
return [];
}

/**
* @return Attribute[]
*/
protected function getPropertyGroupOptionAttributes(PropertyGroupOptionCollection $collection): array
{
$attributes = [];

foreach ($collection as $propertyGroupOptionEntity) {
if (!$propertyGroupOptionEntity->group?->filterable) {
continue;
}

$attributes = array_merge($attributes, $this->getAttributePropertyAsAttribute($propertyGroupOptionEntity));
}

return $attributes;
}

/**
* @return Attribute[]
*/
protected function getAttributePropertyAsAttribute(PropertyGroupOptionEntity $propertyGroupOptionEntity): array
protected function getPropertyAttributes(ProductEntity $product): array
{
$attributes = [];

$group = $propertyGroupOptionEntity->group;
if ($propertyGroupOptionEntity->getTranslation('name') && $group?->getTranslation('name')) {
$groupName = $this->getAttributeKey($group->getTranslation('name'));
$propertyGroupOptionName = $propertyGroupOptionEntity->getTranslation('name');

if (!Utils::isEmpty($groupName) && !Utils::isEmpty($propertyGroupOptionName)) {
$propertyGroupAttrib = new Attribute($groupName);
$propertyGroupAttrib->addValue(Utils::removeControlCharacters($propertyGroupOptionName));

$attributes[] = $propertyGroupAttrib;
}
if (!$product->properties || !$product->properties->count()) {
return [];
}

return $attributes;
return $this->getPropertyGroupOptionAttributes($product->properties);
}

protected function getCustomFieldAttributes(ProductEntity $product): array
Expand Down Expand Up @@ -267,19 +226,6 @@ protected function getAdditionalAttributes(ProductEntity $product): array
return $attributes;
}

/**
* For API Integrations, we have to remove special characters from the attribute key as a requirement for
* sending data via API.
*/
protected function getAttributeKey(?string $key): ?string
{
if ($this->pluginConfig->isIntegrationTypeApi()) {
return Utils::removeSpecialChars($key);
}

return $key;
}

/**
* @param array<string, int, bool>|string|int|bool $value
*
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/BonusAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\Bonus;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class BonusAdapter
class BonusAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?Bonus
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/DateAddedAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\DateAdded;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class DateAddedAdapter
class DateAddedAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?DateAdded
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/DefaultPropertiesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Symfony\Contracts\Translation\TranslatorInterface;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class DefaultPropertiesAdapter
class DefaultPropertiesAdapter implements AdapterInterface
{
public function __construct(
protected readonly ExportContext $exportContext,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/DescriptionAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class DescriptionAdapter
class DescriptionAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?Description
{
Expand Down
13 changes: 12 additions & 1 deletion src/Export/Adapters/ExportItemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,19 @@ public function adaptProduct(Item $item, ProductEntity $product): ?Item
$item->addGroup($group);
}

foreach ($this->adapterFactory->getOptionsAdapter()->adapt($product) as $attribute) {
$item->addMergedAttribute($attribute);
}

return $item;
}

public function adaptVariant(Item $item, ProductEntity $product): ?Item
{
$this->eventDispatcher?->dispatch(new BeforeVariantAdaptEvent($product, $item), BeforeVariantAdaptEvent::NAME);
$this->eventDispatcher->dispatch(
new BeforeVariantAdaptEvent($product, $item),
BeforeVariantAdaptEvent::NAME,
);

try {
foreach ($this->adapterFactory->getOrderNumbersAdapter()->adapt($product) as $orderNumber) {
Expand All @@ -147,6 +154,10 @@ public function adaptVariant(Item $item, ProductEntity $product): ?Item
foreach ($this->adapterFactory->getShopwarePropertiesAdapter()->adapt($product) as $property) {
$item->addProperty($property);
}

foreach ($this->adapterFactory->getVariantConfigurationAdapter()->adapt($product) as $attribute) {
$item->addMergedAttribute($attribute);
}
} catch (Throwable $exception) {
$exceptionLogger = new ExportExceptionLogger($this->logger);
$exceptionLogger->log($product, $exception);
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/GroupsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use FINDOLOGIC\Shopware6Common\Export\ExportContext;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class GroupsAdapter
class GroupsAdapter implements AdapterInterface
{
public function __construct(
protected readonly ExportContext $exportContext,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/ImagesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\Image;
use FINDOLOGIC\Shopware6Common\Export\Services\ProductImageService;

class ImagesAdapter
class ImagesAdapter implements AdapterInterface
{
public function __construct(
protected readonly ProductImageService $productImageService,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/KeywordsAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;
use FINDOLOGIC\Shopware6Common\Export\ExportContext;

class KeywordsAdapter
class KeywordsAdapter implements AdapterInterface
{
protected ExportContext $exportContext;

Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/NameAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class NameAdapter
class NameAdapter implements AdapterInterface
{
/**
* @throws ProductHasNoNameException
Expand Down
32 changes: 32 additions & 0 deletions src/Export/Adapters/OptionsAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace FINDOLOGIC\Shopware6Common\Export\Adapters;

use FINDOLOGIC\Export\Data\Attribute;
use FINDOLOGIC\Shopware6Common\Export\Config\PluginConfig;
use FINDOLOGIC\Shopware6Common\Traits\AdapterHelper;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class OptionsAdapter implements AdapterInterface
{
use AdapterHelper;

public function __construct(PluginConfig $pluginConfig)
{
$this->pluginConfig = $pluginConfig;
}

/**
* @return Attribute[]
*/
public function adapt(ProductEntity $product): array
{
if (!$product->options || !$product->options->count()) {
return [];
}

return $this->getPropertyGroupOptionAttributes($product->options);
}
}
2 changes: 1 addition & 1 deletion src/Export/Adapters/OrderNumberAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class OrderNumberAdapter
class OrderNumberAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/OverriddenPriceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class OverriddenPriceAdapter
class OverriddenPriceAdapter implements AdapterInterface
{
public function __construct(
protected ExportContext $exportContext,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/PriceAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use FINDOLOGIC\Shopware6Common\Export\Utils\Utils;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class PriceAdapter
class PriceAdapter implements AdapterInterface
{
public function __construct(
protected ExportContext $exportContext,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/ShopwarePropertiesAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;
use Vin\ShopwareSdk\Data\Entity\PropertyGroupOption\PropertyGroupOptionEntity;

class ShopwarePropertiesAdapter
class ShopwarePropertiesAdapter implements AdapterInterface
{
public function __construct(
protected readonly PluginConfig $pluginConfig,
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/SortAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\Sort;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class SortAdapter
class SortAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?Sort
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/SummaryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FINDOLOGIC\Export\Data\Summary;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class SummaryAdapter
class SummaryAdapter implements AdapterInterface
{
public function adapt(ProductEntity $product): ?Summary
{
Expand Down
2 changes: 1 addition & 1 deletion src/Export/Adapters/UrlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use FINDOLOGIC\Shopware6Common\Export\Services\ProductUrlService;
use Vin\ShopwareSdk\Data\Entity\Product\ProductEntity;

class UrlAdapter
class UrlAdapter implements AdapterInterface
{
public function __construct(
protected readonly ProductUrlService $productUrlService,
Expand Down
Loading