diff --git a/vendor/magento/module-catalog-staging/Model/IsProductInActiveUpdate.php b/vendor/magento/module-catalog-staging/Model/IsProductInActiveUpdate.php new file mode 100644 index 000000000000..de1132723611 --- /dev/null +++ b/vendor/magento/module-catalog-staging/Model/IsProductInActiveUpdate.php @@ -0,0 +1,80 @@ +versionManager->getCurrentVersion(); + + if (!$product->getId() || !$currentVersion->getRollbackId()) {//if no rollback id, then it is not temporary + return false; + } + + $metadata = $this->metadataPool->getMetadata(ProductInterface::class); + $connection = $this->resourceConnection->getConnection(); + $linkField = $metadata->getLinkField(); + $linkFieldValue = $product->getData($linkField); + + if (!$linkFieldValue) { + $linkFieldValue = $connection->fetchOne( + $connection->select() + ->from($metadata->getEntityTable(), $linkField) + ->where($metadata->getIdentifierField() . ' = ?', $product->getId()) + ); + } + + if (!$linkFieldValue) { + return false; + } + + $select = $connection->select() + ->from($metadata->getEntityTable(), [$linkField]) + ->where($linkField . ' = ?', $linkFieldValue) + ->where('created_in = ?', (int)$currentVersion->getId()) + ->where('updated_in = ?', (int)$currentVersion->getRollbackId()) + ->limit(1); + + return (bool)$connection->fetchOne($select); + } +} diff --git a/vendor/magento/module-catalog-staging/Observer/ProhibitSkuChangeIfStagedObserver.php b/vendor/magento/module-catalog-staging/Observer/ProhibitSkuChangeIfStagedObserver.php new file mode 100644 index 000000000000..8505aba8e1e6 --- /dev/null +++ b/vendor/magento/module-catalog-staging/Observer/ProhibitSkuChangeIfStagedObserver.php @@ -0,0 +1,67 @@ +getEvent()->getProduct(); + if (!$product instanceof ProductInterface) { + return; + } + + $originalSku = (string)$product->getOrigData('sku'); + $currentSku = (string)$product->getSku(); + + if ($originalSku === '' || $originalSku === $currentSku) { + return; + } + + if ($this->isProductInActiveUpdate->execute($product)) { + throw new LocalizedException( + __( + 'You cannot change the SKU because this product has an active update. ' + . 'End the update, then change the SKU.' + ) + ); + } + } +} diff --git a/vendor/magento/module-catalog-staging/Ui/DataProvider/Product/Form/Modifier/DisableSkuWhenStaged.php b/vendor/magento/module-catalog-staging/Ui/DataProvider/Product/Form/Modifier/DisableSkuWhenStaged.php new file mode 100644 index 000000000000..7ff56fec4771 --- /dev/null +++ b/vendor/magento/module-catalog-staging/Ui/DataProvider/Product/Form/Modifier/DisableSkuWhenStaged.php @@ -0,0 +1,83 @@ +locator->getProduct(); + if (!$product || !$product->getId()) { + return $meta; + } + + if (!$this->isProductInActiveUpdate->execute($product)) { + return $meta; + } + + $skuPath = $this->arrayManager->findPath(ProductAttributeInterface::CODE_SKU, $meta, null, 'children'); + if ($skuPath === null) { + return $meta; + } + + $configPath = $skuPath . '/arguments/data/config'; + $meta = $this->arrayManager->merge( + $configPath, + $meta, + [ + 'disabled' => true, + 'notice' => __('SKU cannot be changed while this product has an active update.') + ] + ); + + return $meta; + } + + /** + * @inheritdoc + */ + public function modifyData(array $data): array + { + return $data; + } +} diff --git a/vendor/magento/module-catalog-staging/etc/adminhtml/di.xml b/vendor/magento/module-catalog-staging/etc/adminhtml/di.xml index 68e7e3159516..132df322dd4b 100644 --- a/vendor/magento/module-catalog-staging/etc/adminhtml/di.xml +++ b/vendor/magento/module-catalog-staging/etc/adminhtml/di.xml @@ -252,6 +252,10 @@ Magento\CatalogStaging\Ui\DataProvider\Product\Form\Modifier\ScheduleDesignUpdate 80 + + Magento\CatalogStaging\Ui\DataProvider\Product\Form\Modifier\DisableSkuWhenStaged + 55 + diff --git a/vendor/magento/module-catalog-staging/etc/events.xml b/vendor/magento/module-catalog-staging/etc/events.xml index 90b80b1678dc..e8e21c3082a1 100644 --- a/vendor/magento/module-catalog-staging/etc/events.xml +++ b/vendor/magento/module-catalog-staging/etc/events.xml @@ -9,5 +9,6 @@ +