@param \Spryker\Zed\DataImport\Business\Model\DataSet\DataSetInterface $dataSet
@param \Orm\Zed\ProductAlternative\Persistence\SpyProductAlternativeQuery $productAlternativeQuery

@return void
337783
protected function saveConcreteAlternative(DataSetInterface $dataSet, SpyProductAlternativeQuery $productAlternativeQuery): void
    {
        $productAlternativeEntity = $productAlternativeQuery->filterByFkProductConcreteAlternative(
            $dataSet[ProductAlternativeDataSetInterface::FK_PRODUCT_CONCRETE_ALTERNATIVE]
        )
            ->findOneOrCreate()
            ->setFkProductConcreteAlternative(
                $dataSet[ProductAlternativeDataSetInterface::FK_PRODUCT_CONCRETE_ALTERNATIVE]
            );
        $productAlternativeEntity->save();

        $fkProductConcreteAlternative = $productAlternativeEntity->getFkProductConcreteAlternative();

        if (!$fkProductConcreteAlternative) {
            return;
        }

        $this->addPublishEvents(
            ProductAlternativeEvents::PRODUCT_REPLACEMENT_CONCRETE_PUBLISH,
            $fkProductConcreteAlternative
        );
        $this->addPublishEvents(
            ProductAlternativeEvents::PRODUCT_ALTERNATIVE_PUBLISH,
            $productAlternativeEntity->getFkProduct()
        );
    }
394850
public function execute(DataSetInterface $dataSet): void
    {
        $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT_STORE] = $this->getIdPriceProductStoreEntity($dataSet);
    }
897113
public function execute(DataSetInterface $dataSet)
    {
        $companyUnitAddressLabelToCompanyUnitAddressEntity = SpyCompanyUnitAddressLabelToCompanyUnitAddressQuery::create()
            ->filterByFkCompanyUnitAddress($dataSet[CompanyUnitAddressLabelRelationDataSet::ID_COMPANY_UNIT_ADDRESS])
            ->filterByFkCompanyUnitAddressLabel($dataSet[CompanyUnitAddressLabelRelationDataSet::ID_COMPANY_UNIT_ADDRESS_LABEL])
            ->findOneOrCreate();

        $companyUnitAddressLabelToCompanyUnitAddressEntity->save();
    }
1262051
public function execute(DataSetInterface $dataSet): void
    {
        $categoryKey = $dataSet[ProductListDataSetInterface::CATEGORY_KEY];
        if (!$categoryKey) {
            throw new InvalidDataException(sprintf('"%s" is required.', ProductListDataSetInterface::CATEGORY_KEY));
        }

        $dataSet[ProductListDataSetInterface::ID_CATEGORY] = $this->getIdCategoryByKey($categoryKey);
    }
1311559
public function execute(DataSetInterface $dataSet): void
    {
        $productSku = $dataSet[ProductAlternativeDataSetInterface::KEY_COLUMN_CONCRETE_SKU];

        if (!isset($this->idProductCache[$productSku])) {
            $productEntity = SpyProductQuery::create()->findOneBySku($productSku);
            if (!$productEntity) {
                throw new EntityNotFoundException(sprintf('Could not find product by sku "%s"', $productSku));
            }

            $this->idProductCache[$productSku] = $productEntity->getIdProduct();
        }

        $dataSet[ProductAlternativeDataSetInterface::FK_PRODUCT] = $this->idProductCache[$productSku];
    }
65839
public function execute(DataSetInterface $dataSet): void
    {
        $productListKey = $dataSet[ProductListDataSetInterface::PRODUCT_LIST_KEY];
        if (!$productListKey) {
            throw new InvalidDataException(sprintf('"%s" is required.', ProductListDataSetInterface::PRODUCT_LIST_KEY));
        }

        $dataSet[ProductListDataSetInterface::ID_PRODUCT_LIST] = $this->getIdProductListByKey($productListKey);
    }
74891
protected function saveProductMeasurementUnit(DataSetInterface $dataSet): SpyProductMeasurementUnit
    {
        $productMeasurementUnitEntity = SpyProductMeasurementUnitQuery::create()
            ->filterByCode($dataSet[ProductMeasurementUnitDataSet::COLUMN_CODE])
            ->findOneOrCreate();

        $productMeasurementUnitEntity
            ->setName($dataSet[ProductMeasurementUnitDataSet::COLUMN_NAME])
            ->setDefaultPrecision($this->filterDefaultPrecision($dataSet[ProductMeasurementUnitDataSet::COLUMN_DEFAULT_PRECISION]))
            ->save();
        return $productMeasurementUnitEntity;
    }
