Skip to content

Commit 05417ce

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/2.2-develop' into MC-15874-2
2 parents 35ad602 + c52ee4a commit 05417ce

File tree

27 files changed

+736
-408
lines changed

27 files changed

+736
-408
lines changed

app/code/Magento/Braintree/Controller/Paypal/Review.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Braintree\Gateway\Config\PayPal\Config;
1212
use Magento\Braintree\Model\Paypal\Helper\QuoteUpdater;
1313
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Payment\Model\Method\Logger;
1415

1516
/**
1617
* Class Review
@@ -22,6 +23,11 @@ class Review extends AbstractAction
2223
*/
2324
private $quoteUpdater;
2425

26+
/**
27+
* @var Logger
28+
*/
29+
private $logger;
30+
2531
/**
2632
* @var string
2733
*/
@@ -34,15 +40,18 @@ class Review extends AbstractAction
3440
* @param Config $config
3541
* @param Session $checkoutSession
3642
* @param QuoteUpdater $quoteUpdater
43+
* @param Logger $logger
3744
*/
3845
public function __construct(
3946
Context $context,
4047
Config $config,
4148
Session $checkoutSession,
42-
QuoteUpdater $quoteUpdater
49+
QuoteUpdater $quoteUpdater,
50+
Logger $logger
4351
) {
4452
parent::__construct($context, $config, $checkoutSession);
4553
$this->quoteUpdater = $quoteUpdater;
54+
$this->logger = $logger;
4655
}
4756

4857
/**
@@ -54,6 +63,7 @@ public function execute()
5463
$this->getRequest()->getPostValue('result', '{}'),
5564
true
5665
);
66+
$this->logger->debug($requestData);
5767
$quote = $this->checkoutSession->getQuote();
5868

5969
try {

app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ private function updateShippingAddress(Quote $quote, array $details)
123123
{
124124
$shippingAddress = $quote->getShippingAddress();
125125

126-
$shippingAddress->setLastname($details['lastName']);
127-
$shippingAddress->setFirstname($details['firstName']);
126+
$shippingAddress->setLastname($this->getShippingRecipientLastName($details));
127+
$shippingAddress->setFirstname($this->getShippingRecipientFirstName($details));
128128
$shippingAddress->setEmail($details['email']);
129129

130130
$shippingAddress->setCollectShippingRates(true);
@@ -188,4 +188,30 @@ private function updateAddressData(Address $address, array $addressData)
188188
$address->setSameAsBilling(false);
189189
$address->setCustomerAddressId(null);
190190
}
191+
192+
/**
193+
* Returns shipping recipient first name.
194+
*
195+
* @param array $details
196+
* @return string
197+
*/
198+
private function getShippingRecipientFirstName(array $details)
199+
{
200+
return isset($details['shippingAddress']['recipientName'])
201+
? explode(' ', $details['shippingAddress']['recipientName'], 2)[0]
202+
: $details['firstName'];
203+
}
204+
205+
/**
206+
* Returns shipping recipient last name.
207+
*
208+
* @param array $details
209+
* @return string
210+
*/
211+
private function getShippingRecipientLastName(array $details)
212+
{
213+
return isset($details['shippingAddress']['recipientName'])
214+
? explode(' ', $details['shippingAddress']['recipientName'], 2)[1]
215+
: $details['lastName'];
216+
}
191217
}

app/code/Magento/Braintree/Test/Unit/Controller/Paypal/ReviewTest.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Braintree\Test\Unit\Controller\Paypal;
77

8+
use Magento\Payment\Model\Method\Logger;
89
use Magento\Quote\Model\Quote;
910
use Magento\Framework\View\Layout;
1011
use Magento\Checkout\Model\Session;
@@ -63,6 +64,14 @@ class ReviewTest extends \PHPUnit\Framework\TestCase
6364
* @var Review
6465
*/
6566
private $review;
67+
/**
68+
* @var \PHPUnit_Framework_MockObject_MockObject
69+
*/
70+
71+
/**
72+
* @var Logger|\PHPUnit_Framework_MockObject_MockObject
73+
*/
74+
private $loggerMock;
6675

