Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Street.php
Go to the documentation of this file.
1 <?php
7 
9 
15 class Street extends \Magento\Framework\App\Config\Value
16 {
20  protected $_eavConfig;
21 
25  protected $_storeManager;
26 
38  public function __construct(
39  \Magento\Framework\Model\Context $context,
40  \Magento\Framework\Registry $registry,
42  \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
44  \Magento\Eav\Model\Config $eavConfig,
45  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
46  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
47  array $data = []
48  ) {
49  $this->_eavConfig = $eavConfig;
50  parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
51  $this->_storeManager = $storeManager;
52  }
53 
59  public function afterSave()
60  {
61  $attribute = $this->_eavConfig->getAttribute('customer_address', 'street');
62  $value = $this->getValue();
63  switch ($this->getScope()) {
64  case \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES:
65  $website = $this->_storeManager->getWebsite($this->getScopeCode());
66  $attribute->setWebsite($website);
67  $attribute->load($attribute->getId());
68  if ($attribute->getData('multiline_count') != $value) {
69  $attribute->setData('scope_multiline_count', $value);
70  }
71  break;
72 
74  $attribute->setData('multiline_count', $value);
75  break;
76  }
77  $attribute->save();
78  return parent::afterSave();
79  }
80 
86  public function afterDelete()
87  {
88  $result = parent::afterDelete();
89 
90  if ($this->getScope() == \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES) {
91  $attribute = $this->_eavConfig->getAttribute('customer_address', 'street');
92  $website = $this->_storeManager->getWebsite($this->getScopeCode());
93  $attribute->setWebsite($website);
94  $attribute->load($attribute->getId());
95  $attribute->setData('scope_multiline_count', null);
96  $attribute->save();
97  }
98 
99  return $result;
100  }
101 }
$config
Definition: fraud_order.php:17
$storeManager
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\App\Config\ScopeConfigInterface $config, \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
Definition: Street.php:38
$value
Definition: gender.phtml:16