Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit fb58417

Browse files
authored
Merge pull request #4465 from magento-mpi/pr_2019_07_12
[mpi] MAGETWO-98825: [Magento Cloud] When creating a new category, the Category Permissions are set to Deny by default
2 parents c8cbacc + 2f34965 commit fb58417

File tree

15 files changed

+354
-37
lines changed

15 files changed

+354
-37
lines changed

app/code/Magento/Braintree/Model/LocaleResolver.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Framework\Locale\ResolverInterface;
99
use Magento\Braintree\Gateway\Config\PayPal\Config;
1010

11+
/**
12+
* Resolves locale for PayPal Express.
13+
*/
1114
class LocaleResolver implements ResolverInterface
1215
{
1316
/**
@@ -20,6 +23,17 @@ class LocaleResolver implements ResolverInterface
2023
*/
2124
private $config;
2225

26+
/**
27+
* Mapping Magento locales on PayPal locales.
28+
*
29+
* @var array
30+
*/
31+
private $localeMap = [
32+
'zh_Hans_CN' => 'zh_CN',
33+
'zh_Hant_HK' => 'zh_HK',
34+
'zh_Hant_TW' => 'zh_TW'
35+
];
36+
2337
/**
2438
* @param ResolverInterface $resolver
2539
* @param Config $config
@@ -66,10 +80,11 @@ public function setLocale($locale = null)
6680
* Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal.
6781
*
6882
* @return string
83+
* @see https://braintree.github.io/braintree-web/current/PayPalCheckout.html#createPayment
6984
*/
7085
public function getLocale()
7186
{
72-
$locale = $this->resolver->getLocale();
87+
$locale = $this->localeMap[$this->resolver->getLocale()] ?? $this->resolver->getLocale();
7388
$allowedLocales = $this->config->getValue('supported_locales');
7489

7590
return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US';

app/code/Magento/Braintree/Test/Unit/Model/LocaleResolverTest.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,35 @@ public function testSetLocale()
9898
/**
9999
* Test getLocale method
100100
*
101-
* @return void
101+
* @param string $locale
102+
* @param string $expectedLocale
103+
* @dataProvider getLocaleDataProvider
102104
*/
103-
public function testGetLocale()
105+
public function testGetLocale(string $locale, string $expectedLocale)
104106
{
105-
$locale = 'en_TEST';
106-
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL';
107-
$this->resolverMock->expects($this->once())->method('getLocale')->willReturn($locale);
108-
$this->configMock->expects($this->once())->method('getValue')->with('supported_locales')
107+
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,zh_CN,zh_TW,nl_NL';
108+
$this->resolverMock->method('getLocale')
109+
->willReturn($locale);
110+
$this->configMock->method('getValue')
111+
->with('supported_locales')
109112
->willReturn($allowedLocales);
110-
111-
$expected = 'en_US';
112113
$actual = $this->localeResolver->getLocale();
113-
self::assertEquals($expected, $actual);
114+
115+
self::assertEquals($expectedLocale, $actual);
116+
}
117+
118+
/**
119+
* @return array
120+
*/
121+
public function getLocaleDataProvider(): array
122+
{
123+
return [
124+
['locale' => 'zh_Hans_CN', 'expectedLocale' => 'zh_CN'],
125+
['locale' => 'zh_Hant_HK', 'expectedLocale' => 'zh_HK'],
126+
['locale' => 'zh_Hant_TW', 'expectedLocale' => 'zh_TW'],
127+
['locale' => 'fr_FR', 'expectedLocale' => 'fr_FR'],
128+
['locale' => 'unknown', 'expectedLocale' => 'en_US'],
129+
];
114130
}
115131

116132
/**
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\Category;
9+
10+
use Magento\Catalog\Api\CategoryRepositoryInterface;
11+
use Magento\Catalog\Model\Category;
12+
use Magento\Store\Api\GroupRepositoryInterface;
13+
14+
/**
15+
* Fetcher for associated with store group categories.
16+
*/
17+
class StoreCategories
18+
{
19+
/**
20+
* @var CategoryRepositoryInterface
21+
*/
22+
private $categoryRepository;
23+
24+
/**
25+
* @var GroupRepositoryInterface
26+
*/
27+
private $groupRepository;
28+
29+
/**
30+
* @param CategoryRepositoryInterface $categoryRepository
31+
* @param GroupRepositoryInterface $groupRepository
32+
*/
33+
public function __construct(
34+
CategoryRepositoryInterface $categoryRepository,
35+
GroupRepositoryInterface $groupRepository
36+
) {
37+
$this->categoryRepository = $categoryRepository;
38+
$this->groupRepository = $groupRepository;
39+
}
40+
41+
/**
42+
* Get all category ids for store.
43+
*
44+
* @param int|null $storeGroupId
45+
* @return int[]
46+
* @throws \Magento\Framework\Exception\NoSuchEntityException
47+
*/
48+
public function getCategoryIds(?int $storeGroupId = null): array
49+
{
50+
$rootCategoryId = $storeGroupId
51+
? $this->groupRepository->get($storeGroupId)->getRootCategoryId()
52+
: Category::TREE_ROOT_ID;
53+
/** @var Category $rootCategory */
54+
$rootCategory = $this->categoryRepository->get($rootCategoryId);
55+
$categoriesIds = array_map(
56+
function ($value) {
57+
return (int) $value;
58+
},
59+
(array) $rootCategory->getAllChildren(true)
60+
);
61+
62+
return $categoriesIds;
63+
}
64+
}

app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ protected function _prepareIndexTable($entityIds = null)
292292
*/
293293
protected function _updateIndex($entityIds)
294294
{
295+
$this->deleteOldRecords($entityIds);
295296
$connection = $this->getConnection();
296297
$select = $this->_getStockStatusSelect($entityIds, true);
297298
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds, true);
@@ -314,14 +315,14 @@ protected function _updateIndex($entityIds)
314315
}
315316
}
316317

