Grid.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Shipping\Block\Adminhtml\Order\Packaging;
  7. class Grid extends \Magento\Backend\Block\Template
  8. {
  9. /**
  10. * @var string
  11. */
  12. protected $_template = 'Magento_Shipping::order/packaging/grid.phtml';
  13. /**
  14. * Core registry
  15. *
  16. * @var \Magento\Framework\Registry
  17. */
  18. protected $_coreRegistry = null;
  19. /**
  20. * @var \Magento\Sales\Model\Order\Shipment\ItemFactory
  21. */
  22. protected $_shipmentItemFactory;
  23. /**
  24. * @param \Magento\Backend\Block\Template\Context $context
  25. * @param \Magento\Sales\Model\Order\Shipment\ItemFactory $shipmentItemFactory
  26. * @param \Magento\Framework\Registry $registry
  27. * @param array $data
  28. */
  29. public function __construct(
  30. \Magento\Backend\Block\Template\Context $context,
  31. \Magento\Sales\Model\Order\Shipment\ItemFactory $shipmentItemFactory,
  32. \Magento\Framework\Registry $registry,
  33. array $data = []
  34. ) {
  35. $this->_shipmentItemFactory = $shipmentItemFactory;
  36. $this->_coreRegistry = $registry;
  37. parent::__construct($context, $data);
  38. }
  39. /**
  40. * Return collection of shipment items
  41. *
  42. * @return array
  43. */
  44. public function getCollection()
  45. {
  46. if ($this->getShipment()->getId()) {
  47. $collection = $this->_shipmentItemFactory->create()->getCollection()->setShipmentFilter(
  48. $this->getShipment()->getId()
  49. );
  50. } else {
  51. $collection = $this->getShipment()->getAllItems();
  52. }
  53. return $collection;
  54. }
  55. /**
  56. * Retrieve shipment model instance
  57. *
  58. * @return \Magento\Sales\Model\Order\Shipment
  59. */
  60. public function getShipment()
  61. {
  62. return $this->_coreRegistry->registry('current_shipment');
  63. }
  64. /**
  65. * Can display customs value
  66. *
  67. * @return bool
  68. */
  69. public function displayCustomsValue()
  70. {
  71. $storeId = $this->getShipment()->getStoreId();
  72. $order = $this->getShipment()->getOrder();
  73. $address = $order->getShippingAddress();
  74. $shipperAddressCountryCode = $this->_scopeConfig->getValue(
  75. \Magento\Sales\Model\Order\Shipment::XML_PATH_STORE_COUNTRY_ID,
  76. \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
  77. $storeId
  78. );
  79. $recipientAddressCountryCode = $address->getCountryId();
  80. if ($shipperAddressCountryCode != $recipientAddressCountryCode) {
  81. return true;
  82. }
  83. return false;
  84. }
  85. /**
  86. * Format price
  87. *
  88. * @param float $value
  89. * @return string
  90. */
  91. public function formatPrice($value)
  92. {
  93. return sprintf('%.2F', $value);
  94. }
  95. }