RickSnippet.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Smartwave\Porto\Block;
  3. class RickSnippet extends \Magento\Framework\View\Element\Template {
  4. protected $_coreRegistry;
  5. protected $_imageBuilder;
  6. protected $_reviewSummaryFactory;
  7. public function __construct(\Magento\Catalog\Block\Product\Context $productContext,
  8. \Magento\Review\Model\Review\SummaryFactory $reviewSummaryFactory,
  9. \Magento\Framework\View\Element\Template\Context $context, array $data = [])
  10. {
  11. $this->_coreRegistry = $productContext->getRegistry();
  12. $this->_reviewSummaryFactory = $reviewSummaryFactory;
  13. $this->_imageBuilder = $productContext->getImageBuilder();
  14. parent::__construct($context, $data);
  15. }
  16. public function getProduct()
  17. {
  18. return $this->_coreRegistry->registry('product');
  19. }
  20. public function getImage($product, $imageId, $attributes = [])
  21. {
  22. return $this->_imageBuilder->setProduct($product)
  23. ->setImageId($imageId)
  24. ->setAttributes($attributes)
  25. ->create();
  26. }
  27. public function getReviewSummary()
  28. {
  29. $storeId = $this->_storeManager->getStore()->getId();
  30. $reviewSummary = $this->_reviewSummaryFactory->create();
  31. $reviewSummary->setData('store_id', $storeId);
  32. $summaryModel = $reviewSummary->load($this->getProduct()->getId());
  33. return $summaryModel;
  34. }
  35. public function getCurrencyCode() {
  36. return $this->_storeManager->getStore()->getCurrentCurrencyCode();
  37. }
  38. }