Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/2.2-develop' into MC-15874-2
Browse files Browse the repository at this point in the history
  • Loading branch information
Joan He committed Apr 22, 2019
2 parents 35ad602 + c52ee4a commit 05417ce
Show file tree
Hide file tree
Showing 27 changed files with 736 additions and 408 deletions.
12 changes: 11 additions & 1 deletion app/code/Magento/Braintree/Controller/Paypal/Review.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Braintree\Gateway\Config\PayPal\Config;
use Magento\Braintree\Model\Paypal\Helper\QuoteUpdater;
use Magento\Framework\Exception\LocalizedException;
use Magento\Payment\Model\Method\Logger;

/**
* Class Review
Expand All @@ -22,6 +23,11 @@ class Review extends AbstractAction
*/
private $quoteUpdater;

/**
* @var Logger
*/
private $logger;

/**
* @var string
*/
Expand All @@ -34,15 +40,18 @@ class Review extends AbstractAction
* @param Config $config
* @param Session $checkoutSession
* @param QuoteUpdater $quoteUpdater
* @param Logger $logger
*/
public function __construct(
Context $context,
Config $config,
Session $checkoutSession,
QuoteUpdater $quoteUpdater
QuoteUpdater $quoteUpdater,
Logger $logger
) {
parent::__construct($context, $config, $checkoutSession);
$this->quoteUpdater = $quoteUpdater;
$this->logger = $logger;
}

/**
Expand All @@ -54,6 +63,7 @@ public function execute()
$this->getRequest()->getPostValue('result', '{}'),
true
);
$this->logger->debug($requestData);
$quote = $this->checkoutSession->getQuote();

try {
Expand Down
30 changes: 28 additions & 2 deletions app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ private function updateShippingAddress(Quote $quote, array $details)
{
$shippingAddress = $quote->getShippingAddress();

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

$shippingAddress->setCollectShippingRates(true);
Expand Down Expand Up @@ -188,4 +188,30 @@ private function updateAddressData(Address $address, array $addressData)
$address->setSameAsBilling(false);
$address->setCustomerAddressId(null);
}

/**
* Returns shipping recipient first name.
*
* @param array $details
* @return string
*/
private function getShippingRecipientFirstName(array $details)
{
return isset($details['shippingAddress']['recipientName'])
? explode(' ', $details['shippingAddress']['recipientName'], 2)[0]
: $details['firstName'];
}

