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: 2 additions & 0 deletions src/Export/Adapters/AttributeAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,7 @@ protected function translateBooleanValue(bool $value): string
$translationKey = $value ? 'finSearch.general.yes' : 'finSearch.general.no';

return $this->translator->trans($translationKey);

//test
}
}
39 changes: 37 additions & 2 deletions src/Export/Adapters/ExportItemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,43 @@ public function adaptVariant(Item $item, ProductEntity $product): ?Item
$item->addOrdernumber($orderNumber);
}

foreach ($this->adapterFactory->getAttributeAdapter()->adapt($product) as $attribute) {
$item->addMergedAttribute($attribute);
/**Only in case the export is set to "Main/Parent product"
* we merge all the variants specifications"*
*/
if ($item->getId() == $product->parentId) {
foreach ($this->adapterFactory->getAttributeAdapter()->adapt($product) as $attribute) {
$item->addMergedAttribute($attribute);
}
}
else {
// Include $optionAttributes when export is not set to "Main/Parent product"
foreach ($product->configuratorGroupConfig as $attribute) {
if (!$attribute['expressionForListings']) {
$optionAttributes = $product->options->getElements();

$matchingOptionAttributes = array_filter(
$optionAttributes,
function ($optionAttribute) use ($attribute) {
return $attribute['id'] == $optionAttribute->groupId;
});

$originalAttributes = $this->adapterFactory->getAttributeAdapter()->adapt($product);

$matchingOriginalAttributes = array_filter(
$originalAttributes,
function ($originalAttribute) use ($matchingOptionAttributes) {
$optionAttributeNames = array_map(function ($optionAttribute) {
return $optionAttribute->name;
}, $matchingOptionAttributes);

return in_array($originalAttribute->getValues()[0], $optionAttributeNames);
});

foreach ($matchingOriginalAttributes as $originalAttribute) {
$item->addMergedAttribute($originalAttribute);
}
}
}
}

foreach ($this->adapterFactory->getShopwarePropertiesAdapter()->adapt($product) as $property) {
Expand Down
2 changes: 1 addition & 1 deletion tests/Export/Adapters/AttributeAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public function testEmptyCategoryNameShouldStillExportCategory(): void

$attributes = $this->attributeAdapter->adapt($productEntity);

$this->assertCount(7, $attributes);
$this->assertCount(5, $attributes);
$this->assertSame('cat_url', $attributes[0]->getKey());

$catUrls = $attributes[0]->getValues();
Expand Down
2 changes: 2 additions & 0 deletions tests/Export/Adapters/ExportItemAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public function testExceptionIsThrownForProductWithNoCategories(): void
'categories' => [],
]);

// Test.

$adapter = $this->getExportItemAdapter();
$adapter->adaptProduct(new XMLItem($id), $product);
}
Expand Down
39 changes: 39 additions & 0 deletions tests/Export/Adapters/OptionAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace FINDOLOGIC\Shopware6Common\Tests\Export\Adapters;

use FINDOLOGIC\Shopware6Common\Export\Adapters\OptionsAdapter;
use FINDOLOGIC\Shopware6Common\Export\Config\PluginConfig;
use FINDOLOGIC\Shopware6Common\Tests\Traits\AdapterHelper;
use FINDOLOGIC\Shopware6Common\Tests\Traits\ProductHelper;
use PHPUnit\Framework\TestCase;
use Vin\ShopwareSdk\Data\Uuid\Uuid;

class OptionAdapterTest extends TestCase
{
use ProductHelper;
use AdapterHelper;

public OptionsAdapter $optionsAdapter;
public PluginConfig $pluginConfig;
public function setUp(): void
{
$this->pluginConfig = $this->getPluginConfig();
$this->optionsAdapter = $this->getOptionsAdapter($this->pluginConfig);
}

public function testGetOptionAttributes(): void
{
$id = Uuid::randomHex();
$product = $this->createTestProduct([
'id' => $id,
]);
$attributes = $this->optionsAdapter->adapt($product);

$this->assertCount(2, $attributes);
$this->assertSame('red', $attributes[0]->getValues()[0]);
$this->assertSame('blue', $attributes[1]->getValues()[0]);
}
}
38 changes: 38 additions & 0 deletions tests/Export/Adapters/VariantConfigurationAdapterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace FINDOLOGIC\Shopware6Common\Tests\Export\Adapters;

