Skip to content

Commit 6469d03

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents e23601e + b85552f commit 6469d03

File tree

8 files changed

+303
-56
lines changed

8 files changed

+303
-56
lines changed

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\App\Action\HttpPostActionInterface;
1616
use Magento\Framework\App\Action\HttpGetActionInterface;
17+
use Magento\Payment\Model\Method\Logger;
1718

1819
/**
1920
* Class Review
@@ -25,6 +26,11 @@ class Review extends AbstractAction implements HttpPostActionInterface, HttpGetA
2526
*/
2627
private $quoteUpdater;
2728

29+
/**
30+
* @var Logger
31+
*/
32+
private $logger;
33+
2834
/**
2935
* @var string
3036
*/
@@ -37,15 +43,18 @@ class Review extends AbstractAction implements HttpPostActionInterface, HttpGetA
3743
* @param Config $config
3844
* @param Session $checkoutSession
3945
* @param QuoteUpdater $quoteUpdater
46+
* @param Logger $logger
4047
*/
4148
public function __construct(
4249
Context $context,
4350
Config $config,
4451
Session $checkoutSession,
45-
QuoteUpdater $quoteUpdater
52+
QuoteUpdater $quoteUpdater,
53+
Logger $logger
4654
) {
4755
parent::__construct($context, $config, $checkoutSession);
4856
$this->quoteUpdater = $quoteUpdater;
57+
$this->logger = $logger;
4958
}
5059

5160
/**
@@ -57,6 +66,7 @@ public function execute()
5766
$this->getRequest()->getPostValue('result', '{}'),
5867
true
5968
);
69+
$this->logger->debug($requestData);
6070
$quote = $this->checkoutSession->getQuote();
6171

6272
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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace Magento\Braintree\Test\Unit\Controller\Paypal;
88

9+
use Magento\Payment\Model\Method\Logger;
910
use Magento\Quote\Model\Quote;
1011
use Magento\Framework\View\Layout;
1112
use Magento\Checkout\Model\Session;
@@ -65,6 +66,11 @@ class ReviewTest extends \PHPUnit\Framework\TestCase
6566
*/
6667
private $review;
6768

69+
/**
70+
* @var Logger|\PHPUnit_Framework_MockObject_MockObject
71+
*/
72+
private $loggerMock;
73+
6874
protected function setUp()
6975
{
7076
/** @var Context|\PHPUnit_Framework_MockObject_MockObject $contextMock */
@@ -88,6 +94,9 @@ protected function setUp()
8894
->getMock();
8995
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
9096
->getMockForAbstractClass();
97+
$this->loggerMock = $this->getMockBuilder(Logger::class)
98+
->disableOriginalConstructor()
99+
->getMock();
91100

92101
$contextMock->expects(self::once())
93102
->method('getRequest')
@@ -103,7 +112,8 @@ protected function setUp()
103112
$contextMock,
104113
$this->configMock,
105114
$this->checkoutSessionMock,
106-
$this->quoteUpdaterMock
115+
$this->quoteUpdaterMock,
116+
$this->loggerMock
107117
);
108118
}
109119

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): void
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
@@ -154,38 +154,4 @@ public function modifyMetaLockedDataProvider()
154154
{
155155
return [[true], [false]];
156156
}
157-
158-
public function testModifyMetaWithCaching()
159-
{
160-
$this->arrayManagerMock->expects($this->exactly(2))
161-
->method('findPath')
162-
->willReturn(true);
163-
$cacheManager = $this->getMockBuilder(CacheInterface::class)
164-
->getMockForAbstractClass();
165-
$cacheManager->expects($this->once())
166-
->method('load')
167-
->with(Categories::CATEGORY_TREE_ID . '_');
168-
$cacheManager->expects($this->once())
169-
->method('save');
170-
171-
$modifier = $this->createModel();
172-
$cacheContextProperty = new \ReflectionProperty(
173-
Categories::class,
174-
'cacheManager'
175-
);
176-
$cacheContextProperty->setAccessible(true);
177-
$cacheContextProperty->setValue($modifier, $cacheManager);
178-
179-
$groupCode = 'test_group_code';
180-
$meta = [
181-
$groupCode => [
182-
'children' => [
183-
'category_ids' => [
184-
'sortOrder' => 10,
185-
],
186-
],
187-
],
188-
];
189-
$modifier->modifyMeta($meta);
190-
}
191157
}

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) : ?array
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
}

0 commit comments

Comments
 (0)