BlockProductList.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace WeltPixel\Quickview\Plugin;
  3. class BlockProductList
  4. {
  5. const XML_PATH_QUICKVIEW_ENABLED = 'weltpixel_quickview/general/enable_product_listing';
  6. const XML_PATH_QUICKVIEW_BUTTONSTYLE = 'weltpixel_quickview/general/button_style';
  7. /**
  8. * @var \Magento\Framework\UrlInterface
  9. */
  10. protected $urlInterface;
  11. /**
  12. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  13. */
  14. protected $scopeConfig;
  15. /**
  16. * @param \Magento\Framework\UrlInterface $urlInterface
  17. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  18. */
  19. public function __construct(
  20. \Magento\Framework\UrlInterface $urlInterface,
  21. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  22. ) {
  23. $this->urlInterface = $urlInterface;
  24. $this->scopeConfig = $scopeConfig;
  25. }
  26. public function aroundGetProductDetailsHtml(
  27. \Magento\Catalog\Block\Product\ListProduct $subject,
  28. \Closure $proceed,
  29. \Magento\Catalog\Model\Product $product
  30. )
  31. {
  32. $result = $proceed($product);
  33. $isEnabled = $this->scopeConfig->getValue(self::XML_PATH_QUICKVIEW_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  34. if ($isEnabled) {
  35. $buttonStyle = 'weltpixel_quickview_button_' . $this->scopeConfig->getValue(self::XML_PATH_QUICKVIEW_BUTTONSTYLE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  36. $productUrl = $this->urlInterface->getUrl('weltpixel_quickview/catalog_product/view', array('id' => $product->getId()));
  37. return $result . '<a class="weltpixel-quickview '.$buttonStyle.'" data-quickview-url=' . $productUrl . ' href="javascript:void(0);"><span><em class="porto-icon-eye"></em><span>' . __("Quickview") . '</span></span></a>';
  38. }
  39. return $result;
  40. }
  41. }