Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
7 
9 
18 class Data extends \Magento\Framework\Url\Helper\Data
19 {
25  protected $_product = null;
26 
32  protected $_coreRegistry = null;
33 
37  protected $_layout;
38 
42  private $_storeManager;
43 
50  public function __construct(
51  \Magento\Framework\App\Helper\Context $context,
52  \Magento\Store\Model\StoreManagerInterface $storeManager,
53  \Magento\Framework\Registry $coreRegistry,
54  \Magento\Framework\View\LayoutInterface $layout
55  ) {
56  $this->_coreRegistry = $coreRegistry;
57  $this->_layout = $layout;
58  $this->_storeManager = $storeManager;
59  parent::__construct($context);
60  }
61 
67  public function getProduct()
68  {
69  if ($this->_product !== null) {
70  return $this->_product;
71  }
72  return $this->_coreRegistry->registry('product');
73  }
74 
81  public function setProduct($product)
82  {
83  $this->_product = $product;
84  return $this;
85  }
86 
90  public function getStore()
91  {
92  return $this->_storeManager->getStore();
93  }
94 
99  public function getSaveUrl($type)
100  {
101  return $this->_getUrl(
102  'productalert/add/' . $type,
103  [
104  'product_id' => $this->getProduct()->getId(),
105  \Magento\Framework\App\ActionInterface::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl()
106  ]
107  );
108  }
109 
117  public function createBlock($block)
118  {
119  if (is_string($block)) {
120  if (class_exists($block)) {
121  $block = $this->_layout->createBlock($block);
122  }
123  }
124  if (!$block instanceof \Magento\Framework\View\Element\AbstractBlock) {
125  throw new \Magento\Framework\Exception\LocalizedException(__('Invalid block type: %1', $block));
126  }
127  return $block;
128  }
129 
135  public function isStockAlertAllowed()
136  {
137  return $this->scopeConfig->isSetFlag(
138  \Magento\ProductAlert\Model\Observer::XML_PATH_STOCK_ALLOW,
139  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
140  );
141  }
142 
148  public function isPriceAlertAllowed()
149  {
150  return $this->scopeConfig->isSetFlag(
151  \Magento\ProductAlert\Model\Observer::XML_PATH_PRICE_ALLOW,
152  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
153  );
154  }
155 }
$storeManager
__()
Definition: __.php:13
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\View\LayoutInterface $layout)
Definition: Data.php:50
$block
Definition: block.php:8
$type
Definition: item.phtml:13