Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Document.php
Go to the documentation of this file.
1 <?php
7 
12 
17 {
21  private static $stateAttributeCode = 'state';
22 
26  private static $customerGroupAttributeCode = 'customer_group_id';
27 
31  private $groupRepository;
32 
38  public function __construct(
40  GroupRepositoryInterface $groupRepository
41  ) {
42  parent::__construct($attributeValueFactory);
43  $this->groupRepository = $groupRepository;
44  }
45 
50  {
51  switch ($attributeCode) {
52  case self::$stateAttributeCode:
53  $this->setStateValue();
54  break;
55  case self::$customerGroupAttributeCode:
56  $this->setCustomerGroupValue();
57  break;
58  }
59  return parent::getCustomAttribute($attributeCode);
60  }
61 
67  private function setStateValue()
68  {
69  $value = $this->getData(self::$stateAttributeCode);
71  $state = Invoice::getStates()[$value];
72 
73  $this->setCustomAttribute(self::$stateAttributeCode, $state->getText());
74  }
75 
81  private function setCustomerGroupValue()
82  {
83  $value = $this->getData(self::$customerGroupAttributeCode);
84  try {
85  $group = $this->groupRepository->getById($value);
86  $this->setCustomAttribute(self::$customerGroupAttributeCode, $group->getCode());
87  } catch (NoSuchEntityException $e) {
88  $this->setCustomAttribute(self::$customerGroupAttributeCode, 'N/A');
89  }
90  }
91 }
$groupRepository
getData($key='', $index=null)
Definition: DataObject.php:119
$group
Definition: sections.phtml:16
$value
Definition: gender.phtml:16
__construct(AttributeValueFactory $attributeValueFactory, GroupRepositoryInterface $groupRepository)
Definition: Document.php:38
$attributeCode
Definition: extend.phtml:12