Product-Attribute-Bundle
Sofern das Product-Attribute-Bundle eingesetzt wird, ist es notwendig, die angehörigen Export-Adapter zu implementieren.
ProductAttributeAdapter
src/Components/Export/Adapters/Product/ProductAttributeAdapter.php
Der Namespace und Dateipfad kann beliebig gewählt werden. In dem Beispiel handelt es sich um eine Empfehlung.
<?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);
}
}
Mit diesem Beispiel wird vor dem Export die Attribut-Rekrutierung angestoßen. Ist dies aus individuellen Gründen nicht erwünscht, kann im Konstruktor die Injection des Service AttributeRecruitment
und die Methode convert
entfernt werden.
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
Beide Export-Adapter müssen nun in der config/packages/shopware_connector.yaml
aufgenommen werden.
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 diesem Anwendungsbeispiel werden die beiden Export-Adapter in der Admin-Oberfläche versteckt und im Produkt-Export-Adapter als Abhängigkeit definiert.
Shopware-Import
Auf Import-Seite muss nichts registriert werden, die notwendigen Import-Module sind bereits im JSON-Importer-Plugin enthalten.