From c7612904356747c6947b68bc209c2f669a87d87e Mon Sep 17 00:00:00 2001
From: Arkadii Chyzhov <achyzhov@ebay.com>
Date: Mon, 30 Mar 2015 11:45:13 +0300
Subject: [PATCH] MAGETWO-35391: Create services for order and orderItem

- fix due to CR's comments
---
 .../Block/Adminhtml/Sales/Order/Create/Form.php     |  2 +-
 .../Block/Adminhtml/Sales/Order/Create/Items.php    |  2 +-
 app/code/Magento/GiftMessage/Helper/Message.php     | 13 -------------
 .../Magento/GiftMessage/Model/CartRepository.php    |  2 +-
 .../Magento/GiftMessage/Model/ItemRepository.php    |  2 +-
 .../GiftMessage/Model/OrderItemRepository.php       |  4 ++--
 .../Magento/GiftMessage/Model/OrderRepository.php   |  4 ++--
 app/code/Magento/GiftMessage/Model/Save.php         |  2 +-
 .../Test/Unit/Model/CartRepositoryTest.php          |  2 +-
 .../Test/Unit/Model/ItemRepositoryTest.php          |  2 +-
 .../Block/Adminhtml/Order/Create/Giftmessage.php    |  2 +-
 .../Block/Adminhtml/Order/Create/Items/Grid.php     |  4 ++--
 .../Block/Adminhtml/Order/View/Giftmessage.php      |  2 +-
 .../Order/View/Items/Renderer/DefaultRenderer.php   |  2 +-
 .../Magento/Test/Legacy/_files/obsolete_methods.php |  5 +++++
 15 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php b/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php
index a7c3fcafb72..c5d2d46cccf 100644
--- a/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php
+++ b/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php
@@ -47,6 +47,6 @@ class Form extends \Magento\Backend\Block\Template
     public function canDisplayGiftmessageForm()
     {
         $quote = $this->_sessionQuote->getQuote();
-        return $this->_messageHelper->getIsMessagesAllowed('items', $quote, $quote->getStore());
+        return $this->_messageHelper->isMessagesAllowed('items', $quote, $quote->getStore());
     }
 }
diff --git a/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php b/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php
index d9647363cb1..f343fce19c7 100644
--- a/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php
+++ b/app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php
@@ -52,7 +52,7 @@ class Items extends \Magento\Backend\Block\Template
         if (!$item) {
             return false;
         }