317-
$this->deleteOldRecords($entityIds);
318318
$this->_updateIndexTable($data);
319319

320320
return $this;
321321
}
322322

323323
/**
324324
* Delete records by their ids from index table
325+
*
325326
* Used to clean table before re-indexation
326327
*
327328
* @param array $ids
@@ -366,6 +367,8 @@ public function getIdxTable($table = null)
366367
}
367368

368369
/**
370+
* Get status expression
371+
*
369372
* @param AdapterInterface $connection
370373
* @param bool $isAggregate
371374
* @return mixed
@@ -391,6 +394,8 @@ protected function getStatusExpression(AdapterInterface $connection, $isAggregat
391394
}
392395

393396
/**
397+
* Get stock configuration
398+
*
394399
* @return StockConfigurationInterface
395400
*
396401
* @deprecated 100.1.0
@@ -406,6 +411,8 @@ protected function getStockConfiguration()
406411
}
407412

408413
/**
414+
* Get query processor composite
415+
*
409416
* @return QueryProcessorComposite
410417
*/
411418
private function getQueryProcessorComposite()

app/code/Magento/Config/Model/Config.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ private function getField(string $sectionId, string $groupId, string $fieldId):
287287
*
288288
* @param Field $field
289289
* @param string $fieldId Need for support of clone_field feature
290-
* @param array &$oldConfig Need for compatibility with _processGroup()
291-
* @param array &$extraOldGroups Need for compatibility with _processGroup()
290+
* @param array $oldConfig Need for compatibility with _processGroup()
291+
* @param array $extraOldGroups Need for compatibility with _processGroup()
292292
* @return string
293293
*/
294294
private function getFieldPath(Field $field, string $fieldId, array &$oldConfig, array &$extraOldGroups): string
@@ -337,8 +337,8 @@ private function isValueChanged(array $oldConfig, string $path, array $fieldData
337337
* @param string $sectionId
338338
* @param string $groupId
339339
* @param array $groupData
340-
* @param array &$oldConfig
341-
* @param array &$extraOldGroups
340+
* @param array $oldConfig
341+
* @param array $extraOldGroups
342342
* @return array
343343
*/
344344
private function getChangedPaths(
@@ -384,8 +384,8 @@ private function getChangedPaths(
384384
* @param array $groupData
385385
* @param array $groups
386386
* @param string $sectionPath
387-
* @param array &$extraOldGroups
388-
* @param array &$oldConfig
387+
* @param array $extraOldGroups
388+
* @param array $oldConfig
389389
* @param \Magento\Framework\DB\Transaction $saveTransaction
390390
* @param \Magento\Framework\DB\Transaction $deleteTransaction
391391
* @return void
@@ -546,6 +546,8 @@ public function setDataByPath($path, $value)
546546
}
547547

548548
$section = array_shift($pathParts);
549+
$this->setData('section', $section);
550+
549551
$data = [
550552
'fields' => [
551553
array_pop($pathParts) => ['value' => $value],
@@ -558,8 +560,8 @@ public function setDataByPath($path, $value)
558560
],
559561
];
560562
}
561-
$data['section'] = $section;
562-
$this->addData($data);
563+
$groups = array_replace_recursive((array) $this->getData('groups'), $data['groups']);
564+
$this->setData('groups', $groups);
563565
}
564566

