Configure.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Wishlist Item Configure block
  8. * Serves for configuring item on product view page
  9. *
  10. * @module Wishlist
  11. */
  12. namespace Magento\Wishlist\Block\Item;
  13. /**
  14. * @api
  15. * @since 100.0.2
  16. */
  17. class Configure extends \Magento\Framework\View\Element\Template
  18. {
  19. /**
  20. * Wishlist data
  21. *
  22. * @var \Magento\Wishlist\Helper\Data
  23. */
  24. protected $_wishlistData = null;
  25. /**
  26. * Core registry
  27. *
  28. * @var \Magento\Framework\Registry
  29. */
  30. protected $_coreRegistry = null;
  31. /**
  32. * @param \Magento\Framework\View\Element\Template\Context $context
  33. * @param \Magento\Wishlist\Helper\Data $wishlistData
  34. * @param \Magento\Framework\Registry $registry
  35. * @param array $data
  36. */
  37. public function __construct(
  38. \Magento\Framework\View\Element\Template\Context $context,
  39. \Magento\Wishlist\Helper\Data $wishlistData,
  40. \Magento\Framework\Registry $registry,
  41. array $data = []
  42. ) {
  43. $this->_wishlistData = $wishlistData;
  44. $this->_coreRegistry = $registry;
  45. parent::__construct($context, $data);
  46. }
  47. /**
  48. * Return wishlist widget options
  49. *
  50. * @return array
  51. */
  52. public function getWishlistOptions()
  53. {
  54. return ['productType' => $this->escapeHtml($this->getProduct()->getTypeId())];
  55. }
  56. /**
  57. * Returns product being edited
  58. *
  59. * @return \Magento\Catalog\Model\Product
  60. */
  61. public function getProduct()
  62. {
  63. return $this->_coreRegistry->registry('product');
  64. }
  65. /**
  66. * Get update params for http post
  67. *
  68. * @return bool|string
  69. */
  70. public function getUpdateParams()
  71. {
  72. return $this->_wishlistData->getUpdateParams($this->getWishlistItem());
  73. }
  74. /**
  75. * Returns wishlist item being configured
  76. *
  77. * @return \Magento\Catalog\Model\Product|\Magento\Wishlist\Model\Item
  78. */
  79. protected function getWishlistItem()
  80. {
  81. return $this->_coreRegistry->registry('wishlist_item');
  82. }
  83. /**
  84. * Configure product view blocks
  85. *
  86. * @return $this
  87. */
  88. protected function _prepareLayout()
  89. {
  90. // Set custom add to cart url
  91. $block = $this->getLayout()->getBlock('product.info');
  92. if ($block && $this->getWishlistItem()) {
  93. $url = $this->_wishlistData->getAddToCartUrl($this->getWishlistItem());
  94. $block->setCustomAddToCartUrl($url);
  95. }
  96. return parent::_prepareLayout();
  97. }
  98. }