public function generate(Variation $variation)
    {
        $unitIdentity = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getUnitIdentifier(),
            'objectType' => Unit::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        if (null === $unitIdentity) {
            throw new NotFoundException('Missing unit mapping - ' . $variation->getNumber());
        }

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

        if (null === $productIdentitiy) {
            throw new NotFoundException('Missing product for variation - ' . $variation->getProductIdentifier());
        }

        $shopwareVariation = [
            'articleId' => $productIdentitiy->getAdapterIdentifier(),
            'number' => $variation->getNumber(),
            'position' => $variation->getPosition(),
            'unitId' => $unitIdentity->getAdapterIdentifier(),
            'active' => $variation->getActive(),
            'kind' => $variation->isMain() ? 1 : 2,
            'isMain' => $variation->isMain(),
            'lastStock' => $variation->hasStockLimitation(),
            'standard' => $variation->isMain(),
            'shippingtime' => $variation->getShippingTime(),
            'prices' => $this->getPrices($variation),
            'supplierNumber' => $variation->getModel(),
            'purchasePrice' => $variation->getPurchasePrice(),
            'weight' => $variation->getWeight(),
            'len' => $variation->getLength(),
            'height' => $variation->getHeight(),
            'width' => $variation->getWidth(),
            'images' => $this->getImages($variation),
            'purchaseUnit' => $variation->getContent(),
            'referenceUnit' => $variation->getReferenceAmount(),
            'minPurchase' => $variation->getMinimumOrderQuantity(),
            'purchaseSteps' => $variation->getIntervalOrderQuantity(),
            'maxPurchase' => $variation->getMaximumOrderQuantity(),
            '__options_prices' => ['replace' => true],
            '__options_images' => ['replace' => true],
        ];

        $releaseData = $variation->getReleaseDate();
        if (null !== $releaseData) {
            $shopwareVariation['releaseDate'] = $releaseData->format(DATE_W3C);
        }

        $configuratorOptions = $this->getConfiguratorOptions($variation);
        if (!empty($configuratorOptions)) {
            $shopwareVariation['configuratorOptions'] = $configuratorOptions;
        }

        /**
         * @var Barcode[] $barcodes
         */
        $barcodes = array_filter($variation->getBarcodes(), function (Barcode $barcode) {
            return $barcode->getType() === Barcode::TYPE_GTIN13;
        });

        if (!empty($barcodes)) {
            $barcode = array_shift($barcodes);

            $shopwareVariation['ean'] = $barcode->getCode();
        }

        return $shopwareVariation;
    }
public function generate(Variation $variation)
    {
        $unitIdentity = $this->identityService->findOneBy([
            'objectIdentifier' => $variation->getUnitIdentifier(),
            'objectType' => Unit::TYPE,
            'adapterName' => ShopwareAdapter::NAME,
        ]);

        if (null === $unitIdentity) {
            throw new NotFoundException('Missing unit mapping - ' . $variation->getNumber());
        }

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

        if (null === $productIdentitiy) {
            throw new NotFoundException('Missing product for variation - ' . $variation->getProductIdentifier());
        }

        $shopwareVariation = [
            'articleId' => $productIdentitiy->getAdapterIdentifier(),
            'number' => $variation->getNumber(),
            'position' => $variation->getPosition(),
            'unitId' => $unitIdentity->getAdapterIdentifier(),
            'active' => $variation->getActive(),
            'kind' => $variation->isMain() ? 1 : 2,
            'isMain' => $variation->isMain(),
            'lastStock' => $variation->hasStockLimitation(),
            'standard' => $variation->isMain(),
            'shippingtime' => $variation->getShippingTime(),
            'prices' => $this->getPrices($variation),
            'supplierNumber' => $variation->getModel(),
            'purchasePrice' => $variation->getPurchasePrice(),
            'weight' => $variation->getWeight(),
            'len' => $variation->getLength(),
            'height' => $variation->getHeight(),
            'width' => $variation->getWidth(),
            'images' => $this->getImages($variation),
            'purchaseUnit' => $variation->getContent(),
            'referenceUnit' => $variation->getReferenceAmount(),
            'minPurchase' => $variation->getMinimumOrderQuantity(),
            'purchaseSteps' => $variation->getIntervalOrderQuantity(),
            'maxPurchase' => $variation->getMaximumOrderQuantity(),
            '__options_prices' => ['replace' => true],
            '__options_images' => ['replace' => true],
        ];

        $releaseData = $variation->getReleaseDate();
        if (null !== $releaseData) {
            $shopwareVariation['releaseDate'] = $releaseData->format(DATE_W3C);
        }

        $configuratorOptions = $this->getConfiguratorOptions($variation);
        if (!empty($configuratorOptions)) {
            $shopwareVariation['configuratorOptions'] = $configuratorOptions;
        }

        /**
         * @var Barcode[] $barcodes
         */
        $barcodes = array_filter($variation->getBarcodes(), function (Barcode $barcode) {
            return $barcode->getType() === Barcode::TYPE_GTIN13;
        });

        if (!empty($barcodes)) {
            $barcode = array_shift($barcodes);

            $shopwareVariation['ean'] = $barcode->getCode();
        }

        return $shopwareVariation;
    }
{@inheritdoc}