-        return $this->_messageHelper->getIsMessagesAllowed('item', $item, $item->getStoreId());
+        return $this->_messageHelper->isMessagesAllowed('item', $item, $item->getStoreId());
     }
 
     /**
diff --git a/app/code/Magento/GiftMessage/Helper/Message.php b/app/code/Magento/GiftMessage/Helper/Message.php
index f722cca2f33..e2ab3e3eefa 100644
--- a/app/code/Magento/GiftMessage/Helper/Message.php
+++ b/app/code/Magento/GiftMessage/Helper/Message.php
@@ -210,19 +210,6 @@ class Message extends \Magento\Framework\App\Helper\AbstractHelper
         }
     }
 
-    /**
-     * Alias for isMessagesAllowed(...)
-     *
-     * @param string $type
-     * @param \Magento\Framework\Object $entity
-     * @param \Magento\Store\Model\Store|int|null $store
-     * @return bool|null|string
-     */
-    public function getIsMessagesAllowed($type, \Magento\Framework\Object $entity, $store = null)
-    {
-        return $this->isMessagesAllowed($type, $entity, $store);
-    }
-
     /**
      * Retrieve escaped and preformated gift message text for specified entity
      *
diff --git a/app/code/Magento/GiftMessage/Model/CartRepository.php b/app/code/Magento/GiftMessage/Model/CartRepository.php
index 8ec5cf50a2f..4fe6b988236 100644
--- a/app/code/Magento/GiftMessage/Model/CartRepository.php
+++ b/app/code/Magento/GiftMessage/Model/CartRepository.php
@@ -107,7 +107,7 @@ class CartRepository implements \Magento\GiftMessage\Api\CartRepositoryInterface
         if ($quote->isVirtual()) {
             throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
         }
-        if (!$this->helper->getIsMessagesAllowed('quote', $quote, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) {
             throw new CouldNotSaveException(__('Gift Message is not available'));
         }
         $this->giftMessageManager->setMessage($quote, 'quote', $giftMessage);
diff --git a/app/code/Magento/GiftMessage/Model/ItemRepository.php b/app/code/Magento/GiftMessage/Model/ItemRepository.php
index e4b0a387869..d7220d2516f 100644
--- a/app/code/Magento/GiftMessage/Model/ItemRepository.php
+++ b/app/code/Magento/GiftMessage/Model/ItemRepository.php
@@ -121,7 +121,7 @@ class ItemRepository implements \Magento\GiftMessage\Api\ItemRepositoryInterface
         if ($item->getIsVirtual()) {
             throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
         }
-        if (!$this->helper->getIsMessagesAllowed('items', $quote, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('items', $quote, $this->storeManager->getStore())) {
             throw new CouldNotSaveException(__('Gift Message is not available'));
         }
         $this->giftMessageManager->setMessage($quote, 'quote_item', $giftMessage, $itemId);
diff --git a/app/code/Magento/GiftMessage/Model/OrderItemRepository.php b/app/code/Magento/GiftMessage/Model/OrderItemRepository.php
index ba784da27b0..4c71f599f0b 100644
--- a/app/code/Magento/GiftMessage/Model/OrderItemRepository.php
+++ b/app/code/Magento/GiftMessage/Model/OrderItemRepository.php
@@ -82,7 +82,7 @@ class OrderItemRepository implements \Magento\GiftMessage\Api\OrderItemRepositor
             throw new NoSuchEntityException(__('There is no item with provided id in the order'));
         };
 
-        if (!$this->helper->getIsMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) {
             throw new NoSuchEntityException(
                 __('There is no item with provided id in the order or gift message isn\'t allowed')
             );
@@ -112,7 +112,7 @@ class OrderItemRepository implements \Magento\GiftMessage\Api\OrderItemRepositor
         if ($order->getIsVirtual()) {
             throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
         }
-        if (!$this->helper->getIsMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('order_item', $orderItem, $this->storeManager->getStore())) {
             throw new CouldNotSaveException(__('Gift Message is not available'));
         }
 
diff --git a/app/code/Magento/GiftMessage/Model/OrderRepository.php b/app/code/Magento/GiftMessage/Model/OrderRepository.php
index 29e14566dde..741cce2a4aa 100644
--- a/app/code/Magento/GiftMessage/Model/OrderRepository.php
+++ b/app/code/Magento/GiftMessage/Model/OrderRepository.php
@@ -81,7 +81,7 @@ class OrderRepository implements \Magento\GiftMessage\Api\OrderRepositoryInterfa
         /** @var \Magento\Sales\Api\Data\OrderInterface $order */
         $order = $this->orderFactory->create()->load($orderId);
 
