Product Attribute Bundle
If the Product-Attribute-Bundle is used, it is necessary to implement the associated export adapters.
ProductAttributeAdapter
src/Components/Export/Adapters/Product/ProductAttributeAdapter.php
The namespace and file path can be chosen arbitrarily. In this example, it is a recommendation.
<?php
namespace App\Components\Export\Adapters\Product;
use Twocream\ProductAttributeBundle\Components\Export\Service\ProductAttributeService;
use Twocream\ProductAttributeBundle\Components\Queue\Items\RecruitmentQueueItem;
use Twocream\ShopwareConnectorBundle\Service\AdapterConfigurationService;
use Twocream\ShopwareConnectorBundle\Service\ExportTargetService;
use Twocream\ShopwareConnectorBundle\Service\TranslationService;
use Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ArrayAdapterAbstract;
use Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ConditionManager;
class ProductAttributeAdapter extends ArrayAdapterAbstract
{
private ProductAttributeService $productAttributeService;
private ?RecruitmentQueueItem $attributeRecruitment;
public function __construct(
TranslationService $translationService,
ExportTargetService $exportTargetService,
AdapterConfigurationService $adapterConfigurationService,
ConditionManager $manager,
ProductAttributeService $productAttributeService,
?RecruitmentQueueItem $attributeRecruitment
) {
$this->attributeRecruitment = $attributeRecruitment;
$this->productAttributeService = $productAttributeService;
parent::__construct(
$translationService,
$exportTargetService,
$adapterConfigurationService,
$manager
);
}
public static function getPackageName(): string
{
return 'attributes';
}
public function getTargetClassName(): string
{
return 'ProductAttribute';
}
public static function getDeletedData($object): ?string
{
return json_encode(['uuid' => $object->getAttributeUuid()]);
}
public function convert(bool $exportDelta = true): array
{
if ($this->attributeRecruitment) {
$this->attributeRecruitment->execute(null, null, true);
}
return parent::convert($exportDelta);
}
protected function prepare($object): array
{
return $this->productAttributeService->prepareAttribute($object);
}
}
With this example, attribute recruitment is triggered before export. If this is not desired for individual reasons, the injection of the AttributeRecruitment
service in the constructor and the convert
method can be removed.
service.yaml
twocream.shopware_connector.adapter_product_attribute:
public: true
class: App\Components\Export\Adapters\Product\ProductAttributeAdapter
tags: [ 'twocream.shopware_connector.adapter' ]
ProductAttributeValueAdapter
src/Components/Export/Adapters/Product/ProductAttributeValueAdapter.php
<?php
namespace App\Components\Export\Adapters\Product;
use Twocream\ProductAttributeBundle\Components\Export\Service\ProductAttributeService;
use Twocream\ShopwareConnectorBundle\Service\AdapterConfigurationService;
use Twocream\ShopwareConnectorBundle\Service\ExportTargetService;
use Twocream\ShopwareConnectorBundle\Service\TranslationService;
use Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ArrayAdapterAbstract;
use Twocream\ShopwareConnectorBundle\Transformer\Adapter\ArrayAdapter\ConditionManager;
class ProductAttributeValueAdapter extends ArrayAdapterAbstract
{
private ProductAttributeService $productAttributeService;
public function __construct(
TranslationService $translationService,
ExportTargetService $exportTargetService,
AdapterConfigurationService $adapterConfigurationService,
ConditionManager $manager,
ProductAttributeService $productAttributeService
) {
$this->productAttributeService = $productAttributeService;
parent::__construct(
$translationService,
$exportTargetService,
$adapterConfigurationService,
$manager
);
}
public static function getPackageName(): string
{
return 'attribute-values';
}
public function getTargetClassName(): string
{
return 'ProductAttributeValue';
}
public static function getDeletedData($object): ?string
{
return json_encode(['uuid' => $object->getValueUuid()]);
}
protected function prepare($object): array
{
return $this->productAttributeService->prepareAttributeValue(
$object,
$this->assetHelper(),
exportArticleAssignment: false
);
}
}
service.yaml
twocream.shopware_connector.adapter_product_attribute_values:
public: true
class: App\Components\Export\Adapters\Product\ProductAttributeValueAdapter
tags: [ 'twocream.shopware_connector.adapter' ]
config/packages/shopware_connector.yaml
Both export adapters must now be added to config/packages/shopware_connector.yaml
.
twocream_shopware_connector:
adapters:
- key: 'attributes'
hide_export_mask: true
source_folder_ids:
- '123456'
- key: 'attribute-values'
hide_export_mask: true
source_folder_ids:
- '123456'
In this example, the two export adapters are hidden in the admin interface and defined as dependencies in the product export adapter.
Shopware Import
On the import side, nothing needs to be registered; the necessary import modules are already included in the JSON importer plugin.