6776
protected function setUp()
6877
{
@@ -87,6 +96,9 @@ protected function setUp()
8796
->getMock();
8897
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
8998
->getMockForAbstractClass();
99+
$this->loggerMock = $this->getMockBuilder(Logger::class)
100+
->disableOriginalConstructor()
101+
->getMock();
90102

91103
$contextMock->expects(self::once())
92104
->method('getRequest')
@@ -102,7 +114,8 @@ protected function setUp()
102114
$contextMock,
103115
$this->configMock,
104116
$this->checkoutSessionMock,
105-
$this->quoteUpdaterMock
117+
$this->quoteUpdaterMock,
118+
$this->loggerMock
106119
);
107120
}
108121

app/code/Magento/Braintree/Test/Unit/Model/Paypal/Helper/QuoteUpdaterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private function getDetails(): array
165165
'region' => 'IL',
166166
'postalCode' => '60618',
167167
'countryCodeAlpha2' => 'US',
168-
'recipientName' => 'John Doe',
168+
'recipientName' => 'Jane Smith',
169169
],
170170
'billingAddress' => [
171171
'streetAddress' => '123 Billing Street',
@@ -186,9 +186,9 @@ private function getDetails(): array
186186
private function updateShippingAddressStep(array $details)
187187
{
188188
$this->shippingAddress->method('setLastname')
189-
->with($details['lastName']);
189+
->with('Smith');
190190
$this->shippingAddress->method('setFirstname')
191-
->with($details['firstName']);
191+
->with('Jane');
192192
$this->shippingAddress->method('setEmail')
193193
->with($details['email']);
194194
$this->shippingAddress->method('setCollectShippingRates')

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/CategoriesTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -155,38 +155,4 @@ public function modifyMetaLockedDataProvider()
155155
{
156156
return [[true], [false]];
157157
}
158-
159-
public function testModifyMetaWithCaching()
160-
{
161-
$this->arrayManagerMock->expects($this->exactly(2))
162-
->method('findPath')
163-
->willReturn(true);
164-
$cacheManager = $this->getMockBuilder(CacheInterface::class)
165-
->getMockForAbstractClass();
166-
$cacheManager->expects($this->once())
167-
->method('load')
168-
->with(Categories::CATEGORY_TREE_ID . '_');
169-
$cacheManager->expects($this->once())
170-
->method('save');
171-
172-
$modifier = $this->createModel();
173-
$cacheContextProperty = new \ReflectionProperty(
174-
Categories::class,
175-
'cacheManager'
176-
);
177-
$cacheContextProperty->setAccessible(true);
178-
$cacheContextProperty->setValue($modifier, $cacheManager);
179-
180-
$groupCode = 'test_group_code';
181-
$meta = [
182-
$groupCode => [
183-
'children' => [
184-
'category_ids' => [
185-
'sortOrder' => 10,
186-
],
187-
],
188-
],
189-
];
190-
$modifier->modifyMeta($meta);
191-
}
192158
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Categories.php

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;
79

810
use Magento\Catalog\Model\Locator\LocatorInterface;
@@ -11,6 +13,7 @@
1113
use Magento\Framework\App\CacheInterface;
1214
use Magento\Framework\DB\Helper as DbHelper;
1315
use Magento\Catalog\Model\Category as CategoryModel;
16+
use Magento\Framework\Exception\LocalizedException;
1417
use Magento\Framework\Serialize\SerializerInterface;
1518
use Magento\Framework\UrlInterface;
1619
use Magento\Framework\Stdlib\ArrayManager;
@@ -202,6 +205,7 @@ protected function createNewCategoryModal(array $meta)
202205
*
203206
* @param array $meta
204207
* @return array
208+
* @throws LocalizedException
205209
* @since 101.0.0
206210
*/
207211
protected function customizeCategoriesField(array $meta)
@@ -306,20 +310,64 @@ protected function customizeCategoriesField(array $meta)
306310
*
307311
* @param string|null $filter
308312
* @return array
313+
* @throws LocalizedException
309314
* @since 101.0.0
310315
*/
311316
protected function getCategoriesTree($filter = null)
312317
{
313-
$categoryTree = $this->getCacheManager()->load(self::CATEGORY_TREE_ID . '_' . $filter);
314-
if ($categoryTree) {
315-
return $this->serializer->unserialize($categoryTree);
318+
$storeId = (int) $this->locator->getStore()->getId();
319+
320+
$cachedCategoriesTree = $this->getCacheManager()
321+
->load($this->getCategoriesTreeCacheId($storeId, (string) $filter));
322+
if (!empty($cachedCategoriesTree)) {
323+
return $this->serializer->unserialize($cachedCategoriesTree);
316324
}
317325

318-
$storeId = $this->locator->getStore()->getId();
326+
$categoriesTree = $this->retrieveCategoriesTree(
327+
$storeId,
328+
$this->retrieveShownCategoriesIds($storeId, (string) $filter)
329+
);
330+
331+
$this->getCacheManager()->save(
332+
$this->serializer->serialize($categoriesTree),
333+
$this->getCategoriesTreeCacheId($storeId, (string) $filter),
334+
[
335+
\Magento\Catalog\Model\Category::CACHE_TAG,
336+
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
337+
]
338+
);
339+
340+
return $categoriesTree;
341+
}
342+
343+
/**
344+
* Get cache id for categories tree.
345+
*
346+
* @param int $storeId
347+
* @param string $filter
348+
* @return string
349+
*/
350+
private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : string
351+
{
352+
return self::CATEGORY_TREE_ID
353+
. '_' . (string) $storeId
354+
. '_' . $filter;
355+
}
356+
357+
/**
358+
* Retrieve filtered list of categories id.
359+
*
360+
* @param int $storeId
361+
* @param string $filter
362+
* @return array
363+
* @throws LocalizedException
364+
*/
365+
private function retrieveShownCategoriesIds(int $storeId, string $filter = '') : array
366+
{
319367
/* @var $matchingNamesCollection \Magento\Catalog\Model\ResourceModel\Category\Collection */
320368
$matchingNamesCollection = $this->categoryCollectionFactory->create();
321369

322-
if ($filter !== null) {
370+
if (!empty($filter)) {
323371
$matchingNamesCollection->addAttributeToFilter(
324372
'name',
325373
['like' => $this->dbHelper->addLikeEscape($filter, ['position' => 'any'])]
@@ -339,6 +387,19 @@ protected function getCategoriesTree($filter = null)
339387
}
340388
}
341389

390+
return $shownCategoriesIds;
391+
}
392+
393+
/**
394+
* Retrieve tree of categories with attributes.
395+
*
396+
* @param int $storeId
397+
* @param array $shownCategoriesIds
398+
* @return array|null
399+
* @throws LocalizedException
400+
*/
401+
private function retrieveCategoriesTree(int $storeId, array $shownCategoriesIds)
402+
{
342403
/* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
343404
$collection = $this->categoryCollectionFactory->create();
344405

@@ -365,15 +426,6 @@ protected function getCategoriesTree($filter = null)
365426
$categoryById[$category->getParentId()]['optgroup'][] = &$categoryById[$category->getId()];
366427
}
367428

368-
$this->getCacheManager()->save(
369-
$this->serializer->serialize($categoryById[CategoryModel::TREE_ROOT_ID]['optgroup']),
370-
self::CATEGORY_TREE_ID . '_' . $filter,
371-
[
372-
\Magento\Catalog\Model\Category::CACHE_TAG,
373-
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
374-
]
375-
);
376-
377429
return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
378430
}
379431
}

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,8 @@ protected function getProductUrlSuffix($storeId = null)
28382838
protected function getUrlKey($rowData)
28392839
{
28402840
if (!empty($rowData[self::URL_KEY])) {
2841-
return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
2841+
$urlKey = (string) $rowData[self::URL_KEY];
2842+
return trim(strtolower($urlKey));
28422843
}
28432844

28442845
if (!empty($rowData[self::COL_NAME])) {

0 commit comments

Comments
 (0)