-        if (!$this->helper->getIsMessagesAllowed('order', $order, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('order', $order, $this->storeManager->getStore())) {
             throw new NoSuchEntityException(
                 __('There is no order with provided id or gift message isn\'t allowed')
             );
@@ -113,7 +113,7 @@ class OrderRepository implements \Magento\GiftMessage\Api\OrderRepositoryInterfa
         if ($order->getIsVirtual()) {
             throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
         }
-        if (!$this->helper->getIsMessagesAllowed('order', $order, $this->storeManager->getStore())) {
+        if (!$this->helper->isMessagesAllowed('order', $order, $this->storeManager->getStore())) {
             throw new CouldNotSaveException(__('Gift Message is not available'));
         }
 
diff --git a/app/code/Magento/GiftMessage/Model/Save.php b/app/code/Magento/GiftMessage/Model/Save.php
index 558ab84f200..7841e2f3786 100644
--- a/app/code/Magento/GiftMessage/Model/Save.php
+++ b/app/code/Magento/GiftMessage/Model/Save.php
@@ -265,7 +265,7 @@ class Save extends \Magento\Framework\Object
      */
     public function isGiftMessagesAvailable($item)
     {
-        return $this->_giftMessageMessage->getIsMessagesAllowed('item', $item, $item->getStore());
+        return $this->_giftMessageMessage->isMessagesAllowed('item', $item, $item->getStore());
     }
 
     /**
diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php
index 132fb8c0de5..6974c1f131c 100644
--- a/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php
+++ b/app/code/Magento/GiftMessage/Test/Unit/Model/CartRepositoryTest.php
@@ -172,7 +172,7 @@ class CartRepositoryTest extends \PHPUnit_Framework_TestCase
         $this->quoteMock->expects($this->once())->method('getItemsCount')->will($this->returnValue(1));
         $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
         $this->helperMock->expects($this->once())
-            ->method('getIsMessagesAllowed')
+            ->method('isMessagesAllowed')
             ->with('quote', $this->quoteMock, $this->storeMock)
             ->will($this->returnValue(true));
         $this->giftMessageManagerMock->expects($this->once())
diff --git a/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php b/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php
index 3d90238b453..5caa71f1b2b 100644
--- a/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php
+++ b/app/code/Magento/GiftMessage/Test/Unit/Model/ItemRepositoryTest.php
@@ -211,7 +211,7 @@ class ItemRepositoryTest extends \PHPUnit_Framework_TestCase
         $quoteItem->expects($this->once())->method('getIsVirtual')->will($this->returnValue(0));
         $this->storeManagerMock->expects($this->once())->method('getStore')->will($this->returnValue($this->storeMock));
         $this->helperMock->expects($this->once())
-            ->method('getIsMessagesAllowed')
+            ->method('isMessagesAllowed')
             ->with('items', $this->quoteMock, $this->storeMock)
             ->will($this->returnValue(true));
         $this->giftMessageManagerMock->expects($this->once())
diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Giftmessage.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Giftmessage.php
index 249811c7731..52cc36384d6 100644
--- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Giftmessage.php
+++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Giftmessage.php
@@ -84,7 +84,7 @@ class Giftmessage extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCr
         foreach ($allItems as $item) {
             if ($this->_getGiftmessageSaveModel()->getIsAllowedQuoteItem(
                 $item
-            ) && $this->_messageHelper->getIsMessagesAllowed(
+            ) && $this->_messageHelper->isMessagesAllowed(
                 'item',
                 $item,
                 $this->getStore()
diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php
index f3172e54968..fe33696ba77 100644
--- a/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php
+++ b/app/code/Magento/Sales/Block/Adminhtml/Order/Create/Items/Grid.php
@@ -232,9 +232,9 @@ class Grid extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
     public function isGiftMessagesAvailable($item = null)
     {
         if ($item === null) {
-            return $this->_messageHelper->getIsMessagesAllowed('items', $this->getQuote(), $this->getStore());
+            return $this->_messageHelper->isMessagesAllowed('items', $this->getQuote(), $this->getStore());
         }
-        return $this->_messageHelper->getIsMessagesAllowed('item', $item, $this->getStore());
+        return $this->_messageHelper->isMessagesAllowed('item', $item, $this->getStore());
     }
 
     /**
diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Giftmessage.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Giftmessage.php
index 999d9df016e..2f70036c540 100644
--- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Giftmessage.php
+++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Giftmessage.php
@@ -290,7 +290,7 @@ class Giftmessage extends \Magento\Backend\Block\Widget
      */
     public function canDisplayGiftmessage()
     {
-        return $this->_messageHelper->getIsMessagesAllowed(
+        return $this->_messageHelper->isMessagesAllowed(
             'order',
             $this->getEntity(),
             $this->getEntity()->getStoreId()
diff --git a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Items/Renderer/DefaultRenderer.php b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Items/Renderer/DefaultRenderer.php
index 5e98a9ef2fa..92cc81fa6f2 100644
--- a/app/code/Magento/Sales/Block/Adminhtml/Order/View/Items/Renderer/DefaultRenderer.php
+++ b/app/code/Magento/Sales/Block/Adminhtml/Order/View/Items/Renderer/DefaultRenderer.php
@@ -220,7 +220,7 @@ class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\Defa
      */
     public function canDisplayGiftmessage()
     {
-        return $this->_messageHelper->getIsMessagesAllowed(
+        return $this->_messageHelper->isMessagesAllowed(
             'order_item',
             $this->getItem(),
             $this->getItem()->getOrder()->getStoreId()
diff --git a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php
index 21ff60a356b..b8908add5d8 100644
--- a/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php
+++ b/dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php
@@ -338,6 +338,11 @@ return [
     ['_getItemPosition', 'Magento\Catalog\Block\Navigation'],
     ['_renderCategoryMenuItemHtml', 'Magento\Catalog\Block\Navigation'],
     ['getCurrentCategoryPath', 'Magento\Catalog\Block\Navigation'],
+    [
+        'getIsMessagesAvailable',
+        'Magento\GiftMessage\Helper\Message',
+        'Magento\GiftMessage\Helper\Message::isMessageAllowed'
+    ],
     ['drawOpenCategoryItem', 'Magento\Catalog\Block\Navigation'],
     ['renderCategoriesMenuHtml', 'Magento\Catalog\Block\Navigation'],
     ['dropKey', 'Magento\Framework\DB\Adapter\Pdo\Mysql'],
-- 
GitLab