123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\GiftMessage\Block\Adminhtml\Sales\Order\View;
- /**
- * Gift message adminhtml sales order view items
- *
- * @api
- * @author Magento Core Team <core@magentocommerce.com>
- * @since 100.0.2
- */
- class Items extends \Magento\Backend\Block\Template
- {
- /**
- * Gift message array
- *
- * @var array
- */
- protected $_giftMessage = [];
- /**
- * @var \Magento\GiftMessage\Helper\Message
- */
- protected $_messageHelper;
- /**
- * @param \Magento\Backend\Block\Template\Context $context
- * @param \Magento\GiftMessage\Helper\Message $messageHelper
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Template\Context $context,
- \Magento\GiftMessage\Helper\Message $messageHelper,
- array $data = []
- ) {
- $this->_messageHelper = $messageHelper;
- parent::__construct($context, $data);
- }
- /**
- * Get Order Item
- *
- * @return \Magento\Sales\Model\Order\Item
- * @codeCoverageIgnore
- */
- public function getItem()
- {
- return $this->getParentBlock()->getItem();
- }
- /**
- * Retrieve default value for giftmessage sender
- *
- * @return string
- */
- public function getDefaultSender()
- {
- if (!$this->getItem()) {
- return '';
- }
- if ($this->getItem()->getOrder()) {
- return $this->getItem()->getOrder()->getBillingAddress()->getName();
- }
- return $this->getItem()->getBillingAddress()->getName();
- }
- /**
- * Retrieve default value for giftmessage recipient
- *
- * @return string
- */
- public function getDefaultRecipient()
- {
- if (!$this->getItem()) {
- return '';
- }
- if ($this->getItem()->getOrder()) {
- if ($this->getItem()->getOrder()->getShippingAddress()) {
- return $this->getItem()->getOrder()->getShippingAddress()->getName();
- } elseif ($this->getItem()->getOrder()->getBillingAddress()) {
- return $this->getItem()->getOrder()->getBillingAddress()->getName();
- }
- }
- if ($this->getItem()->getShippingAddress()) {
- return $this->getItem()->getShippingAddress()->getName();
- } elseif ($this->getItem()->getBillingAddress()) {
- return $this->getItem()->getBillingAddress()->getName();
- }
- return '';
- }
- /**
- * Retrieve real name for field
- *
- * @param string $name
- * @return string
- * @codeCoverageIgnore
- */
- public function getFieldName($name)
- {
- return 'giftmessage[' . $this->getItem()->getId() . '][' . $name . ']';
- }
- /**
- * Retrieve real html id for field
- *
- * @param string $id
- * @return string
- * @codeCoverageIgnore
- */
- public function getFieldId($id)
- {
- return $this->getFieldIdPrefix() . $id;
- }
- /**
- * Retrieve field html id prefix
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getFieldIdPrefix()
- {
- return 'giftmessage_' . $this->getItem()->getId() . '_';
- }
- /**
- * Initialize gift message for entity
- *
- * @return $this
- */
- protected function _initMessage()
- {
- $this->_giftMessage[$this->getItem()->getGiftMessageId()] = $this->_messageHelper->getGiftMessage(
- $this->getItem()->getGiftMessageId()
- );
- // init default values for giftmessage form
- if (!$this->getMessage()->getSender()) {
- $this->getMessage()->setSender($this->getDefaultSender());
- }
- if (!$this->getMessage()->getRecipient()) {
- $this->getMessage()->setRecipient($this->getDefaultRecipient());
- }
- return $this;
- }
- /**
- * Retrieve gift message for entity
- *
- * @return \Magento\GiftMessage\Model\Message
- */
- public function getMessage()
- {
- if (!isset($this->_giftMessage[$this->getItem()->getGiftMessageId()])) {
- $this->_initMessage();
- }
- return $this->_giftMessage[$this->getItem()->getGiftMessageId()];
- }
- /**
- * Retrieve save url
- *
- * @return array
- * @codeCoverageIgnore
- */
- public function getSaveUrl()
- {
- return $this->getUrl(
- 'sales/order_view_giftmessage/save',
- ['entity' => $this->getItem()->getId(), 'type' => 'order_item', 'reload' => true]
- );
- }
- /**
- * Retrieve block html id
- *
- * @return string
- * @codeCoverageIgnore
- */
- public function getHtmlId()
- {
- return substr($this->getFieldIdPrefix(), 0, -1);
- }
- /**
- * Indicates that block can display giftmessages form
- *
- * @return boolean
- */
- public function canDisplayGiftmessage()
- {
- return $this->getItem()->getGiftMessageId();
- }
- /**
- * Retrieve gift message sender
- *
- * @return string
- */
- public function getSender()
- {
- return $this->escapeHtml($this->getMessage()->getSender());
- }
- /**
- * Retrieve gift message recipient
- *
- * @return string
- */
- public function getRecipient()
- {
- return $this->escapeHtml($this->getMessage()->getRecipient());
- }
- /**
- * Retrieve gift message text
- *
- * @return string
- */
- public function getMessageText()
- {
- return $this->escapeHtml($this->getMessage()->getMessage());
- }
- }
|