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

Commit

Permalink
Merge pull request #4465 from magento-mpi/pr_2019_07_12
Browse files Browse the repository at this point in the history
[mpi] MAGETWO-98825: [Magento Cloud] When creating a new category, the Category Permissions are set to Deny by default
  • Loading branch information
viktym authored Jul 15, 2019
2 parents c8cbacc + 2f34965 commit fb58417
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 37 deletions.
17 changes: 16 additions & 1 deletion app/code/Magento/Braintree/Model/LocaleResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Magento\Framework\Locale\ResolverInterface;
use Magento\Braintree\Gateway\Config\PayPal\Config;

/**
* Resolves locale for PayPal Express.
*/
class LocaleResolver implements ResolverInterface
{
/**
Expand All @@ -20,6 +23,17 @@ class LocaleResolver implements ResolverInterface
*/
private $config;

/**
* Mapping Magento locales on PayPal locales.
*
* @var array
*/
private $localeMap = [
'zh_Hans_CN' => 'zh_CN',
'zh_Hant_HK' => 'zh_HK',
'zh_Hant_TW' => 'zh_TW'
];

/**
* @param ResolverInterface $resolver
* @param Config $config
Expand Down Expand Up @@ -66,10 +80,11 @@ public function setLocale($locale = null)
* Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal.
*
* @return string
* @see https://braintree.github.io/braintree-web/current/PayPalCheckout.html#createPayment
*/
public function getLocale()
{
$locale = $this->resolver->getLocale();
$locale = $this->localeMap[$this->resolver->getLocale()] ?? $this->resolver->getLocale();
$allowedLocales = $this->config->getValue('supported_locales');

return strpos($allowedLocales, $locale) !== false ? $locale : 'en_US';
Expand Down
34 changes: 25 additions & 9 deletions app/code/Magento/Braintree/Test/Unit/Model/LocaleResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,35 @@ public function testSetLocale()
/**
* Test getLocale method
*
* @return void
* @param string $locale
* @param string $expectedLocale
* @dataProvider getLocaleDataProvider
*/
public function testGetLocale()
public function testGetLocale(string $locale, string $expectedLocale)
{
$locale = 'en_TEST';
$allowedLocales = 'en_US,en_GB,en_AU,da_DK,fr_FR,fr_CA,de_DE,zh_HK,it_IT,nl_NL';
$this->resolverMock->expects($this->once())->method('getLocale')->willReturn($locale);
$this->configMock->expects($this->once())->method('getValue')->with('supported_locales')
$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';
$this->resolverMock->method('getLocale')
->willReturn($locale);
$this->configMock->method('getValue')
->with('supported_locales')
->willReturn($allowedLocales);

$expected = 'en_US';
$actual = $this->localeResolver->getLocale();
self::assertEquals($expected, $actual);

self::assertEquals($expectedLocale, $actual);
}

/**
* @return array
*/
public function getLocaleDataProvider(): array
{
return [
['locale' => 'zh_Hans_CN', 'expectedLocale' => 'zh_CN'],
['locale' => 'zh_Hant_HK', 'expectedLocale' => 'zh_HK'],
['locale' => 'zh_Hant_TW', 'expectedLocale' => 'zh_TW'],
['locale' => 'fr_FR', 'expectedLocale' => 'fr_FR'],
['locale' => 'unknown', 'expectedLocale' => 'en_US'],
];
}

/**
Expand Down
64 changes: 64 additions & 0 deletions app/code/Magento/Catalog/Model/Category/StoreCategories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Category;

use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Catalog\Model\Category;
use Magento\Store\Api\GroupRepositoryInterface;

/**
* Fetcher for associated with store group categories.
*/
class StoreCategories
{
/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var GroupRepositoryInterface
*/
private $groupRepository;

/**
* @param CategoryRepositoryInterface $categoryRepository
* @param GroupRepositoryInterface $groupRepository
*/
public function __construct(
CategoryRepositoryInterface $categoryRepository,
GroupRepositoryInterface $groupRepository
) {
$this->categoryRepository = $categoryRepository;
$this->groupRepository = $groupRepository;
}

/**
* Get all category ids for store.
*
* @param int|null $storeGroupId
* @return int[]
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function getCategoryIds(?int $storeGroupId = null): array
{
$rootCategoryId = $storeGroupId
? $this->groupRepository->get($storeGroupId)->getRootCategoryId()
: Category::TREE_ROOT_ID;
/** @var Category $rootCategory */
$rootCategory = $this->categoryRepository->get($rootCategoryId);
$categoriesIds = array_map(
function ($value) {
return (int) $value;
},
(array) $rootCategory->getAllChildren(true)
);

return $categoriesIds;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ protected function _prepareIndexTable($entityIds = null)
*/
protected function _updateIndex($entityIds)
{
$this->deleteOldRecords($entityIds);
$connection = $this->getConnection();
$select = $this->_getStockStatusSelect($entityIds, true);
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds, true);
Expand All @@ -314,14 +315,14 @@ protected function _updateIndex($entityIds)
}
}

$this->deleteOldRecords($entityIds);
$this->_updateIndexTable($data);

return $this;
}

