diff --git a/CHANGELOG.md b/CHANGELOG.md index 119a9c7..71a2feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,8 @@ ## Features * Add #PAC-354 new feature: - * Validation whether the product of the website is assigned to the current store view line - * `TechDivision\Import\Callbacks\StoreWebsiteValidatorCallback` + * extend the validation für catalog_product entity + * `"import.callback.store.in.website.validator"` # Version 25.3.2 diff --git a/etc/configuration/operations.json b/etc/configuration/operations.json index baa6f0d..540d8a4 100644 --- a/etc/configuration/operations.json +++ b/etc/configuration/operations.json @@ -416,7 +416,10 @@ "callbacks": [ { "sku": [ "import.callback.custom.regex.validator" ], - "store_view_code": [ "import.callback.store.view.code.validator" ], + "store_view_code": [ + "import.callback.store.view.code.validator", + "import.callback.store.in.website.validator" + ], "attribute_set_code": [ "import.callback.attribute.set.name.validator" ], "product_type": [ "import_product.callback.validator.product_type" ], "tax_class_id": [ "import_product.callback.validator.tax.class" ], diff --git a/src/Callbacks/StoreWebsiteValidatorCallback.php b/src/Callbacks/StoreWebsiteValidatorCallback.php deleted file mode 100644 index f8818ce..0000000 --- a/src/Callbacks/StoreWebsiteValidatorCallback.php +++ /dev/null @@ -1,142 +0,0 @@ - - * @copyright 2024 TechDivision GmbH - * @license https://opensource.org/licenses/MIT - * @link https://github.com/techdivision/import - * @link http://www.techdivision.com - */ - -namespace TechDivision\Import\Callbacks; - -use TechDivision\Import\Loaders\LoaderInterface; -use TechDivision\Import\Services\ImportProcessorInterface; -use TechDivision\Import\Utils\MemberNames; -use TechDivision\Import\Utils\RegistryKeys; - -/** - * storeview validator callback implementation. - * - * @author MET - * @copyright 2024 TechDivision GmbH - * @license https://opensource.org/licenses/MIT - * @link https://github.com/techdivision/import - * @link http://www.techdivision.com - */ -class StoreWebsiteValidatorCallback extends ArrayValidatorCallback -{ - /** - * The flag to query whether or not the value can be empty. - * - * @var boolean - */ - protected $nullable = false; - - /** - * The flag to query whether or not the value has to be validated on the main row only. - * - * @var boolean - */ - protected $mainRowOnly = false; - - /** - * The flag to query whether or not the value has to be ignored global strict mode configuration. - * - * @var boolean - */ - protected $ignoreStrictMode = false; - - /** - * The store websites. - * - * @var array - */ - protected $storeWebsites = array(); - - /** - * Initializes the callback with the loader instance. - * - * @param LoaderInterface $storeLoader The loader instance to load the validations with - * @param ImportProcessorInterface $importProcessor The import processor instance - * @param boolean $nullable The flag to decide whether or not the value can be empty - * @param boolean $mainRowOnly The flag to decide whether or not the value has to be validated on the main row only - * @param boolean $ignoreStrictMode The flag to query whether or not the value has to be ignored global strict mode configuration. - */ - public function __construct(LoaderInterface $storeLoader, ImportProcessorInterface $importProcessor, $nullable = false, $mainRowOnly = false, $ignoreStrictMode = true) - { - - // pass the loader to the parent instance - parent::__construct($storeLoader); - - // initialize the flags with the passed values - $this->nullable = $nullable; - $this->mainRowOnly = $mainRowOnly; - $this->ignoreStrictMode = $ignoreStrictMode; - - // initialize the array with the store websites - foreach ($importProcessor->getStoreWebsites() as $storeWebsite) { - $this->storeWebsites[$storeWebsite[MemberNames::CODE]] = $storeWebsite[MemberNames::WEBSITE_ID]; - } - } - - /** - * Will be invoked by a observer it has been registered for. - * - * @param string|null $attributeCode The code of the attribute that has to be validated - * @param string|null $attributeValue The attribute value to be validated - * - * @return mixed The modified value - */ - public function handle($attributeCode = null, $attributeValue = null) - { - // query whether or not the passed value IS empty and empty - // values are allowed - if ($this->isNullable($attributeValue)) { - return; - } - - // the validations for the attribute with the given code - $validations = $this->getValidations($attributeCode); - - $website = $this->load(); - $productWebsite = $this->getSubject()->getValue('product_websites'); - - if ($validations[$attributeValue][MemberNames::WEBSITE_ID] !== $website[$productWebsite]) { - $message = sprintf( - 'The store "%s" does not belong to the website "%s" . Please check your data.', - $attributeValue, - $productWebsite - ); - - $this->getSubject() - ->getSystemLogger() - ->warning($this->getSubject()->appendExceptionSuffix($message)); - $this->getSubject()->mergeStatus( - array( - RegistryKeys::NO_STRICT_VALIDATIONS => array( - basename($this->getSubject()->getFilename()) => array( - $this->getSubject()->getLineNumber() => array( - $attributeCode => $message - ) - ) - ) - ) - ); - } - } - - /** - * Loads and returns data. - * - * @return \ArrayAccess The array with the data - */ - public function load() - { - return $this->storeWebsites; - } -} diff --git a/symfony/Resources/config/services.xml b/symfony/Resources/config/services.xml index 1847ad8..a2c71df 100644 --- a/symfony/Resources/config/services.xml +++ b/symfony/Resources/config/services.xml @@ -459,8 +459,8 @@ @@ -472,7 +472,7 @@ - +