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

Commit

Permalink
Merge remote-tracking branch 'mainline/2.3-develop' into fix-incorrec…
Browse files Browse the repository at this point in the history
…t-signature
  • Loading branch information
TomashKhamlai committed Oct 12, 2019
2 parents 35b37c0 + e023220 commit 26b0821
Show file tree
Hide file tree
Showing 101 changed files with 2,815 additions and 480 deletions.
590 changes: 340 additions & 250 deletions app/code/Magento/Authorizenet/Test/Unit/Model/DirectpostTest.php

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions app/code/Magento/Backend/Model/Locale/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

/**
* Backend locale model
*
* @api
* @since 100.0.2
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class Resolver extends \Magento\Framework\Locale\Resolver
{
Expand Down Expand Up @@ -40,7 +42,7 @@ class Resolver extends \Magento\Framework\Locale\Resolver
* @param Manager $localeManager
* @param \Magento\Framework\App\RequestInterface $request
* @param \Magento\Framework\Validator\Locale $localeValidator
* @param null $locale
* @param string|null $locale
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand Down Expand Up @@ -76,7 +78,7 @@ public function setLocale($locale = null)
$sessionLocale = $this->_session->getSessionLocale();
$userLocale = $this->_localeManager->getUserInterfaceLocale();

$localeCodes = array_filter([$forceLocale, $sessionLocale, $userLocale]);
$localeCodes = array_filter([$forceLocale, $locale, $sessionLocale, $userLocale]);

if (count($localeCodes)) {
$locale = reset($localeCodes);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
<entity name="AdminGeneralSetStoreNameConfigData">
<data key="path">general/store_information/name</data>
<data key="value">New Store Information</data>
</entity>
<entity name="AdminGeneralSetStorePhoneConfigData">
<data key="path">general/store_information/phone</data>
</entity>
<entity name="AdminGeneralSetCountryConfigData">
<data key="path">general/store_information/country_id</data>
</entity>
<entity name="AdminGeneralSetCityConfigData">
<data key="path">general/store_information/city</data>
</entity>
<entity name="AdminGeneralSetPostcodeConfigData">
<data key="path">general/store_information/postcode</data>
</entity>
<entity name="AdminGeneralSetStreetAddressConfigData">
<data key="path">general/store_information/street_line1</data>
</entity>
<entity name="AdminGeneralSetStreetAddress2ConfigData">
<data key="path">general/store_information/street_line2</data>
</entity>
</entities>
55 changes: 44 additions & 11 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
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\Model\Category;

use Magento\Catalog\Api\Data\CategoryInterface;
Expand All @@ -20,6 +22,7 @@
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Framework\Stdlib\ArrayUtils;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Form\Field;
Expand All @@ -28,10 +31,9 @@
use Magento\Framework\AuthorizationInterface;

/**
* Class DataProvider
* Category form data provider.
*
* @api
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.TooManyFields)
* @since 101.0.0
Expand All @@ -52,6 +54,7 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider

/**
* EAV attribute properties to fetch from meta storage
*
* @var array
* @since 101.0.0
*/
Expand Down Expand Up @@ -143,6 +146,11 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
*/
private $arrayManager;

/**
* @var ArrayUtils
*/
private $arrayUtils;

/**
* @var Filesystem
*/
Expand All @@ -154,8 +162,6 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
private $auth;