/**
* Delete records by their ids from index table
*
* Used to clean table before re-indexation
*
* @param array $ids
Expand Down Expand Up @@ -366,6 +367,8 @@ public function getIdxTable($table = null)
}

/**
* Get status expression
*
* @param AdapterInterface $connection
* @param bool $isAggregate
* @return mixed
Expand All @@ -391,6 +394,8 @@ protected function getStatusExpression(AdapterInterface $connection, $isAggregat
}

/**
* Get stock configuration
*
* @return StockConfigurationInterface
*
* @deprecated 100.1.0
Expand All @@ -406,6 +411,8 @@ protected function getStockConfiguration()
}

/**
* Get query processor composite
*
* @return QueryProcessorComposite
*/
private function getQueryProcessorComposite()
Expand Down
20 changes: 11 additions & 9 deletions app/code/Magento/Config/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ private function getField(string $sectionId, string $groupId, string $fieldId):
*
* @param Field $field
* @param string $fieldId Need for support of clone_field feature
* @param array &$oldConfig Need for compatibility with _processGroup()
* @param array &$extraOldGroups Need for compatibility with _processGroup()
* @param array $oldConfig Need for compatibility with _processGroup()
* @param array $extraOldGroups Need for compatibility with _processGroup()
* @return string
*/
private function getFieldPath(Field $field, string $fieldId, array &$oldConfig, array &$extraOldGroups): string
Expand Down Expand Up @@ -337,8 +337,8 @@ private function isValueChanged(array $oldConfig, string $path, array $fieldData
* @param string $sectionId
* @param string $groupId
* @param array $groupData
* @param array &$oldConfig
* @param array &$extraOldGroups
* @param array $oldConfig
* @param array $extraOldGroups
* @return array
*/
private function getChangedPaths(
Expand Down Expand Up @@ -384,8 +384,8 @@ private function getChangedPaths(
* @param array $groupData
* @param array $groups
* @param string $sectionPath
* @param array &$extraOldGroups
* @param array &$oldConfig
* @param array $extraOldGroups
* @param array $oldConfig
* @param \Magento\Framework\DB\Transaction $saveTransaction
* @param \Magento\Framework\DB\Transaction $deleteTransaction
* @return void
Expand Down Expand Up @@ -546,6 +546,8 @@ public function setDataByPath($path, $value)
}

$section = array_shift($pathParts);
$this->setData('section', $section);

$data = [
'fields' => [
array_pop($pathParts) => ['value' => $value],
Expand All @@ -558,8 +560,8 @@ public function setDataByPath($path, $value)
],
];
}
$data['section'] = $section;
$this->addData($data);
$groups = array_replace_recursive((array) $this->getData('groups'), $data['groups']);
$this->setData('groups', $groups);
}

/**
Expand Down Expand Up @@ -679,7 +681,7 @@ protected function _checkSingleStoreMode(
* Get config data value
*
* @param string $path
* @param null|bool &$inherit
* @param null|bool $inherit
* @param null|array $configData
* @return \Magento\Framework\Simplexml\Element
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ define([
* {Function}
*/
setPaymentInformation: function () {
setPaymentInformationAction(
return setPaymentInformationAction(
this.messageContainer,
{
method: this.getCode()
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Paypal/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1511,6 +1511,7 @@ protected function _mapExpressFieldset($fieldName)
case 'allow_ba_signup':
case 'in_context':
case 'merchant_id':
case 'supported_locales':
return "payment/{$this->_methodCode}/{$fieldName}";
default:
return $this->_mapMethodFieldset($fieldName);
Expand Down
112 changes: 112 additions & 0 deletions app/code/Magento/Paypal/Model/Express/LocaleResolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Paypal\Model\Express;

use Magento\Framework\Locale\ResolverInterface;
use Magento\Paypal\Model\ConfigFactory;
use Magento\Paypal\Model\Config;

/**
* Resolves locale for PayPal Express.
*/
class LocaleResolver implements ResolverInterface
{
/**
* @var ResolverInterface
*/
private $resolver;

/**
* @var Config
*/
private $config;

/**
* Mapping Magento locales on PayPal locales.
*
* @var array
*/
private $localeMap = [
'zh_Hans_CN' => 'zh_CN',
'zh_Hant_HK' => 'zh_HK',
'zh_Hant_TW' => 'zh_TW'
];

/**
* @param ResolverInterface $resolver
* @param ConfigFactory $configFactory
*/
public function __construct(ResolverInterface $resolver, ConfigFactory $configFactory)
{
$this->resolver = $resolver;
$this->config = $configFactory->create();
$this->config->setMethod(Config::METHOD_EXPRESS);
}

/**
* @inheritdoc
*/
public function getDefaultLocalePath()
{
return $this->resolver->getDefaultLocalePath();
}

/**
* @inheritdoc
*/
public function setDefaultLocale($locale)
{
return $this->resolver->setDefaultLocale($locale);
}

/**
* @inheritdoc
*/
public function getDefaultLocale()
{
return $this->resolver->getDefaultLocale();
}

/**
* @inheritdoc
*/
public function setLocale($locale = null)
{
return $this->resolver->setLocale($locale);
}

/**
* Gets store's locale or the `en_US` locale if store's locale does not supported by PayPal.
*
* @return string
* @see https://developer.paypal.com/docs/api/reference/locale-codes/#supported-locale-codes
*/
public function getLocale(): string
{
$locale = $this->localeMap[$this->resolver->getLocale()] ?? $this->resolver->getLocale();
$allowedLocales = $this->config->getValue('supported_locales');

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

/**
* @inheritdoc
*/
public function emulate($scopeId)
{
return $this->resolver->emulate($scopeId);
}

/**
* @inheritdoc
*/
public function revert()
{
return $this->resolver->revert();
}
}
Loading

0 comments on commit fb58417

Please sign in to comment.