1222559
public function execute(DataSetInterface $dataSet): void
    {
        $productMeasurementUnitEntity = $this->saveProductMeasurementUnit($dataSet);

        $this->addPublishEvents(
            static::PRODUCT_MEASUREMENT_UNIT_PUBLISH,
            $productMeasurementUnitEntity->getIdProductMeasurementUnit()
        );
    }
264755
protected function saveProductListCategory(DataSetInterface $dataSet): void
    {
        $productListCategoryEntity = SpyProductListCategoryQuery::create()
            ->filterByFkProductList($dataSet[ProductListDataSetInterface::ID_PRODUCT_LIST])
            ->filterByFkCategory($dataSet[ProductListDataSetInterface::ID_CATEGORY])
            ->findOneOrCreate();

        $productListCategoryEntity->setFkProductList($dataSet[ProductListDataSetInterface::ID_PRODUCT_LIST])
            ->setFkCategory($dataSet[ProductListDataSetInterface::ID_CATEGORY])
            ->save();

        $this->addPublishEvents(
            ProductListEvents::PRODUCT_LIST_CATEGORY_PUBLISH,
            $productListCategoryEntity->getFkCategory()
        );
    }
1258945
protected function findOrCreateNode(SpyCategory $categoryEntity, DataSetInterface $dataSet)
    {
        $categoryNodeEntity = SpyCategoryNodeQuery::create()
            ->filterByCategory($categoryEntity)
            ->findOneOrCreate();

        if (!empty($dataSet[static::KEY_PARENT_CATEGORY_KEY])) {
            $idParentCategoryNode = $this->categoryReader->getIdCategoryNodeByCategoryKey($dataSet[static::KEY_PARENT_CATEGORY_KEY]);
            $categoryNodeEntity->setFkParentCategoryNode($idParentCategoryNode);
        }

        $categoryNodeEntity->fromArray($dataSet->getArrayCopy());

        if ($categoryNodeEntity->isNew() || $categoryNodeEntity->isModified()) {
            $categoryNodeEntity->save();
        }

        $this->addToClosureTable($categoryNodeEntity);
        $this->addPublishEvents(CategoryEvents::CATEGORY_NODE_PUBLISH, $categoryNodeEntity->getIdCategoryNode());

        foreach ($categoryEntity->getAttributes() as $categoryAttributesEntity) {
            $idLocale = $categoryAttributesEntity->getFkLocale();
            $languageIdentifier = $this->getLanguageIdentifier($idLocale, $dataSet);
            $urlPathParts = [$languageIdentifier];
            if (!$categoryNodeEntity->getIsRoot()) {
                $parentUrl = $this->categoryReader->getParentUrl(
                    $dataSet[static::KEY_PARENT_CATEGORY_KEY],
                    $idLocale
                );

                $urlPathParts = explode('/', ltrim($parentUrl, '/'));
                $urlPathParts[] = $categoryAttributesEntity->getName();
            }

            if ($categoryNodeEntity->getIsRoot()) {
                $this->addPublishEvents(CategoryEvents::CATEGORY_TREE_PUBLISH, $categoryNodeEntity->getIdCategoryNode());
            }

            $convertCallback = function ($value) {
                return mb_strtolower(str_replace(' ', '-', $value));
            };
            $urlPathParts = array_map($convertCallback, $urlPathParts);
            $url = '/' . implode('/', $urlPathParts);

            $urlEntity = SpyUrlQuery::create()
                ->filterByFkLocale($idLocale)
                ->filterByFkResourceCategorynode($categoryNodeEntity->getIdCategoryNode())
                ->findOneOrCreate();

            $urlEntity
                ->setUrl($url);

            if ($urlEntity->isNew() || $urlEntity->isModified()) {
                $urlEntity->save();
                $this->addPublishEvents(UrlEvents::URL_PUBLISH, $urlEntity->getIdUrl());
            }
        }

        return $categoryNodeEntity;
    }
