Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractEmail.php
Go to the documentation of this file.
1 <?php
7 
11 
16 {
22  protected $_products = [];
23 
29  protected $_store;
30 
34  protected $_maliciousCode;
35 
39  protected $priceCurrency;
40 
44  protected $imageBuilder;
45 
49  private $imageProvider;
50 
59  public function __construct(
60  \Magento\Framework\View\Element\Template\Context $context,
61  \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
63  \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
64  array $data = [],
65  ImageProvider $imageProvider = null
66  ) {
67  $this->imageBuilder = $imageBuilder;
68  $this->priceCurrency = $priceCurrency;
69  $this->_maliciousCode = $maliciousCode;
70  $this->imageProvider = $imageProvider ?: ObjectManager::getInstance()->get(ImageProvider::class);
71 
72  parent::__construct($context, $data);
73  }
74 
81  public function getFilteredContent($content)
82  {
83  return $this->_maliciousCode->filter($content);
84  }
85 
92  public function setStore($store)
93  {
94  if ($store instanceof \Magento\Store\Model\Website) {
95  $store = $store->getDefaultStore();
96  }
97  if (!$store instanceof \Magento\Store\Model\Store) {
98  $store = $this->_storeManager->getStore($store);
99  }
100 
101  $this->_store = $store;
102 
103  return $this;
104  }
105 
111  public function getStore()
112  {
113  if ($this->_store === null) {
114  $this->_store = $this->_storeManager->getStore();
115  }
116  return $this->_store;
117  }
118 
127  public function formatPrice($price, $format = true, $includeContainer = true)
128  {
129  return $format
130  ? $this->priceCurrency->convertAndFormat($price, $includeContainer)
131  : $this->priceCurrency->convert($price);
132  }
133 
139  public function reset()
140  {
141  $this->_products = [];
142  }
143 
150  public function addProduct(\Magento\Catalog\Model\Product $product)
151  {
152  $this->_products[$product->getId()] = $product;
153  }
154 
160  public function getProducts()
161  {
162  return $this->_products;
163  }
164 
170  protected function _getUrlParams()
171  {
172  return ['_scope' => $this->getStore(), '_scope_to_url' => true];
173  }
174 
178  protected function getPriceRender()
179  {
180  return $this->_layout->createBlock(
181  \Magento\Framework\Pricing\Render::class,
182  '',
183  ['data' => ['price_render_handle' => 'catalog_product_prices']]
184  );
185  }
186 
196  public function getProductPriceHtml(
197  \Magento\Catalog\Model\Product $product,
198  $priceType,
199  $renderZone = \Magento\Framework\Pricing\Render::ZONE_ITEM_LIST,
200  array $arguments = []
201  ) {
202  if (!isset($arguments['zone'])) {
203  $arguments['zone'] = $renderZone;
204  }
205 
207  $priceRender = $this->getPriceRender();
208  $price = '';
209 
210  if ($priceRender) {
211  $price = $priceRender->render(
212  $priceType,
213  $product,
214  $arguments
215  );
216  }
217  return $price;
218  }
219 
228  public function getImage($product, $imageId, $attributes = [])
229  {
230  return $this->imageProvider->getImage($product, $imageId, $attributes);
231  }
232 }
$price
$format
Definition: list.phtml:12
$priceType
Definition: msrp.phtml:18
getImage($product, $imageId, $attributes=[])
$attributes
Definition: matrix.phtml:13
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode, PriceCurrencyInterface $priceCurrency, \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder, array $data=[], ImageProvider $imageProvider=null)
$arguments
formatPrice($price, $format=true, $includeContainer=true)
addProduct(\Magento\Catalog\Model\Product $product)