Skip to content

Commit 7679766

Browse files
author
Cari Spruiell
committed
Merge branches 'MAGETWO-27932-Create-Gift-Message-Extension-For-Order' and 'develop' of github.scm.corp.ebay.com:magento-api/magento2ce into develop
2 parents 2d1bc64 + 9d1dcef commit 7679766

File tree

124 files changed

+1245
-227
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+1245
-227
lines changed

app/code/Magento/GiftMessage/Api/CartRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
interface CartRepositoryInterface
99
{
1010
/**
11-
* Returns the gift message for a specified order.
11+
* Return the gift message for a specified order.
1212
*
1313
* @param int $cartId The shopping cart ID.
1414
* @return \Magento\GiftMessage\Api\Data\MessageInterface Gift message.
1515
*/
1616
public function get($cartId);
1717

1818
/**
19-
* Sets the gift message for an entire order.
19+
* Set the gift message for an entire order.
2020
*
2121
* @param int $cartId The cart ID.
2222
* @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.

app/code/Magento/GiftMessage/Api/Data/MessageInterface.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,74 +18,74 @@ interface MessageInterface extends \Magento\Framework\Api\ExtensibleDataInterfac
1818
/**#@-*/
1919

2020
/**
21-
* Returns the gift message ID.
21+
* Return the gift message ID.
2222
*
2323
* @return int|null Gift message ID. Otherwise, null.
2424
*/
2525
public function getGiftMessageId();
2626

2727
/**
28-
* Sets the gift message ID.
28+
* Set the gift message ID.
2929
*
3030
* @param int|null $id
3131
* @return $this
3232
*/
3333
public function setGiftMessageId($id);
3434

3535
/**
36-
* Returns the customer ID.
36+
* Return the customer ID.
3737
*
3838
* @return int|null Customer ID. Otherwise, null.
3939
*/
4040
public function getCustomerId();
4141

4242
/**
43-
* Sets the customer ID.
43+
* Set the customer ID.
4444
*
4545
* @param int|null $id
4646
* @return $this
4747
*/
4848
public function setCustomerId($id);
4949

5050
/**
51-
* Returns the sender name.
51+
* Return the sender name.
5252
*
5353
* @return string Sender name.
5454
*/
5555
public function getSender();
5656

5757
/**
58-
* Sets the sender name.
58+
* Set the sender name.
5959
*
6060
* @param string $sender
6161
* @return $this
6262
*/
6363
public function setSender($sender);
6464

6565
/**
66-
* Returns the recipient name.
66+
* Return the recipient name.
6767
*
6868
* @return string Recipient name.
6969
*/
7070
public function getRecipient();
7171

7272
/**
73-
* Gets the recipient name.
73+
* Get the recipient name.
7474
*
7575
* @param string $recipient
7676
* @return $this
7777
*/
7878
public function setRecipient($recipient);
7979

8080
/**
81-
* Returns the message text.
81+
* Return the message text.
8282
*
8383
* @return string Message text.
8484
*/
8585
public function getMessage();
8686

8787
/**
88-
* Sets the message text.
88+
* Set the message text.
8989
*
9090
* @param string $message
9191
* @return $this

app/code/Magento/GiftMessage/Api/ItemRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
interface ItemRepositoryInterface
99
{
1010
/**
11-
* Returns the gift message for a specified item in a specified shopping cart.
11+
* Return the gift message for a specified item in a specified shopping cart.
1212
*
1313
* @param int $cartId The shopping cart ID.
1414
* @param int $itemId The item ID.
@@ -18,7 +18,7 @@ interface ItemRepositoryInterface
1818
public function get($cartId, $itemId);
1919

2020
/**
21-
* Sets the gift message for a specified item in a specified shopping cart.
21+
* Set the gift message for a specified item in a specified shopping cart.
2222
*
2323
* @param int $cartId The cart ID.
2424
* @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GiftMessage\Api;
7+
8+
interface OrderItemRepositoryInterface
9+
{
10+
/**
11+
* Return the gift message for a specified item in a specified order.
12+
*
13+
* @param int $orderId The order ID.
14+
* @param int $orderItemId The item ID.
15+
* @return \Magento\GiftMessage\Api\Data\MessageInterface Gift message.
16+
* @throws \Magento\Framework\Exception\NoSuchEntityException
17+
*/
18+
public function get($orderId, $orderItemId);
19+
20+
/**
21+
* Set the gift message for a specified item in a specified order.
22+
*
23+
* @param int $orderId The order ID.
24+
* @param int $orderItemId The item ID.
25+
* @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.
26+
* @return bool
27+
* @throws \Magento\Framework\Exception\NoSuchEntityException
28+
* @throws \Magento\Framework\Exception\State\InvalidTransitionException
29+
* @throws \Magento\Framework\Exception\CouldNotSaveException
30+
*/
31+
public function save($orderId, $orderItemId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage);
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\GiftMessage\Api;
7+
8+
interface OrderRepositoryInterface
9+
{
10+
/**
11+
* Return the gift message for a specified order.
12+
*
13+
* @param int $orderId The order ID.
14+
* @return \Magento\GiftMessage\Api\Data\MessageInterface Gift message.
15+
* @throws \Magento\Framework\Exception\NoSuchEntityException
16+
*/
17+
public function get($orderId);
18+
19+
/**
20+
* Set the gift message for an entire order.
21+
*
22+
* @param int $orderId The order ID.
23+
* @param \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage The gift message.
24+
* @return bool
25+
* @throws \Magento\Framework\Exception\NoSuchEntityException
26+
* @throws \Magento\Framework\Exception\InputException
27+
* @throws \Magento\Framework\Exception\CouldNotSaveException
28+
* @throws \Magento\Framework\Exception\State\InvalidTransitionException
29+
*/
30+
public function save($orderId, \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage);
31+
}

app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ public function __construct(
4747
public function canDisplayGiftmessageForm()
4848
{
4949
$quote = $this->_sessionQuote->getQuote();
50-
return $this->_messageHelper->getIsMessagesAvailable('items', $quote, $quote->getStore());
50+
return $this->_messageHelper->isMessagesAllowed('items', $quote, $quote->getStore());
5151
}
5252
}

app/code/Magento/GiftMessage/Block/Adminhtml/Sales/Order/Create/Items.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function canDisplayGiftMessage()
5252
if (!$item) {
5353
return false;
5454
}
55-
return $this->_messageHelper->getIsMessagesAvailable('item', $item, $item->getStoreId());
55+
return $this->_messageHelper->isMessagesAllowed('item', $item, $item->getStoreId());
5656
}
5757