/**
* Returns shipping recipient last name.
*
* @param array $details
* @return string
*/
private function getShippingRecipientLastName(array $details)
{
return isset($details['shippingAddress']['recipientName'])
? explode(' ', $details['shippingAddress']['recipientName'], 2)[1]
: $details['lastName'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Braintree\Test\Unit\Controller\Paypal;

use Magento\Payment\Model\Method\Logger;
use Magento\Quote\Model\Quote;
use Magento\Framework\View\Layout;
use Magento\Checkout\Model\Session;
Expand Down Expand Up @@ -63,6 +64,14 @@ class ReviewTest extends \PHPUnit\Framework\TestCase
* @var Review
*/
private $review;
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/

/**
* @var Logger|\PHPUnit_Framework_MockObject_MockObject
*/
private $loggerMock;

protected function setUp()
{
Expand All @@ -87,6 +96,9 @@ protected function setUp()
->getMock();
$this->messageManagerMock = $this->getMockBuilder(ManagerInterface::class)
->getMockForAbstractClass();
$this->loggerMock = $this->getMockBuilder(Logger::class)
->disableOriginalConstructor()
->getMock();

$contextMock->expects(self::once())
->method('getRequest')
Expand All @@ -102,7 +114,8 @@ protected function setUp()
$contextMock,
$this->configMock,
$this->checkoutSessionMock,
$this->quoteUpdaterMock
$this->quoteUpdaterMock,
$this->loggerMock
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private function getDetails(): array
'region' => 'IL',
'postalCode' => '60618',
'countryCodeAlpha2' => 'US',
'recipientName' => 'John Doe',
'recipientName' => 'Jane Smith',
],
'billingAddress' => [
'streetAddress' => '123 Billing Street',
Expand All @@ -186,9 +186,9 @@ private function getDetails(): array
private function updateShippingAddressStep(array $details)
{
$this->shippingAddress->method('setLastname')
->with($details['lastName']);
->with('Smith');
$this->shippingAddress->method('setFirstname')
->with($details['firstName']);
->with('Jane');
$this->shippingAddress->method('setEmail')
->with($details['email']);
$this->shippingAddress->method('setCollectShippingRates')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,4 @@ public function modifyMetaLockedDataProvider()
{
return [[true], [false]];
}

public function testModifyMetaWithCaching()
{
$this->arrayManagerMock->expects($this->exactly(2))
->method('findPath')
->willReturn(true);
$cacheManager = $this->getMockBuilder(CacheInterface::class)
->getMockForAbstractClass();
$cacheManager->expects($this->once())
->method('load')
->with(Categories::CATEGORY_TREE_ID . '_');
$cacheManager->expects($this->once())
->method('save');

$modifier = $this->createModel();
$cacheContextProperty = new \ReflectionProperty(
Categories::class,
'cacheManager'
);
$cacheContextProperty->setAccessible(true);
$cacheContextProperty->setValue($modifier, $cacheManager);

$groupCode = 'test_group_code';
$meta = [
$groupCode => [
'children' => [
'category_ids' => [
'sortOrder' => 10,
],
],
],
];
$modifier->modifyMeta($meta);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Model\Locator\LocatorInterface;
Expand All @@ -11,6 +13,7 @@
use Magento\Framework\App\CacheInterface;
use Magento\Framework\DB\Helper as DbHelper;
use Magento\Catalog\Model\Category as CategoryModel;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Serialize\SerializerInterface;
use Magento\Framework\UrlInterface;
use Magento\Framework\Stdlib\ArrayManager;
Expand Down Expand Up @@ -202,6 +205,7 @@ protected function createNewCategoryModal(array $meta)
*
* @param array $meta
* @return array
* @throws LocalizedException
* @since 101.0.0
*/
protected function customizeCategoriesField(array $meta)
Expand Down Expand Up @@ -306,20 +310,64 @@ protected function customizeCategoriesField(array $meta)
*
* @param string|null $filter
* @return array
* @throws LocalizedException
* @since 101.0.0
*/
protected function getCategoriesTree($filter = null)
{
$categoryTree = $this->getCacheManager()->load(self::CATEGORY_TREE_ID . '_' . $filter);
if ($categoryTree) {
return $this->serializer->unserialize($categoryTree);
$storeId = (int) $this->locator->getStore()->getId();

$cachedCategoriesTree = $this->getCacheManager()
->load($this->getCategoriesTreeCacheId($storeId, (string) $filter));
if (!empty($cachedCategoriesTree)) {
return $this->serializer->unserialize($cachedCategoriesTree);
}

$storeId = $this->locator->getStore()->getId();
$categoriesTree = $this->retrieveCategoriesTree(
$storeId,
$this->retrieveShownCategoriesIds($storeId, (string) $filter)
);

$this->getCacheManager()->save(
$this->serializer->serialize($categoriesTree),
$this->getCategoriesTreeCacheId($storeId, (string) $filter),
[
\Magento\Catalog\Model\Category::CACHE_TAG,
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
]
);

return $categoriesTree;
}

/**
* Get cache id for categories tree.
*
* @param int $storeId
* @param string $filter
* @return string
*/
private function getCategoriesTreeCacheId(int $storeId, string $filter = '') : string
{
return self::CATEGORY_TREE_ID
. '_' . (string) $storeId
. '_' . $filter;
}

/**
* Retrieve filtered list of categories id.
*
* @param int $storeId
* @param string $filter
* @return array
* @throws LocalizedException
*/
private function retrieveShownCategoriesIds(int $storeId, string $filter = '') : array
{
/* @var $matchingNamesCollection \Magento\Catalog\Model\ResourceModel\Category\Collection */
$matchingNamesCollection = $this->categoryCollectionFactory->create();

if ($filter !== null) {
if (!empty($filter)) {
$matchingNamesCollection->addAttributeToFilter(
'name',
['like' => $this->dbHelper->addLikeEscape($filter, ['position' => 'any'])]
Expand All @@ -339,6 +387,19 @@ protected function getCategoriesTree($filter = null)
}
}

return $shownCategoriesIds;
}

/**
* Retrieve tree of categories with attributes.
*
* @param int $storeId
* @param array $shownCategoriesIds
* @return array|null
* @throws LocalizedException
*/
private function retrieveCategoriesTree(int $storeId, array $shownCategoriesIds)
{
/* @var $collection \Magento\Catalog\Model\ResourceModel\Category\Collection */
$collection = $this->categoryCollectionFactory->create();

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

$this->getCacheManager()->save(
$this->serializer->serialize($categoryById[CategoryModel::TREE_ROOT_ID]['optgroup']),
self::CATEGORY_TREE_ID . '_' . $filter,
[
\Magento\Catalog\Model\Category::CACHE_TAG,
\Magento\Framework\App\Cache\Type\Block::CACHE_TAG
]
);

return $categoryById[CategoryModel::TREE_ROOT_ID]['optgroup'];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2838,7 +2838,8 @@ protected function getProductUrlSuffix($storeId = null)
protected function getUrlKey($rowData)
{
if (!empty($rowData[self::URL_KEY])) {
return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
$urlKey = (string) $rowData[self::URL_KEY];
return trim(strtolower($urlKey));
}

if (!empty($rowData[self::COL_NAME])) {
Expand Down
Loading

0 comments on commit 05417ce

Please sign in to comment.