Adapter/ShopwareAdapter/ServiceBus/CommandHandler/Variation/HandleVariationCommandHandler.php
public function handle(CommandInterface $command)
    {
        /**
         * @var Variation $variation
         */
        $variation = $command->getPayload();

        $productIdentitiy = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getProductIdentifier(),
            'objectType' => Product::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        if (null === $productIdentitiy) {
            return false;
        }

        $variationIdentity = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getIdentifier(),
            'objectType' => Variation::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        $variationResource = $this->getVariationResource();
        $variationParams = $this->variationRequestGenerator->generate($variation);
        $variationRepository = $this->entityManager->getRepository(Detail::class);

        if (null === $variationIdentity) {
            /**
             * @var null|Detail $variationModel
             */
            $variationModel = $variationRepository->findOneBy(['number' => $variation->getNumber()]);

            if (null === $variationModel) {
                $variationModel = $variationResource->create($variationParams);
            } else {
                $variationModel = $variationResource->update(
                    $variationModel->getId(),
                    $variationParams
                );
            }

            $this->identityService->insert(
                $variation->getIdentifier(),
                Variation::TYPE,
                (string) $variationModel->getId(),
                ShopwareAdapter::NAME
            );
        } else {
            /**
             * @var null|Detail $variationModel
             */
            $variationModel = $variationRepository->find($variationIdentity->getAdapterIdentifier());

            if (null === $variationModel) {
                $variationModel = $variationRepository->findOneBy(['number' => $variation->getNumber()]);
            }

            if (null === $variationModel) {
                $variationModel = $variationResource->create($variationParams);
            } else {
                $variationModel = $variationResource->update(
                    $variationModel->getId(),
                    $variationParams
                );
            }

            $this->identityService->update(
                $variationIdentity,
                [
                    'adapterIdentifier' => (string) $variationModel->getId(),
                ]
            );
        }

        $this->correctProductAssignment($variationModel, $productIdentitiy);
        $this->correctMainDetailAssignment($variationModel, $variation);

        $this->attributeDataPersister->saveProductDetailAttributes(
            $variationModel,
            $variation->getAttributes()
        );

        return true;
    }
public function handle(CommandInterface $command)
    {
        /**
         * @var Variation $variation
         */
        $variation = $command->getPayload();

        $productIdentitiy = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getProductIdentifier(),
            'objectType' => Product::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        if (null === $productIdentitiy) {
            return false;
        }

        $variationIdentity = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getIdentifier(),
            'objectType' => Variation::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        $variationResource = $this->getVariationResource();
        $variationParams = $this->variationRequestGenerator->generate($variation);
        $variationRepository = $this->entityManager->getRepository(Detail::class);

        if (null === $variationIdentity) {
            /**
             * @var null|Detail $variationModel
             */
            $variationModel = $variationRepository->findOneBy(['number' => $variation->getNumber()]);

            if (null === $variationModel) {
                $variationModel = $variationResource->create($variationParams);
            } else {
                $variationModel = $variationResource->update(
                    $variationModel->getId(),
                    $variationParams
                );
            }

            $this->identityService->insert(
                $variation->getIdentifier(),
                Variation::TYPE,
                (string) $variationModel->getId(),
                ShopwareAdapter::NAME
            );
        } else {
            /**
             * @var null|Detail $variationModel
             */
            $variationModel = $variationRepository->find($variationIdentity->getAdapterIdentifier());

            if (null === $variationModel) {
                $variationModel = $variationRepository->findOneBy(['number' => $variation->getNumber()]);
            }

            if (null === $variationModel) {
                $variationModel = $variationResource->create($variationParams);
            } else {
                $variationModel = $variationResource->update(
                    $variationModel->getId(),
                    $variationParams
                );
            }

            $this->identityService->update(
                $variationIdentity,
                [
                    'adapterIdentifier' => (string) $variationModel->getId(),
                ]
            );
        }

        $this->correctProductAssignment($variationModel, $productIdentitiy);
        $this->correctMainDetailAssignment($variationModel, $variation);

        $this->attributeDataPersister->saveProductDetailAttributes(
            $variationModel,
            $variation->getAttributes()
        );

        return true;
    }
{@inheritdoc}

@param TransferObjectCommand $command