Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Title.php
Go to the documentation of this file.
1 <?php
8 
10 
17 {
21  protected $_titles;
22 
26  protected $_template = 'Magento_Tax::rate/title.phtml';
27 
31  protected $_storeFactory;
32 
36  protected $_coreRegistry;
37 
42 
52  public function __construct(
53  \Magento\Framework\View\Element\Template\Context $context,
54  \Magento\Store\Model\StoreFactory $storeFactory,
55  \Magento\Framework\Registry $coreRegistry,
56  \Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository,
57  array $data = []
58  ) {
59  $this->_coreRegistry = $coreRegistry;
60  $this->_taxRateRepository = $taxRateRepository;
61  $this->_storeFactory = $storeFactory;
62  parent::__construct($context, $data);
63  }
64 
70  public function getTitles()
71  {
72  if ($this->_titles === null) {
73  $this->_titles = [];
74 
75  $taxRateId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_TAX_RATE_ID);
76  $titles = [];
77  if ($taxRateId) {
78  $rate = $this->_taxRateRepository->get($taxRateId);
79  $titles = $rate->getTitles();
80  }
81 
82  foreach ($titles as $title) {
83  $this->_titles[$title->getStoreId()] = $title->getValue();
84  }
85  foreach ($this->getStores() as $store) {
86  if (!isset($this->_titles[$store->getId()])) {
87  $this->_titles[$store->getId()] = '';
88  }
89  }
90  }
91  return $this->_titles;
92  }
93 
97  public function getStores()
98  {
99  $stores = $this->getData('stores');
100  if ($stores === null) {
101  $stores = $this->_storeFactory->create()->getResourceCollection()->setLoadDefault(false)->load();
102  $this->setData('stores', $stores);
103  }
104  return $stores;
105  }
106 }
$title
Definition: default.phtml:14
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Store\Model\StoreFactory $storeFactory, \Magento\Framework\Registry $coreRegistry, \Magento\Tax\Api\TaxRateRepositoryInterface $taxRateRepository, array $data=[])
Definition: Title.php:52
getData($key='', $index=null)
Definition: DataObject.php:119
setData($key, $value=null)
Definition: DataObject.php:72