Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LockValidator.php
Go to the documentation of this file.
1 <?php
7 
13 
18 {
22  protected $resource;
23 
27  private $metadataPool;
28 
34  public function __construct(
36  ) {
37  $this->resource = $resource;
38  }
39 
48  public function validate(\Magento\Framework\Model\AbstractModel $object, $attributeSet = null)
49  {
50  $metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
51  $connection = $this->resource->getConnection();
52 
53  $bind = ['attribute_id' => $object->getAttributeId()];
54 
55  $select = clone $connection->select();
56  $select->reset()
57  ->from(
58  ['main_table' => $this->resource->getTableName('catalog_product_super_attribute')],
59  ['psa_count' => 'COUNT(product_super_attribute_id)']
60  )->join(
61  ['entity' => $this->resource->getTableName('catalog_product_entity')],
62  'main_table.product_id = entity.' . $metadata->getLinkField()
63  )->where('main_table.attribute_id = :attribute_id')
64  ->group('main_table.attribute_id')
65  ->limit(1);
66 
67  if ($attributeSet !== null) {
68  $bind['attribute_set_id'] = $attributeSet;
69  $select->where('entity.attribute_set_id = :attribute_set_id');
70  }
71 
72  if ($connection->fetchOne($select, $bind)) {
73  throw new \Magento\Framework\Exception\LocalizedException(
74  __('This attribute is used in configurable products.')
75  );
76  }
77  }
78 
83  private function getMetadataPool()
84  {
85  if (!$this->metadataPool) {
86  $this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
87  }
88  return $this->metadataPool;
89  }
90 }
__()
Definition: __.php:13
validate(\Magento\Framework\Model\AbstractModel $object, $attributeSet=null)
$connection
Definition: bulk.php:13