Skip to content

Commit

Permalink
merge magento/2.4-develop into magento-trigger/MC-13825
Browse files Browse the repository at this point in the history
  • Loading branch information
magento-mts-svc authored Mar 24, 2020
2 parents 5482cdf + 70cf0c2 commit b26e6c9
Show file tree
Hide file tree
Showing 29 changed files with 945 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;

/**
* Update catalog_product_index_price table after delete or save customer group
*/
class CustomerGroup
{
/**
Expand Down Expand Up @@ -80,7 +83,7 @@ public function aroundSave(
\Closure $proceed,
GroupInterface $group
) {
$isGroupNew = !$group->getId();
$isGroupNew = $group->getId() === null;
$group = $proceed($group);
if ($isGroupNew) {
foreach ($this->getAffectedDimensions((string)$group->getId()) as $dimensions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model\Indexer\Product\Price\Plugin;

use Magento\Catalog\Model\Indexer\Product\Price\DimensionModeConfiguration;
use Magento\Catalog\Model\Indexer\Product\Price\Plugin\CustomerGroup;
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
use Magento\Customer\Api\GroupRepositoryInterface;
use Magento\Customer\Model\Data\Group;
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
use Magento\Framework\Indexer\DimensionFactory;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;

/**
* Test for CustomerGroup plugin
*/
class CustomerGroupTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManager
*/
private $objectManager;

/**
* @var CustomerGroup
*/
private $model;

/**
* @var DimensionFactory|MockObject
*/
private $dimensionFactory;

/**
* @var TableMaintainer|MockObject
*/
private $tableMaintainerMock;

/**
* @var DimensionModeConfiguration|MockObject
*/
private $dimensionModeConfiguration;

/**
* @var \Callable
*/
private $proceedMock;

protected function setUp()
{
$this->objectManager = new ObjectManager($this);

$this->dimensionFactory = $this->createPartialMock(
DimensionFactory::class,
['create']
);

$this->dimensionModeConfiguration = $this->createPartialMock(
DimensionModeConfiguration::class,
['getDimensionConfiguration']
);

$this->tableMaintainerMock = $this->createPartialMock(
TableMaintainer::class,
['createTablesForDimensions']
);

$this->model = $this->objectManager->getObject(
CustomerGroup::class,
[
'dimensionFactory' => $this->dimensionFactory,
'dimensionModeConfiguration' => $this->dimensionModeConfiguration,
'tableMaintainer' => $this->tableMaintainerMock,
]
);
}

/**
* Check of call count createTablesForDimensions() method
*
* @param $customerGroupId
* @param $callTimes
*
* @dataProvider aroundSaveDataProvider
*/
public function testAroundSave($customerGroupId, $callTimes)
{
$subjectMock = $this->createMock(GroupRepositoryInterface::class);
$customerGroupMock = $this->createPartialMock(
Group::class,
['getId']
);
$customerGroupMock->method('getId')->willReturn($customerGroupId);
$this->tableMaintainerMock->expects(
$this->exactly($callTimes)
)->method('createTablesForDimensions');
$this->proceedMock = function ($customerGroupMock) {
return $customerGroupMock;
};
$this->dimensionModeConfiguration->method('getDimensionConfiguration')->willReturn(
[CustomerGroupDimensionProvider::DIMENSION_NAME]
);
$this->model->aroundSave($subjectMock, $this->proceedMock, $customerGroupMock);
}

/**
* Data provider for testAroundSave
*
* @return array
*/
public function aroundSaveDataProvider()
{
return [
'customer_group_id = 0' => [
'customer_group_id' => '0',
'create_tables_call_times' => 0
],
'customer_group_id = 1' => [
'customer_group_id' => '1',
'create_tables_call_times' => 0
],
'customer_group_id = null' => [
'customer_group_id' => null,
'create_tables_call_times' => 1
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
namespace Magento\Catalog\Test\Unit\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Websites;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\Store\Api\GroupRepositoryInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\Store\Model\Group;
use Magento\Store\Model\Store as StoreView;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Website;
use Magento\Store\Model\Store as StoreView;
use Magento\Store\Model\Group;

/**
* Class WebsitesTest
* Class WebsitesTest test the meta data and website data for different websites
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
Expand Down Expand Up @@ -111,7 +110,7 @@ protected function setUp()
->method('getWebsiteIds')
->willReturn($this->assignedWebsites);
$this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
->setMethods(['isSingleStoreMode', 'getWesites'])
->setMethods(['isSingleStoreMode', 'getWebsites'])
->getMockForAbstractClass();
$this->storeManagerMock->method('getWebsites')
->willReturn([$this->websiteMock, $this->secondWebsiteMock]);
Expand Down Expand Up @@ -182,6 +181,14 @@ public function testModifyMeta()
$this->assertTrue(isset($meta['websites']['children'][self::SECOND_WEBSITE_ID]));
$this->assertTrue(isset($meta['websites']['children'][self::WEBSITE_ID]));
$this->assertTrue(isset($meta['websites']['children']['copy_to_stores.' . self::WEBSITE_ID]));
$this->assertEquals(
$meta['websites']['children'][self::SECOND_WEBSITE_ID]['arguments']['data']['config']['value'],
(string) self::SECOND_WEBSITE_ID
);
$this->assertEquals(
$meta['websites']['children'][self::WEBSITE_ID]['arguments']['data']['config']['value'],
"0"
);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
namespace Magento\Catalog\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\Store\Api\GroupRepositoryInterface;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Ui\Component\Form;
use Magento\Store\Api\WebsiteRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\DynamicRows;
use Magento\Ui\Component\Form;

/**
* Class Websites customizes websites panel
Expand Down Expand Up @@ -211,6 +211,30 @@ protected function getFieldsForFieldset()
}
}

$children = $this->setDefaultWebsiteIdIfNoneAreSelected($children);
return $children;
}

/**
* Set default website id if none are selected
*
* @param array $children
* @return array
*/
private function setDefaultWebsiteIdIfNoneAreSelected(array $children):array
{
$websitesList = $this->getWebsitesList();
$defaultSelectedWebsite = false;
foreach ($websitesList as $website) {
if ($children[$website['id']]['arguments']['data']['config']['value']) {
$defaultSelectedWebsite = true;
break;
}
}
if (count($websitesList) === 1 && !$defaultSelectedWebsite) {
$website = reset($websitesList);
$children[$website['id']]['arguments']['data']['config']['value'] = (string)$website['id'];
}
return $children;
}

Expand Down
22 changes: 22 additions & 0 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1726,6 +1726,7 @@ protected function _saveProducts()
}

$rowData[self::COL_MEDIA_IMAGE] = [];
list($rowImages, $rowData) = $this->clearNoSelectionImages($rowImages, $rowData);

/*
* Note: to avoid problems with undefined sorting, the value of media gallery items positions
Expand Down Expand Up @@ -1934,6 +1935,27 @@ protected function _saveProducts()

// phpcs:enable

/**
* Clears entries from Image Set and Row Data marked as no_selection
*
* @param array $rowImages
* @param array $rowData
* @return array
*/
private function clearNoSelectionImages($rowImages, $rowData)
{
foreach ($rowImages as $column => $columnImages) {
foreach ($columnImages as $key => $image) {
if ($image == 'no_selection') {
unset($rowImages[$column][$key]);
unset($rowData[$column]);
}
}
}

return [$rowImages, $rowData];
}

/**
* Prepare array with image states (visible or hidden from product page)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*
* phpcs:disable Magento2.Commenting.ConstantsPHPDocFormatting
* @SuppressWarnings(PHPMD.TooManyFields)
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
*/
class Downloadable extends \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType
{
Expand Down Expand Up @@ -332,7 +333,7 @@ public function isRowValid(array $rowData, $rowNum, $isNewProduct = true)
{
$this->rowNum = $rowNum;
$error = false;
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData)) {
if (!$this->downloadableHelper->isRowDownloadableNoValid($rowData) && $isNewProduct) {
$this->_entityModel->addRowError(self::ERROR_OPTIONS_NOT_FOUND, $this->rowNum);
$error = true;
}
Expand Down Expand Up @@ -888,8 +889,8 @@ protected function uploadDownloadableFiles($fileName, $type = 'links', $renameFi
try {
$uploader = $this->uploaderHelper->getUploader($type, $this->parameters);
if (!$this->uploaderHelper->isFileExist($fileName)) {
$uploader->move($fileName, $renameFileOff);
$fileName = $uploader['file'];
$res = $uploader->move($fileName, $renameFileOff);
$fileName = $res['file'];
}
} catch (\Exception $e) {
$this->_entityModel->addRowError(self::ERROR_MOVE_FILE, $this->rowNum);
Expand Down
Loading

0 comments on commit b26e6c9

Please sign in to comment.