Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SW-801 Export variants with different attribute values v1 #15

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d47f590
Added the fix for variants export regarding properties split
bojand-soprex Aug 22, 2023
ade23a8
Test adaptations
bojand-soprex Aug 23, 2023
eec3e5a
Lint fix
bojand-soprex Aug 23, 2023
3f8c9a6
Lint fix for multiline comma
bojand-soprex Aug 23, 2023
2ddb821
Refactor logic for Variant config and tests
bojand-soprex Oct 31, 2023
d93f2ec
Fix lint errors
bojand-soprex Nov 1, 2023
ec95f18
fix lint failed tests
bojand-soprex Nov 1, 2023
a910c0a
Fix tests PHp7.4
bojand-soprex Nov 1, 2023
83bdc28
Resolved PR comments
bojand-soprex Nov 1, 2023
a486585
VariantConfigurations logic refactor
bojand-soprex Nov 8, 2023
8ad3c4f
refactor optionsAdapter
bojand-soprex Nov 8, 2023
48921d8
Refactor variant logic, add AdapterHelper
bojand-soprex Nov 14, 2023
df10b68
Fix lint
bojand-soprex Nov 14, 2023
b23e67a
Refactor and test adaptations
bojand-soprex Nov 17, 2023
7d5d42b
Removed unceccesary check for isVariant
bojand-soprex Dec 15, 2023
d327d42
Refactor logic and adapt tests
bojand-soprex Dec 20, 2023
32c0bc7
Remove as parameter PR comment resolve
bojand-soprex Jan 4, 2024
9290ae8
Resolve PR comments and adaptati the logic and tests
bojand-soprex Feb 8, 2024
effc44d
Remove order number check from adaptProduct method
bojand-soprex Feb 8, 2024
aca53d7
Adapt tests and resolve PR comments
bojand-soprex Feb 20, 2024
0cb977e
Removed ordernumber hotfix
bojand-soprex Feb 26, 2024
e2080f0
Lint fix
bojand-soprex Feb 26, 2024
5748ebf
Remove pluginConfig setup from ExportItemAdapter
bojand-soprex Feb 27, 2024
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
20 changes: 19 additions & 1 deletion src/Export/Adapters/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class AdapterFactory

private NameAdapter $nameAdapter;

private OptionsAdapter $optionsAdapter;

private OrderNumberAdapter $orderNumberAdapter;

private PriceAdapter $priceAdapter;
Expand All @@ -38,6 +40,8 @@ class AdapterFactory

private UserGroupsAdapter $userGroupsAdapter;

private VariantConfigurationAdapter $variantConfigurationAdapter;

public function __construct(
AttributeAdapter $attributeAdapter,
BonusAdapter $bonusAdapter,
Expand All @@ -47,14 +51,16 @@ public function __construct(
ImagesAdapter $imagesAdapter,
KeywordsAdapter $keywordsAdapter,
NameAdapter $itemNameAdapter,
OptionsAdapter $optionsAdapter,
OrderNumberAdapter $orderNumberAdapter,
PriceAdapter $priceAdapter,
AbstractSalesFrequencyAdapter $salesFrequencyAdapter,
SortAdapter $sortAdapter,
SummaryAdapter $summaryAdapter,
ShopwarePropertiesAdapter $shopwarePropertiesAdapter,
UrlAdapter $urlAdapter,
UserGroupsAdapter $userGroupsAdapter
UserGroupsAdapter $userGroupsAdapter,
VariantConfigurationAdapter $variantConfigurationAdapter
) {
$this->attributeAdapter = $attributeAdapter;
$this->bonusAdapter = $bonusAdapter;
Expand All @@ -64,6 +70,7 @@ public function __construct(
$this->imagesAdapter = $imagesAdapter;
$this->keywordsAdapter = $keywordsAdapter;
$this->nameAdapter = $itemNameAdapter;
$this->optionsAdapter = $optionsAdapter;
$this->orderNumberAdapter = $orderNumberAdapter;
$this->priceAdapter = $priceAdapter;
$this->salesFrequencyAdapter = $salesFrequencyAdapter;
Expand All @@ -72,6 +79,7 @@ public function __construct(
$this->shopwarePropertiesAdapter = $shopwarePropertiesAdapter;
$this->urlAdapter = $urlAdapter;
$this->userGroupsAdapter = $userGroupsAdapter;
$this->variantConfigurationAdapter = $variantConfigurationAdapter;
bojand-soprex marked this conversation as resolved.
Show resolved Hide resolved
}

public function getAttributeAdapter(): AttributeAdapter
Expand Down Expand Up @@ -114,6 +122,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 @@ -153,4 +166,9 @@ public function getUserGroupsAdapter(): UserGroupsAdapter
{
return $this->userGroupsAdapter;
}

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);
}
78 changes: 10 additions & 68 deletions src/Export/Adapters/AttributeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
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;
bojand-soprex marked this conversation as resolved.
Show resolved Hide resolved

protected AbstractDynamicProductGroupService $dynamicProductGroupService;

protected AbstractCatUrlBuilderService $catUrlBuilderService;

protected ExportContext $exportContext;

protected PluginConfig $pluginConfig;

protected TranslatorInterface $translator;

public function __construct(
Expand Down Expand Up @@ -149,68 +148,24 @@ protected function getManufacturerAttributes(ProductEntity $product): array
}

/**
* @return Attribute[]
*/
protected function getPropertyAttributes(ProductEntity $product): array
{
if (!$product->properties || !$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
bojand-soprex marked this conversation as resolved.
Show resolved Hide resolved
{
if (!$product->options || !$product->options->count()) {
return [];
}

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

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

foreach ($collection as $propertyGroupOptionEntity) {
$group = $propertyGroupOptionEntity->group;
if ($group && !$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 ($group && $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 @@ -282,19 +237,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
{
protected 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 @@ -136,13 +136,20 @@ public function adaptProduct(Item $item, ProductEntity $product): ?Item
$item->addUsergroup($userGroup);
}

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

return $item;
}

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

try {
Expand All @@ -157,6 +164,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/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
{
protected 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;

bojand-soprex marked this conversation as resolved.
Show resolved Hide resolved
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/PriceAdapter.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 PriceAdapter
class PriceAdapter implements AdapterInterface
{
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
{
protected 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
Loading
Loading