565567
/**
@@ -679,7 +681,7 @@ protected function _checkSingleStoreMode(
679681
* Get config data value
680682
*
681683
* @param string $path
682-
* @param null|bool &$inherit
684+
* @param null|bool $inherit
683685
* @param null|array $configData
684686
* @return \Magento\Framework\Simplexml\Element
685687
*/

app/code/Magento/Payment/view/frontend/web/js/view/payment/iframe.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ define([
144144
* {Function}
145145
*/
146146
setPaymentInformation: function () {
147-
setPaymentInformationAction(
147+
return setPaymentInformationAction(
148148
this.messageContainer,
149149
{
150150
method: this.getCode()

app/code/Magento/Paypal/Model/Config.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,7 @@ protected function _mapExpressFieldset($fieldName)
15111511
case 'allow_ba_signup':
15121512
case 'in_context':
15131513
case 'merchant_id':
1514+
case 'supported_locales':
15141515
return "payment/{$this->_methodCode}/{$fieldName}";
15151516
default:
15161517
return $this->_mapMethodFieldset($fieldName);
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Model\Express;
9+
10+
use Magento\Framework\Locale\ResolverInterface;
11+
use Magento\Paypal\Model\ConfigFactory;
12+
use Magento\Paypal\Model\Config;
13+
14+
/**
15+
* Resolves locale for PayPal Express.
16+
*/
17+
class LocaleResolver implements ResolverInterface
18+
{
19+
/**
20+
* @var ResolverInterface
21+
*/
22+
private $resolver;
23+
24+
/**
25+
* @var Config
26+
*/
27+
private $config;
28+
29+
/**
30+
* Mapping Magento locales on PayPal locales.
31+
*
32+
* @var array
33+
*/
34+
private $localeMap = [
35+
'zh_Hans_CN' => 'zh_CN',
36+
'zh_Hant_HK' => 'zh_HK',
37+
'zh_Hant_TW' => 'zh_TW'
38+
];
39+
40+
/**
41+
* @param ResolverInterface $resolver
42+
* @param ConfigFactory $configFactory
43+
*/
44+
public function __construct(ResolverInterface $resolver, ConfigFactory $configFactory)
45+
{
46+
$this->resolver = $resolver;
47+
$this->config = $configFactory->create();
48+
$this->config->setMethod(Config::METHOD_EXPRESS);
49+
}
50+
51+
/**
52+
* @inheritdoc
53+
*/
54+
public function getDefaultLocalePath()
55+
{
56+
return $this->resolver->getDefaultLocalePath();
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function setDefaultLocale($locale)
63+
{
64+
return $this->resolver->setDefaultLocale($locale);
65+
}
66+
67+
/**
68+
* @inheritdoc
69+
*/
70+
public function getDefaultLocale()
71+
{
72+
return $this->resolver->getDefaultLocale();
73+
}
74+
75+
/**
76+
* @inheritdoc
77+
*/
78+
public function setLocale($locale = null)
79+
{
80+
return $this->resolver->setLocale($locale);
81+
}
82+
83+
/**
84+
* Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal.
85+
*
86+
* @return string
87+
* @see https://developer.paypal.com/docs/api/reference/locale-codes/#supported-locale-codes
88+
*/
89+
public function getLocale(): string
90+
{
91+
$locale = $this->localeMap[$this->resolver->getLocale()] ?? $this->resolver->getLocale();
92+
$allowedLocales = $this->config->getValue('supported_locales');
93+
94+
return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US';
95+
}
96+
97+
/**
98+
* @inheritdoc
99+
*/
100+
public function emulate($scopeId)
101+
{
102+
return $this->resolver->emulate($scopeId);
103+
}
104+
105+
/**
106+
* @inheritdoc
107+
*/
108+
public function revert()
109+
{
110+
return $this->resolver->revert();
111+
}
112+
}

0 commit comments

Comments
 (0)