BlockProductViewGalleryMagnifier.php 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace WeltPixel\Quickview\Plugin;
  3. class BlockProductViewGalleryMagnifier
  4. {
  5. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_ENABLED = 'weltpixel_quickview/general/enable_zoom';
  6. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_FULLSCREENZOOM = 'weltpixel_quickview/general/zoom_fullscreenzoom';
  7. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_TOP = 'weltpixel_quickview/general/zoom_top';
  8. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_LEFT = 'weltpixel_quickview/general/zoom_left';
  9. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_WIDTH = 'weltpixel_quickview/general/zoom_width';
  10. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_HEIGHT = 'weltpixel_quickview/general/zoom_height';
  11. const XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_EVENTTYPE = 'weltpixel_quickview/general/zoom_eventtype';
  12. /**
  13. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  14. */
  15. protected $scopeConfig;
  16. /**
  17. * @var \Magento\Framework\App\Request\Http
  18. */
  19. protected $request;
  20. /**
  21. *
  22. * @var \Magento\Framework\Json\EncoderInterface
  23. */
  24. protected $jsonEncoder;
  25. /**
  26. *
  27. * @var \Magento\Framework\Json\DecoderInterface
  28. */
  29. protected $jsonDecoder;
  30. /**
  31. * ResultPage constructor.
  32. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  33. * @param \Magento\Framework\App\Request\Http $request
  34. * @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
  35. * @param \Magento\Framework\Json\DecoderInterface $jsonDecoder
  36. */
  37. public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  38. \Magento\Framework\App\Request\Http $request,
  39. \Magento\Framework\Json\EncoderInterface $jsonEncoder,
  40. \Magento\Framework\Json\DecoderInterface $jsonDecoder)
  41. {
  42. $this->request = $request;
  43. $this->scopeConfig = $scopeConfig;
  44. $this->jsonEncoder = $jsonEncoder;
  45. $this->jsonDecoder = $jsonDecoder;
  46. }
  47. /**
  48. * @param \Magento\Catalog\Block\Product\View\Gallery $subject
  49. * @param $result
  50. * @return mixed
  51. */
  52. public function afterGetMagnifier(
  53. \Magento\Catalog\Block\Product\View\Gallery $subject, $result
  54. )
  55. {
  56. if ($this->request->getFullActionName() != 'weltpixel_quickview_catalog_product_view') {
  57. return $result;
  58. }
  59. $result = $this->jsonDecoder->decode($result);
  60. $magnifierEnabled = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_ENABLED, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  61. $magnifierFullscreenzoom = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_FULLSCREENZOOM, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  62. $magnifierTop = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_TOP, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  63. $magnifierLeft = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_LEFT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  64. $magnifierWidth = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_WIDTH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  65. $magnifierHeight = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_HEIGHT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  66. $magnifierEventtype = $this->scopeConfig->getValue(self::XML_PATH_WELTPIXEL_QUICKVIEW_MAGNIFIER_EVENTTYPE, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
  67. $result['enabled'] = $magnifierEnabled;
  68. $result['fullscreenzoom'] = $magnifierFullscreenzoom;
  69. $result['top'] = $magnifierTop;
  70. $result['left'] = $magnifierLeft;
  71. $result['width'] = $magnifierWidth;
  72. $result['height'] = $magnifierHeight;
  73. $result['eventType'] = $magnifierEventtype;
  74. return $this->jsonEncoder->encode($result);
  75. }
  76. }