/**
* DataProvider constructor
*
* @param string $name
* @param string $primaryFieldName
* @param string $requestFieldName
Expand All @@ -170,6 +176,8 @@ class DataProvider extends \Magento\Ui\DataProvider\ModifierPoolDataProvider
* @param array $data
* @param PoolInterface|null $pool
* @param AuthorizationInterface|null $auth
* @param ArrayUtils|null $arrayUtils
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -186,7 +194,8 @@ public function __construct(
array $meta = [],
array $data = [],
PoolInterface $pool = null,
?AuthorizationInterface $auth = null
?AuthorizationInterface $auth = null,
?ArrayUtils $arrayUtils = null
) {
$this->eavValidationRules = $eavValidationRules;
$this->collection = $categoryCollectionFactory->create();
Expand All @@ -197,6 +206,7 @@ public function __construct(
$this->request = $request;
$this->categoryFactory = $categoryFactory;
$this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class);
$this->arrayUtils = $arrayUtils ?? ObjectManager::getInstance()->get(ArrayUtils::class);

parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data, $pool);
}
Expand Down Expand Up @@ -226,7 +236,7 @@ public function getMeta()
* @param array $meta
* @return array
*/
private function addUseDefaultValueCheckbox(Category $category, array $meta)
private function addUseDefaultValueCheckbox(Category $category, array $meta): array
{
/** @var EavAttributeInterface $attribute */
foreach ($category->getAttributes() as $attribute) {
Expand Down Expand Up @@ -290,7 +300,7 @@ public function prepareMeta($meta)
* @param array $fieldsMeta
* @return array
*/
private function prepareFieldsMeta($fieldsMap, $fieldsMeta)
private function prepareFieldsMeta(array $fieldsMap, array $fieldsMeta): array
{
$canEditDesign = $this->auth->isAllowed('Magento_Catalog::edit_category_design');

Expand Down Expand Up @@ -350,6 +360,8 @@ public function getAttributesMeta(Type $entityType)
{
$meta = [];
$attributes = $entityType->getAttributeCollection();
$fields = $this->getFields();
$category = $this->getCurrentCategory();
/* @var EavAttribute $attribute */
foreach ($attributes as $attribute) {
$code = $attribute->getAttributeCode();
Expand All @@ -374,6 +386,16 @@ public function getAttributesMeta(Type $entityType)

$meta[$code]['scopeLabel'] = $this->getScopeLabel($attribute);
$meta[$code]['componentType'] = Field::NAME;

// disable fields
if ($category) {
$attributeIsLocked = $category->isLockedAttribute($code);
$meta[$code]['disabled'] = $attributeIsLocked;
$hasUseConfigField = (bool) array_search('use_config.' . $code, $fields, true);
if ($hasUseConfigField && $meta[$code]['disabled']) {
$meta['use_config.' . $code]['disabled'] = true;
}
}
}

$result = [];
Expand Down Expand Up @@ -505,7 +527,7 @@ protected function filterFields($categoryData)
* @param array $categoryData
* @return array
*/
private function convertValues($category, $categoryData)
private function convertValues($category, $categoryData): array
{
foreach ($category->getAttributes() as $attributeCode => $attribute) {
if (!isset($categoryData[$attributeCode])) {
Expand Down Expand Up @@ -616,13 +638,24 @@ protected function getFieldsMap()
];
}

/**
* Return list of fields names.
*
* @return array
*/
private function getFields(): array
{
$fieldsMap = $this->getFieldsMap();
return $this->arrayUtils->flatten($fieldsMap);
}

/**
* Retrieve scope overridden value
*
* @return ScopeOverriddenValue
* @deprecated 101.1.0
*/
private function getScopeOverriddenValue()
private function getScopeOverriddenValue(): ScopeOverriddenValue
{
if (null === $this->scopeOverriddenValue) {
$this->scopeOverriddenValue = \Magento\Framework\App\ObjectManager::getInstance()->get(
Expand All @@ -639,7 +672,7 @@ private function getScopeOverriddenValue()
* @return ArrayManager
* @deprecated 101.1.0
*/
private function getArrayManager()
private function getArrayManager(): ArrayManager
{
if (null === $this->arrayManager) {
$this->arrayManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
Expand All @@ -657,7 +690,7 @@ private function getArrayManager()
*
* @deprecated 101.1.0
*/
private function getFileInfo()
private function getFileInfo(): FileInfo
{
if ($this->fileInfo === null) {
$this->fileInfo = ObjectManager::getInstance()->get(FileInfo::class);
Expand Down
71 changes: 70 additions & 1 deletion app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product\Gallery;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\EntityManager\Operation\ExtensionInterface;
use Magento\MediaStorage\Model\File\Uploader as FileUploader;
use Magento\Store\Model\StoreManagerInterface;

/**
* Create handler for catalog product gallery
Expand Down Expand Up @@ -74,6 +79,16 @@ class CreateHandler implements ExtensionInterface
*/
private $mediaAttributeCodes;

/**
* @var array
*/
private $imagesGallery;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $storeManager;

/**
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param \Magento\Catalog\Api\ProductAttributeRepositoryInterface $attributeRepository
Expand All @@ -82,6 +97,8 @@ class CreateHandler implements ExtensionInterface
* @param \Magento\Catalog\Model\Product\Media\Config $mediaConfig
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
* @param \Magento\Store\Model\StoreManagerInterface|null $storeManager
* @throws \Magento\Framework\Exception\FileSystemException
*/
public function __construct(
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
Expand All @@ -90,7 +107,8 @@ public function __construct(
\Magento\Framework\Json\Helper\Data $jsonHelper,
\Magento\Catalog\Model\Product\Media\Config $mediaConfig,
\Magento\Framework\Filesystem $filesystem,
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb
\Magento\MediaStorage\Helper\File\Storage\Database $fileStorageDb,
\Magento\Store\Model\StoreManagerInterface $storeManager = null
) {
$this->metadata = $metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
$this->attributeRepository = $attributeRepository;
Expand All @@ -99,6 +117,7 @@ public function __construct(
$this->mediaConfig = $mediaConfig;
$this->mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$this->fileStorageDb = $fileStorageDb;
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
}

/**
Expand Down Expand Up @@ -137,6 +156,10 @@ public function execute($product, $arguments = [])

if ($product->getIsDuplicate() != true) {
foreach ($value['images'] as &$image) {
if (!empty($image['removed']) && !$this->canRemoveImage($product, $image['file'])) {
$image['removed'] = '';
}

if (!empty($image['removed'])) {
$clearImages[] = $image['file'];
} elseif (empty($image['value_id'])) {
Expand All @@ -152,6 +175,10 @@ public function execute($product, $arguments = [])
// For duplicating we need copy original images.
$duplicate = [];
foreach ($value['images'] as &$image) {
if (!empty($image['removed']) && !$this->canRemoveImage($product, $image['file'])) {
$image['removed'] = '';
}

if (empty($image['value_id']) || !empty($image['removed'])) {
continue;
}
Expand Down Expand Up @@ -538,4 +565,46 @@ private function processMediaAttributeLabel(
);
}
}

/**
* Get product images for all stores
*
* @param ProductInterface $product
* @return array
*/
private function getImagesForAllStores(ProductInterface $product)
{
if ($this->imagesGallery === null) {
$storeIds = array_keys($this->storeManager->getStores());
$storeIds[] = 0;

$this->imagesGallery = $this->resourceModel->getProductImages($product, $storeIds);
}

return $this->imagesGallery;
}

/**
* Check possibility to remove image
*
* @param ProductInterface $product
* @param string $imageFile
* @return bool
*/
private function canRemoveImage(ProductInterface $product, string $imageFile) :bool
{
$canRemoveImage = true;
$gallery = $this->getImagesForAllStores($product);
$storeId = $product->getStoreId();

if (!empty($gallery)) {
foreach ($gallery as $image) {
if ($image['filepath'] === $imageFile && (int) $image['store_id'] !== $storeId) {
$canRemoveImage = false;
}
}
}

return $canRemoveImage;
}
}
Loading

0 comments on commit 26b0821

Please sign in to comment.