use FINDOLOGIC\Shopware6Common\Export\Adapters\VariantConfigurationAdapter;
use FINDOLOGIC\Shopware6Common\Export\Config\PluginConfig;
use FINDOLOGIC\Shopware6Common\Tests\Traits\AdapterHelper;
use FINDOLOGIC\Shopware6Common\Tests\Traits\ProductHelper;
use PHPUnit\Framework\TestCase;
use Vin\ShopwareSdk\Data\Uuid\Uuid;

class VariantConfigurationAdapterTest extends TestCase
{
use ProductHelper;
use AdapterHelper;

public VariantConfigurationAdapter $variantConfigurationAdapter;
public PluginConfig $pluginConfig;
public function setUp(): void
{
$this->pluginConfig = $this->getPluginConfig();
$this->variantConfigurationAdapter = $this->getVariantConfigurationAdapter($this->pluginConfig);
}

public function testGetVariantAttributes(): void
{
$id = Uuid::randomHex();
$product = $this->createTestProduct([
'id' => $id,
]);
$attributes = $this->variantConfigurationAdapter->adapt($product);
$this->assertCount(2, $attributes);
$this->assertSame('red', $attributes[0]->getValues()[0]);
$this->assertSame('blue', $attributes[1]->getValues()[0]);
}
}
14 changes: 14 additions & 0 deletions tests/Traits/AdapterHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use FINDOLOGIC\Shopware6Common\Export\Adapters\ImagesAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\KeywordsAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\NameAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\OptionsAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\OrderNumberAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\OverriddenPriceAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\PriceAdapter;
Expand All @@ -23,6 +24,7 @@
use FINDOLOGIC\Shopware6Common\Export\Adapters\SummaryAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\UrlAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\GroupsAdapter;
use FINDOLOGIC\Shopware6Common\Export\Adapters\VariantConfigurationAdapter;
use FINDOLOGIC\Shopware6Common\Export\Config\PluginConfig;
use Monolog\Logger;
use Psr\EventDispatcher\EventDispatcherInterface;
Expand All @@ -47,6 +49,7 @@ public function getAdapterFactory(?PluginConfig $config = null): AdapterFactory
$this->getImagesAdapter(),
$this->getKeywordsAdapter(),
$this->getNameAdapter(),
$this->getOptionsAdapter($config),
$this->getOrderNumberAdapter(),
$this->getOverriddenPriceAdapter(),
$this->getPriceAdapter(),
Expand All @@ -55,6 +58,7 @@ public function getAdapterFactory(?PluginConfig $config = null): AdapterFactory
$this->getSummaryAdapter(),
$this->getShopwarePropertiesAdapter(),
$this->getUrlAdapter(),
$this->getVariantConfigurationAdapter($config),
);
}

Expand Down Expand Up @@ -118,6 +122,11 @@ public function getNameAdapter(): NameAdapter
return new NameAdapter();
}

public function getOptionsAdapter(?PluginConfig $config = null): OptionsAdapter
{
return new OptionsAdapter($config ?? $this->getPluginConfig());
}

public function getOrderNumberAdapter(): OrderNumberAdapter
{
return new OrderNumberAdapter();
Expand Down Expand Up @@ -180,6 +189,11 @@ public function getUrlAdapter(): UrlAdapter
return new UrlAdapter($this->getProductUrlService());
}

public function getVariantConfigurationAdapter(?PluginConfig $config = null): VariantConfigurationAdapter
{
return new VariantConfigurationAdapter($config ?? $this->getPluginConfig());
}

public function getGroupAdapter(?CustomerGroupCollection $customerGroupCollection = null): GroupsAdapter
{
return new GroupsAdapter($this->getExportContext($customerGroupCollection));
Expand Down
1 change: 1 addition & 0 deletions tests/Traits/ProductHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function createTestProduct(
'description' => 'FINDOLOGIC Description',
],
'streamIds' => [],
'variantListingConfig' => ['displayParent' => null],
]);

$productData = array_merge_recursive(
Expand Down
1 change: 1 addition & 0 deletions tests/Traits/ServicesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function getPluginConfig(?array $overrides = []): PluginConfig
return PluginConfig::createFromArray(array_merge([
'shopkey' => 'ABCDABCDABCDABCDABCDABCDABCDABCD',
'active' => true,
'mainVariant' => 'default',
], $overrides));
}

Expand Down