Street.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Model\Config\Backend\Address;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. /**
  9. * Line count config model for customer address street attribute
  10. *
  11. * @method string getWebsiteCode()
  12. */
  13. class Street extends \Magento\Framework\App\Config\Value
  14. {
  15. /**
  16. * @var \Magento\Eav\Model\Config
  17. */
  18. protected $_eavConfig;
  19. /**
  20. * @var \Magento\Store\Model\StoreManagerInterface
  21. */
  22. protected $_storeManager;
  23. /**
  24. * @param \Magento\Framework\Model\Context $context
  25. * @param \Magento\Framework\Registry $registry
  26. * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
  27. * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
  28. * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  29. * @param \Magento\Eav\Model\Config $eavConfig
  30. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  31. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  32. * @param array $data
  33. */
  34. public function __construct(
  35. \Magento\Framework\Model\Context $context,
  36. \Magento\Framework\Registry $registry,
  37. \Magento\Framework\App\Config\ScopeConfigInterface $config,
  38. \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
  39. \Magento\Store\Model\StoreManagerInterface $storeManager,
  40. \Magento\Eav\Model\Config $eavConfig,
  41. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  42. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  43. array $data = []
  44. ) {
  45. $this->_eavConfig = $eavConfig;
  46. parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
  47. $this->_storeManager = $storeManager;
  48. }
  49. /**
  50. * Actions after save
  51. *
  52. * @return $this
  53. */
  54. public function afterSave()
  55. {
  56. $attribute = $this->_eavConfig->getAttribute('customer_address', 'street');
  57. $value = $this->getValue();
  58. switch ($this->getScope()) {
  59. case \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES:
  60. $website = $this->_storeManager->getWebsite($this->getScopeCode());
  61. $attribute->setWebsite($website);
  62. $attribute->load($attribute->getId());
  63. if ($attribute->getData('multiline_count') != $value) {
  64. $attribute->setData('scope_multiline_count', $value);
  65. }
  66. break;
  67. case ScopeConfigInterface::SCOPE_TYPE_DEFAULT:
  68. $attribute->setData('multiline_count', $value);
  69. break;
  70. }
  71. $attribute->save();
  72. return parent::afterSave();
  73. }
  74. /**
  75. * Processing object after delete data
  76. *
  77. * @return \Magento\Framework\Model\AbstractModel
  78. */
  79. public function afterDelete()
  80. {
  81. $result = parent::afterDelete();
  82. $attribute = $this->_eavConfig->getAttribute('customer_address', 'street');
  83. switch ($this->getScope()) {
  84. case \Magento\Store\Model\ScopeInterface::SCOPE_WEBSITES:
  85. $website = $this->_storeManager->getWebsite($this->getScopeCode());
  86. $attribute->setWebsite($website);
  87. $attribute->load($attribute->getId());
  88. $attribute->setData('scope_multiline_count', null);
  89. break;
  90. case ScopeConfigInterface::SCOPE_TYPE_DEFAULT:
  91. $attribute->setData('multiline_count', 2);
  92. break;
  93. }
  94. $attribute->save();
  95. return $result;
  96. }
  97. }