|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © 2013-2017 Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | +namespace Magento\ConfigurableProduct\Plugin\Model\Attribute\Backend; |
| 7 | + |
| 8 | +use Magento\Catalog\Api\Data\ProductInterface; |
| 9 | +use Magento\ConfigurableProduct\Model\Product\Type\Configurable; |
| 10 | + |
| 11 | +/** |
| 12 | + * Skip validate attributes used for create configurable product |
| 13 | + */ |
| 14 | +class AttributeValidation |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var Configurable |
| 18 | + */ |
| 19 | + private $configurableProductType; |
| 20 | + |
| 21 | + /** |
| 22 | + * AttributeValidation constructor. |
| 23 | + * @param Configurable $configurableProductType |
| 24 | + */ |
| 25 | + public function __construct( |
| 26 | + Configurable $configurableProductType |
| 27 | + ) { |
| 28 | + $this->configurableProductType = $configurableProductType; |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @param \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject |
| 33 | + * @param \Closure $proceed |
| 34 | + * @param \Magento\Framework\DataObject $entity |
| 35 | + * @return bool |
| 36 | + */ |
| 37 | + public function aroundValidate( |
| 38 | + \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBackend $subject, |
| 39 | + \Closure $proceed, |
| 40 | + \Magento\Framework\DataObject $entity |
| 41 | + ) { |
| 42 | + $attribute = $subject->getAttribute(); |
| 43 | + if ($entity instanceof ProductInterface |
| 44 | + && $entity->getTypeId() == Configurable::TYPE_CODE |
| 45 | + && in_array( |
| 46 | + $attribute->getAttributeId(), |
| 47 | + $this->configurableProductType->getUsedProductAttributeIds($entity), |
| 48 | + true |
| 49 | + ) |
| 50 | + ) { |
| 51 | + return true; |
| 52 | + } |
| 53 | + return $proceed($entity); |
| 54 | + } |
| 55 | +} |
0 commit comments