Downloadable.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Downloadable\Block\Sales\Order\Item\Renderer;
  7. use Magento\Downloadable\Model\Link;
  8. use Magento\Downloadable\Model\Link\Purchased;
  9. use Magento\Store\Model\ScopeInterface;
  10. /**
  11. * Downloadable order item render block
  12. *
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Downloadable extends \Magento\Sales\Block\Order\Item\Renderer\DefaultRenderer
  17. {
  18. /**
  19. * @var Purchased
  20. */
  21. protected $_purchasedLinks;
  22. /**
  23. * @var \Magento\Downloadable\Model\Link\PurchasedFactory
  24. */
  25. protected $_purchasedFactory;
  26. /**
  27. * @var \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory
  28. */
  29. protected $_itemsFactory;
  30. /**
  31. * @param \Magento\Framework\View\Element\Template\Context $context
  32. * @param \Magento\Framework\Stdlib\StringUtils $string
  33. * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
  34. * @param \Magento\Downloadable\Model\Link\PurchasedFactory $purchasedFactory
  35. * @param \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory $itemsFactory
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Framework\View\Element\Template\Context $context,
  40. \Magento\Framework\Stdlib\StringUtils $string,
  41. \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
  42. \Magento\Downloadable\Model\Link\PurchasedFactory $purchasedFactory,
  43. \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory $itemsFactory,
  44. array $data = []
  45. ) {
  46. $this->_purchasedFactory = $purchasedFactory;
  47. $this->_itemsFactory = $itemsFactory;
  48. parent::__construct($context, $string, $productOptionFactory, $data);
  49. }
  50. /**
  51. * @return Purchased
  52. */
  53. public function getLinks()
  54. {
  55. $this->_purchasedLinks = $this->_purchasedFactory->create()->load(
  56. $this->getOrderItem()->getId(),
  57. 'order_item_id'
  58. );
  59. $purchasedItems = $this->_itemsFactory->create()->addFieldToFilter(
  60. 'order_item_id',
  61. $this->getOrderItem()->getId()
  62. );
  63. $this->_purchasedLinks->setPurchasedItems($purchasedItems);
  64. return $this->_purchasedLinks;
  65. }
  66. /**
  67. * @return string
  68. */
  69. public function getLinksTitle()
  70. {
  71. return $this->getLinks()->getLinkSectionTitle() ?: $this->_scopeConfig->getValue(
  72. Link::XML_PATH_LINKS_TITLE,
  73. ScopeInterface::SCOPE_STORE
  74. );
  75. }
  76. }