889998
public function execute(DataSetInterface $dataSet): void
    {
        $priceTypeEntity = SpyPriceTypeQuery::create()
            ->filterByName($dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_TYPE])
            ->findOneOrCreate();

        if ($priceTypeEntity->isNew() || $priceTypeEntity->isModified()) {
            $priceTypeEntity->setPriceModeConfiguration(SpyPriceTypeTableMap::COL_PRICE_MODE_CONFIGURATION_BOTH);
            $priceTypeEntity->save();
        }

        $priceProductQuery = SpyPriceProductQuery::create();
        $priceProductQuery->filterByFkPriceType($priceTypeEntity->getIdPriceType());

        if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE])) {
            $priceProductQuery->filterByFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]);
        } else {
            $priceProductQuery->filterByFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]);
        }
        $productPriceEntity = $priceProductQuery->findOneOrCreate();
        $productPriceEntity->save();

        $dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT] = $productPriceEntity->getIdPriceProduct();
    }
173074
protected function getIdPriceProductStoreEntity(DataSetInterface $dataSet): string
    {
        $cacheIndex = $this->buildCacheIndex($dataSet);
        if (isset($this->idPriceProductStoreCache[$cacheIndex])) {
            return $this->idPriceProductStoreCache[$cacheIndex];
        }

        $priceProductStoreEntity = SpyPriceProductStoreQuery::create()
            ->filterByFkStore($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_STORE])
            ->filterByFkCurrency($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_CURRENCY])
            ->filterByFkPriceProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT])
            ->filterByNetPrice((int)$dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_NET])
            ->filterByGrossPrice((int)$dataSet[PriceProductMerchantRelationshipDataSetInterface::PRICE_GROSS])
            ->findOneOrCreate();

        $priceProductStoreEntity->save();

        $this->idPriceProductStoreCache[$cacheIndex] = $priceProductStoreEntity->getIdPriceProductStore();

        return $this->idPriceProductStoreCache[$cacheIndex];
    }
1209844
public function execute(DataSetInterface $dataSet): void
    {
        $priceTypeEntity = SpyPriceTypeQuery::create()
            ->filterByName($dataSet[PriceProductDataSet::KEY_PRICE_TYPE])
            ->findOneOrCreate();

        if ($priceTypeEntity->isNew() || $priceTypeEntity->isModified()) {
            $priceTypeEntity->setPriceModeConfiguration(SpyPriceTypeTableMap::COL_PRICE_MODE_CONFIGURATION_BOTH);
            $priceTypeEntity->save();
        }

        $priceProductQuery = SpyPriceProductQuery::create();
        $priceProductQuery->filterByFkPriceType($priceTypeEntity->getIdPriceType());

        if (empty($dataSet[PriceProductDataSet::KEY_ABSTRACT_SKU]) && empty($dataSet[PriceProductDataSet::KEY_CONCRETE_SKU])) {
            throw new DataKeyNotFoundInDataSetException(sprintf(
                'One of "%s" or "%s" must be in the data set. Given: "%s"',
                PriceProductDataSet::KEY_ABSTRACT_SKU,
                PriceProductDataSet::KEY_CONCRETE_SKU,
                implode(', ', array_keys($dataSet->getArrayCopy()))
            ));
        }

        if (!empty($dataSet[PriceProductDataSet::KEY_ABSTRACT_SKU])) {
            $priceProductQuery->filterByFkProductAbstract($dataSet[PriceProductDataSet::ID_PRODUCT_ABSTRACT]);
            $this->addPublishEvents(PriceProductEvents::PRICE_ABSTRACT_PUBLISH, $dataSet[PriceProductDataSet::ID_PRODUCT_ABSTRACT]);
            $this->addPublishEvents(ProductEvents::PRODUCT_ABSTRACT_PUBLISH, $dataSet[PriceProductDataSet::ID_PRODUCT_ABSTRACT]);
        } else {
            $this->addPublishEvents(PriceProductEvents::PRICE_CONCRETE_PUBLISH, $dataSet[PriceProductDataSet::ID_PRODUCT_CONCRETE]);
            $priceProductQuery->filterByFkProduct($dataSet[PriceProductDataSet::ID_PRODUCT_CONCRETE]);
        }

        $productPriceEntity = $priceProductQuery->findOneOrCreate();
        $productPriceEntity->save();

        $priceProductStoreEntity = SpyPriceProductStoreQuery::create()
            ->filterByFkStore($dataSet[PriceProductDataSet::ID_STORE])
            ->filterByFkCurrency($dataSet[PriceProductDataSet::ID_CURRENCY])
            ->filterByFkPriceProduct($productPriceEntity->getPrimaryKey())
            ->findOneOrCreate();

        $priceProductStoreEntity->setGrossPrice($dataSet[PriceProductDataSet::KEY_PRICE_GROSS]);
        $priceProductStoreEntity->setNetPrice($dataSet[PriceProductDataSet::KEY_PRICE_NET]);
        $priceProductStoreEntity->setPriceData($dataSet[PriceProductDataSet::KEY_PRICE_DATA]);
        $priceProductStoreEntity->setPriceDataChecksum($dataSet[PriceProductDataSet::KEY_PRICE_DATA_CHECKSUM]);

        $priceProductStoreEntity->save();

        $this->savePriceProductDefault($priceProductStoreEntity->getPrimaryKey());
    }
