Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
StoreViewService.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  protected $eavConfig;
22 
26  protected $connection;
27 
31  protected $metadataPool;
32 
37  public function __construct(
40  ) {
41  $this->eavConfig = $eavConfig;
42  $this->connection = $resource->getConnection();
43  }
44 
55  {
56  return $this->doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, 'url_key');
57  }
58 
69  {
70  return $this->doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, 'url_path');
71  }
72 
83  protected function doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, $attributeName)
84  {
85  $attribute = $this->eavConfig->getAttribute($entityType, $attributeName);
86  if (!$attribute) {
87  throw new \InvalidArgumentException(sprintf('Cannot retrieve attribute for entity type "%s"', $entityType));
88  }
89  $linkFieldName = $attribute->getEntity()->getLinkField();
90  if (!$linkFieldName) {
91  $linkFieldName = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
92  }
93  $select = $this->connection->select()
94  ->from(['e' => $attribute->getEntity()->getEntityTable()], [])
95  ->join(
96  ['e_attr' => $attribute->getBackendTable()],
97  "e.{$linkFieldName} = e_attr.{$linkFieldName}",
98  'store_id'
99  )->where('e_attr.attribute_id = ?', $attribute->getId())
100  ->where('e.entity_id = ?', $entityId);
101 
102  return in_array($storeId, $this->connection->fetchCol($select));
103  }
104 
110  private function getMetadataPool()
111  {
112  if (!$this->metadataPool) {
114  ->get(\Magento\Framework\EntityManager\MetadataPool::class);
115  }
116  return $this->metadataPool;
117  }
118 }
doesEntityHaveOverriddenUrlPathForStore($storeId, $entityId, $entityType)
doesEntityHaveOverriddenUrlAttributeForStore($storeId, $entityId, $entityType, $attributeName)
doesEntityHaveOverriddenUrlKeyForStore($storeId, $entityId, $entityType)
$resource
Definition: bulk.php:12
__construct(Config $eavConfig, ResourceConnection $resource)