Renderer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Block\Checkout\Cart\Item;
  7. use Magento\Bundle\Helper\Catalog\Product\Configuration;
  8. use Magento\Framework\Pricing\PriceCurrencyInterface;
  9. use Magento\Framework\View\Element\Message\InterpretationStrategyInterface;
  10. /**
  11. * Shopping cart item render block
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Renderer extends \Magento\Checkout\Block\Cart\Item\Renderer
  17. {
  18. /**
  19. * Bundle catalog product configuration
  20. *
  21. * @var Configuration
  22. */
  23. protected $_bundleProductConfiguration = null;
  24. /**
  25. * @param \Magento\Framework\View\Element\Template\Context $context
  26. * @param \Magento\Catalog\Helper\Product\Configuration $productConfig
  27. * @param \Magento\Checkout\Model\Session $checkoutSession
  28. * @param \Magento\Catalog\Block\Product\ImageBuilder|\Magento\Catalog\Helper\Image $imageBuilder
  29. * @param \Magento\Framework\Url\Helper\Data $urlHelper
  30. * @param \Magento\Framework\Message\ManagerInterface $messageManager
  31. * @param PriceCurrencyInterface $priceCurrency
  32. * @param \Magento\Framework\Module\Manager $moduleManager
  33. * @param InterpretationStrategyInterface $messageInterpretationStrategy
  34. * @param Configuration $bundleProductConfiguration
  35. * @param array $data
  36. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  37. */
  38. public function __construct(
  39. \Magento\Framework\View\Element\Template\Context $context,
  40. \Magento\Catalog\Helper\Product\Configuration $productConfig,
  41. \Magento\Checkout\Model\Session $checkoutSession,
  42. \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
  43. \Magento\Framework\Url\Helper\Data $urlHelper,
  44. \Magento\Framework\Message\ManagerInterface $messageManager,
  45. PriceCurrencyInterface $priceCurrency,
  46. \Magento\Framework\Module\Manager $moduleManager,
  47. InterpretationStrategyInterface $messageInterpretationStrategy,
  48. Configuration $bundleProductConfiguration,
  49. array $data = []
  50. ) {
  51. $this->_bundleProductConfiguration = $bundleProductConfiguration;
  52. parent::__construct(
  53. $context,
  54. $productConfig,
  55. $checkoutSession,
  56. $imageBuilder,
  57. $urlHelper,
  58. $messageManager,
  59. $priceCurrency,
  60. $moduleManager,
  61. $messageInterpretationStrategy,
  62. $data
  63. );
  64. $this->_isScopePrivate = true;
  65. }
  66. /**
  67. * Overloaded method for getting list of bundle options
  68. * Caches result in quote item, because it can be used in cart 'recent view' and on same page in cart checkout
  69. *
  70. * @return array
  71. */
  72. public function getOptionList()
  73. {
  74. return $this->_bundleProductConfiguration->getOptions($this->getItem());
  75. }
  76. /**
  77. * Return cart item error messages
  78. *
  79. * @return array
  80. */
  81. public function getMessages()
  82. {
  83. $messages = [];
  84. $quoteItem = $this->getItem();
  85. // Add basic messages occuring during this page load
  86. $baseMessages = $quoteItem->getMessage(false);
  87. if ($baseMessages) {
  88. foreach ($baseMessages as $message) {
  89. $messages[] = ['text' => $message, 'type' => $quoteItem->getHasError() ? 'error' : 'notice'];
  90. }
  91. }
  92. return $messages;
  93. }
  94. }