5858
/**

app/code/Magento/GiftMessage/Block/Message/Inline.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ public function getEscaped($value, $defaultValue = '')
317317
*/
318318
public function isMessagesAvailable()
319319
{
320-
return $this->_giftMessageMessage->isMessagesAvailable('quote', $this->getEntity());
320+
return $this->_giftMessageMessage->isMessagesAllowed('quote', $this->getEntity());
321321
}
322322

323323
/**
@@ -329,7 +329,7 @@ public function isMessagesAvailable()
329329
public function isItemMessagesAvailable($item)
330330
{
331331
$type = substr($this->getType(), 0, 5) == 'multi' ? 'address_item' : 'item';
332-
return $this->_giftMessageMessage->isMessagesAvailable($type, $item);
332+
return $this->_giftMessageMessage->isMessagesAllowed($type, $item);
333333
}
334334

335335
/**

app/code/Magento/GiftMessage/Helper/Message.php

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function __construct(
109109
*/
110110
public function getInline($type, \Magento\Framework\Object $entity, $dontDisplayContainer = false)
111111
{
112-
if (!$this->skipPage($type) && !$this->isMessagesAvailable($type, $entity)) {
112+
if (!$this->skipPage($type) && !$this->isMessagesAllowed($type, $entity)) {
113113
return '';
114114
}
115115
return $this->_layoutFactory->create()->createBlock('Magento\GiftMessage\Block\Message\Inline')
@@ -129,20 +129,24 @@ protected function skipPage($pageType)
129129
}
130130

131131
/**
132-
* Check availability of giftmessages for specified entity.
132+
* Check if giftmessages is allowed for specified entity.
133133
*
134134
* @param string $type
135135
* @param \Magento\Framework\Object $entity
136136
* @param \Magento\Store\Model\Store|int|null $store
137137
* @return bool|string|null
138138
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
139139
*/
140-
public function isMessagesAvailable($type, \Magento\Framework\Object $entity, $store = null)
140+
public function isMessagesAllowed($type, \Magento\Framework\Object $entity, $store = null)
141141
{
142142
if ($type == 'items') {
143143
$items = $entity->getAllItems();
144144
if (!is_array($items) || empty($items)) {
145-
return $this->scopeConfig->getValue(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
145+
return $this->scopeConfig->getValue(
146+
self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
147+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
148+
$store
149+
);
146150
}
147151
if ($entity instanceof \Magento\Quote\Model\Quote) {
148152
$_type = $entity->getIsMultiShipping() ? 'address_item' : 'item';
@@ -153,7 +157,7 @@ public function isMessagesAvailable($type, \Magento\Framework\Object $entity, $s
153157
if ($item->getParentItem()) {
154158
continue;
155159
}
156-
if ($this->isMessagesAvailable($_type, $item, $store)) {
160+
if ($this->isMessagesAllowed($_type, $item, $store)) {
157161
return true;
158162
}
159163
}
@@ -177,7 +181,11 @@ public function isMessagesAvailable($type, \Magento\Framework\Object $entity, $s
177181
$store
178182
);
179183
} else {
180-
return $this->scopeConfig->getValue(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
184+
return $this->scopeConfig->getValue(
185+
self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ORDER,
186+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
187+
$store
188+
);
181189
}
182190
return false;
183191
}
@@ -191,27 +199,17 @@ public function isMessagesAvailable($type, \Magento\Framework\Object $entity, $s
191199
*/
192200
protected function _getDependenceFromStoreConfig($productGiftMessageAllow, $store = null)
193201
{
194-
$result = $this->scopeConfig->getValue(self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store);
202+
$result = $this->scopeConfig->getValue(
203+
self::XPATH_CONFIG_GIFT_MESSAGE_ALLOW_ITEMS,
204+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $store
205+
);
195206
if ($productGiftMessageAllow === '' || is_null($productGiftMessageAllow)) {
196207
return $result;
197208
} else {
198209
return $productGiftMessageAllow;
199210
}
200211
}
201212

202-
/**
203-
* Alias for isMessagesAvailable(...)
204-
*
205-
* @param string $type
206-
* @param \Magento\Framework\Object $entity
207-
* @param \Magento\Store\Model\Store|int|null $store
208-
* @return bool|null|string
209-
*/
210-
public function getIsMessagesAvailable($type, \Magento\Framework\Object $entity, $store = null)
211-
{
212-
return $this->isMessagesAvailable($type, $entity, $store);
213-
}
214-
215213
/**
216214
* Retrieve escaped and preformated gift message text for specified entity
217215
*
@@ -293,7 +291,7 @@ public function setCached($key, $value)
293291
public function getAvailableForQuoteItems($quote, $store = null)
294292
{
295293
foreach ($quote->getAllItems() as $item) {
296-
if ($this->isMessagesAvailable('item', $item, $store)) {
294+
if ($this->isMessagesAllowed('item', $item, $store)) {
297295
return true;
298296
}
299297
}
@@ -311,7 +309,7 @@ public function getAvailableForQuoteItems($quote, $store = null)
311309
public function getAvailableForAddressItems($items, $store = null)
312310
{
313311
foreach ($items as $item) {
314-
if ($this->isMessagesAvailable('address_item', $item, $store)) {
312+
if ($this->isMessagesAllowed('address_item', $item, $store)) {
315313
return true;
316314
}
317315
}

app/code/Magento/GiftMessage/Model/CartRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function save($cartId, \Magento\GiftMessage\Api\Data\MessageInterface $gi
107107
if ($quote->isVirtual()) {
108108
throw new InvalidTransitionException(__('Gift Messages is not applicable for virtual products'));
109109
}
110-
if (!$this->helper->getIsMessagesAvailable('quote', $quote, $this->storeManager->getStore())) {
110+
if (!$this->helper->isMessagesAllowed('quote', $quote, $this->storeManager->getStore())) {
111111
throw new CouldNotSaveException(__('Gift Message is not available'));
112112
}
113113
$this->giftMessageManager->setMessage($quote, 'quote', $giftMessage);

0 commit comments

Comments
 (0)