908813
protected function findExistingPriceProductStoreEntity(DataSetInterface $dataSet): ?SpyPriceProductMerchantRelationship
    {
        $query = SpyPriceProductMerchantRelationshipQuery::create()
            ->usePriceProductStoreQuery()
                ->filterByFkStore($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_STORE])
                ->filterByFkCurrency($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_CURRENCY])
                ->filterByFkPriceProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRICE_PRODUCT])
            ->endUse()
            ->filterByFkMerchantRelationship($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_MERCHANT_RELATIONSHIP]);

        if (!empty($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT])) {
            $query->filterByFkProductAbstract($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_ABSTRACT]);
        } else {
            $query->filterByFkProduct($dataSet[PriceProductMerchantRelationshipDataSetInterface::ID_PRODUCT_CONCRETE]);
        }

        return $query->findOne();
    }
1049138
public function execute(DataSetInterface $dataSet): void
    {
        $productAbstractSku = $dataSet[PriceProductDataSet::KEY_ABSTRACT_SKU];
        if (empty($productAbstractSku)) {
            return;
        }

        if (!isset($this->idProductAbstractCache[$productAbstractSku])) {
            $productQuery = new SpyProductAbstractQuery();
            $idProduct = $productQuery
                ->select(SpyProductAbstractTableMap::COL_ID_PRODUCT_ABSTRACT)
                ->findOneBySku($productAbstractSku);

            if (!$idProduct) {
                throw new EntityNotFoundException(sprintf('Could not find abstract product by sku "%s"', $productAbstractSku));
            }

            $this->idProductAbstractCache[$productAbstractSku] = $idProduct;
        }

        $dataSet[PriceProductDataSet::ID_PRODUCT_ABSTRACT] = $this->idProductAbstractCache[$productAbstractSku];
    }
964517
protected function getIso2Code(DataSetInterface $dataSet)
    {
        if (isset($dataSet[CompanyUnitAddressDataSet::COUNTRY_ISO_2_CODE]) && !empty($dataSet[CompanyUnitAddressDataSet::COUNTRY_ISO_2_CODE])) {
            return $dataSet[CompanyUnitAddressDataSet::COUNTRY_ISO_2_CODE];
        }

        return null;
    }
569637
public function execute(DataSetInterface $dataSet): void
    {
        $companyBusinessUnitKey = $dataSet[ShoppingListCompanyBusinessUnitDataSetInterface::COLUMN_COMPANY_BUSINESS_UNIT_KEY];
        if (!isset($this->idCompanyBusinessUnitCache[$companyBusinessUnitKey])) {
            $companyBusinessUnitQuery = new SpyCompanyBusinessUnitQuery();
            $idCompanyUser = $companyBusinessUnitQuery
                ->select([SpyCompanyBusinessUnitTableMap::COL_ID_COMPANY_BUSINESS_UNIT])
                ->findOneByKey($companyBusinessUnitKey);

            if (!$idCompanyUser) {
                throw new EntityNotFoundException(sprintf('Could not find company business unit by key "%s"', $companyBusinessUnitKey));
            }

            $this->idCompanyBusinessUnitCache[$companyBusinessUnitKey] = $idCompanyUser;
        }

        $dataSet[ShoppingListCompanyBusinessUnitDataSetInterface::ID_COMPANY_BUSINESS_UNIT] = $this->idCompanyBusinessUnitCache[$companyBusinessUnitKey];
    }