Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProductEntityAttributesForAst.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
14 
19 {
23  private $config;
24 
28  private $additionalAttributes = ['min_price', 'max_price', 'category_id'];
29 
34  public function __construct(
35  ConfigInterface $config,
36  array $additionalAttributes = []
37  ) {
38  $this->config = $config;
39  $this->additionalAttributes = array_merge($this->additionalAttributes, $additionalAttributes);
40  }
41 
45  public function getEntityAttributes() : array
46  {
47  $productTypeSchema = $this->config->getConfigElement('SimpleProduct');
48  if (!$productTypeSchema instanceof Type) {
49  throw new \LogicException(__("SimpleProduct type not defined in schema."));
50  }
51 
52  $fields = [];
53  foreach ($productTypeSchema->getInterfaces() as $interface) {
55  $configElement = $this->config->getConfigElement($interface['interface']);
56 
57  foreach ($configElement->getFields() as $field) {
58  $fields[$field->getName()] = 'String';
59  }
60  }
61 
62  foreach ($this->additionalAttributes as $attribute) {
63  $fields[$attribute] = 'String';
64  }
65 
66  return array_keys($fields);
67  }
68 }
$config
Definition: fraud_order.php:17
$fields
Definition: details.phtml:14
__()
Definition: __.php:13