diff --git a/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidator.php b/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidator.php
new file mode 100644
index 0000000000000..783602b09beef
--- /dev/null
+++ b/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidator.php
@@ -0,0 +1,43 @@
+unassignable)) {
+ $this->unassignable = $this->attributeConfig->getAttributeNames('unassignable');
+ }
+ if (in_array($attribute->getAttributeCode(), $this->unassignable)) {
+ throw new LocalizedException(
+ __("The system attribute can't be deleted.")
+ );
+ }
+ }
+}
diff --git a/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidatorInterface.php b/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidatorInterface.php
new file mode 100644
index 0000000000000..a50935f67f364
--- /dev/null
+++ b/vendor/magento/module-catalog/Model/Product/Attribute/AttributeSetUnassignValidatorInterface.php
@@ -0,0 +1,28 @@
+_attributeCollectionFactory = $attributeCollectionFactory;
+ $this->attributeSetUnassignValidator = $attributeSetUnassignValidator
+ ?: ObjectManager::getInstance()->get(AttributeSetUnassignValidatorInterface::class);
parent::__construct(
$context,
$registry,
@@ -72,4 +84,24 @@ public function hasSystemAttributes()
}
return $result;
}
+
+ /**
+ * @inheritdoc
+ */
+ public function beforeDelete()
+ {
+ $attributesCollection = $this->_attributeCollectionFactory->create();
+ $attributesCollection->setAttributeGroupFilter($this->getId());
+ foreach ($attributesCollection as $attribute) {
+ try {
+ $this->attributeSetUnassignValidator->validate($attribute, (int) $attribute->getAttributeSetId());
+ } catch (LocalizedException $e) {
+ throw new LocalizedException(
+ __("This group contains system attributes." .
+ " Please move system attributes to another group and try again.")
+ );
+ }
+ }
+ return parent::beforeDelete();
+ }
}
diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Eav/Attribute.php b/vendor/magento/module-catalog/Model/ResourceModel/Eav/Attribute.php
index 07ce84c7cd62e..403cfec206eb6 100644
--- a/vendor/magento/module-catalog/Model/ResourceModel/Eav/Attribute.php
+++ b/vendor/magento/module-catalog/Model/ResourceModel/Eav/Attribute.php
@@ -8,8 +8,10 @@
use Magento\Catalog\Model\Attribute\Backend\DefaultBackend;
use Magento\Catalog\Model\Attribute\LockValidatorInterface;
+use Magento\Catalog\Model\Product\Attribute\AttributeSetUnassignValidatorInterface;
use Magento\Eav\Model\Entity;
use Magento\Framework\Api\AttributeValueFactory;
+use Magento\Framework\App\ObjectManager;
use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
/**
@@ -98,6 +100,11 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
*/
private $eavAttributeFactory;
+ /**
+ * @var AttributeSetUnassignValidatorInterface
+ */
+ private $attributeSetUnassignValidator;
+
/**
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
@@ -123,6 +130,7 @@ class Attribute extends \Magento\Eav\Model\Entity\Attribute implements
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
* @param array $data
* @param \Magento\Eav\Api\Data\AttributeExtensionFactory|null $eavAttributeFactory
+ * @param AttributeSetUnassignValidatorInterface|null $attributeSetUnassignValidator
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
@@ -149,7 +157,8 @@ public function __construct(
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = [],
- \Magento\Eav\Api\Data\AttributeExtensionFactory $eavAttributeFactory = null
+ ?\Magento\Eav\Api\Data\AttributeExtensionFactory $eavAttributeFactory = null,
+ ?AttributeSetUnassignValidatorInterface $attributeSetUnassignValidator = null
) {
$this->_indexerEavProcessor = $indexerEavProcessor;
$this->_productFlatIndexerProcessor = $productFlatIndexerProcessor;
@@ -157,6 +166,8 @@ public function __construct(
$this->attrLockValidator = $lockValidator;
$this->eavAttributeFactory = $eavAttributeFactory ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Eav\Api\Data\AttributeExtensionFactory::class);
+ $this->attributeSetUnassignValidator = $attributeSetUnassignValidator
+ ?: ObjectManager::getInstance()->get(AttributeSetUnassignValidatorInterface::class);
parent::__construct(
$context,
$registry,
@@ -917,4 +928,16 @@ protected function _getDefaultBackendModel()
return $backend;
}
+
+ /**
+ * @inheritdoc
+ */
+ public function deleteEntity()
+ {
+ if ($this->getEntityAttributeId()) {
+ $result = $this->_getResource()->getEntityAttribute($this->getEntityAttributeId());
+ $result && $this->attributeSetUnassignValidator->validate($this, (int) $result['attribute_set_id']);
+ }
+ return parent::deleteEntity();
+ }
}
diff --git a/vendor/magento/module-catalog/etc/di.xml b/vendor/magento/module-catalog/etc/di.xml
index a13175fa78e90..df36733051c0d 100644
--- a/vendor/magento/module-catalog/etc/di.xml
+++ b/vendor/magento/module-catalog/etc/di.xml
@@ -78,6 +78,7 @@
= $block->escapeHtml(__('Double click on a group to rename it.')) ?>
+= $escaper->escapeHtml(__('Double click on a group to rename it.')) ?>
= $block->getSetsFilterHtml() ?> @@ -46,462 +47,109 @@ script;