Skip to content

Commit

Permalink
Merge branch '2.4-develop' into 30936-cms-perfomance
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Charlie authored Jan 15, 2021
2 parents 9ee832e + 3fef6d1 commit 2900e74
Show file tree
Hide file tree
Showing 149 changed files with 1,912 additions and 580 deletions.
39 changes: 27 additions & 12 deletions app/code/Magento/Backend/Controller/Adminhtml/System/Store/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
namespace Magento\Backend\Controller\Adminhtml\System\Store;

use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;
use Magento\Store\Model\Group as StoreGroup;
use Magento\Store\Model\Store;
use Magento\Framework\Exception\LocalizedException;

/**
* Class Save
Expand All @@ -33,6 +36,17 @@ private function processWebsiteSave($postData)
$websiteModel->setId(null);
}

$groupModel = $this->_objectManager->create(StoreGroup::class);
$groupModel->load($websiteModel->getDefaultGroupId());
$storeModel = $this->_objectManager->create(Store::class);
$storeModel->load($groupModel->getDefaultStoreId());

if ($websiteModel->getIsDefault() && !$storeModel->isActive()) {
throw new LocalizedException(
__('Please enable your Store View before using this Web Site as Default')
);
}

$websiteModel->save();
$this->messageManager->addSuccessMessage(__('You saved the website.'));

Expand All @@ -43,13 +57,13 @@ private function processWebsiteSave($postData)
* Process Store model save
*
* @param array $postData
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @return array
*/
private function processStoreSave($postData)
{
/** @var \Magento\Store\Model\Store $storeModel */
$storeModel = $this->_objectManager->create(\Magento\Store\Model\Store::class);
/** @var Store $storeModel */
$storeModel = $this->_objectManager->create(Store::class);
$postData['store']['name'] = $this->filterManager->removeTags($postData['store']['name']);
if ($postData['store']['store_id']) {
$storeModel->load($postData['store']['store_id']);
Expand All @@ -59,13 +73,13 @@ private function processStoreSave($postData)
$storeModel->setId(null);
}
$groupModel = $this->_objectManager->create(
\Magento\Store\Model\Group::class
StoreGroup::class
)->load(
$storeModel->getGroupId()
);
$storeModel->setWebsiteId($groupModel->getWebsiteId());
if (!$storeModel->isActive() && $storeModel->isDefault()) {
throw new \Magento\Framework\Exception\LocalizedException(
throw new LocalizedException(
__('The default store cannot be disabled')
);
}
Expand All @@ -79,14 +93,14 @@ private function processStoreSave($postData)
* Process StoreGroup model save
*
* @param array $postData
* @throws \Magento\Framework\Exception\LocalizedException
* @throws LocalizedException
* @return array
*/
private function processGroupSave($postData)
{
$postData['group']['name'] = $this->filterManager->removeTags($postData['group']['name']);
/** @var \Magento\Store\Model\Group $groupModel */
$groupModel = $this->_objectManager->create(\Magento\Store\Model\Group::class);
/** @var StoreGroup $groupModel */
$groupModel = $this->_objectManager->create(StoreGroup::class);
if ($postData['group']['group_id']) {
$groupModel->load($postData['group']['group_id']);
}
Expand All @@ -95,10 +109,11 @@ private function processGroupSave($postData)
$groupModel->setId(null);
}
if (!$this->isSelectedDefaultStoreActive($postData, $groupModel)) {
throw new \Magento\Framework\Exception\LocalizedException(
throw new LocalizedException(
__('An inactive store view cannot be saved as default store view')
);
}

$groupModel->save();
$this->messageManager->addSuccessMessage(__('You saved the store.'));

Expand Down Expand Up @@ -135,7 +150,7 @@ public function execute()
}
$redirectResult->setPath('adminhtml/*/');
return $redirectResult;
} catch (\Magento\Framework\Exception\LocalizedException $e) {
} catch (LocalizedException $e) {
$this->messageManager->addErrorMessage($e->getMessage());
$this->_getSession()->setPostData($postData);
} catch (\Exception $e) {
Expand All @@ -156,10 +171,10 @@ public function execute()
* Verify if selected default store is active
*
* @param array $postData
* @param \Magento\Store\Model\Group $groupModel
* @param StoreGroup $groupModel
* @return bool
*/
private function isSelectedDefaultStoreActive(array $postData, \Magento\Store\Model\Group $groupModel)
private function isSelectedDefaultStoreActive(array $postData, StoreGroup $groupModel)
{
if (!empty($postData['group']['default_store_id'])) {
$defaultStoreId = $postData['group']['default_store_id'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminClearGridFiltersActionGroup">
<annotations>
<description>Click the Clear filters on the grid.</description>
</annotations>

<click selector="{{AdminDataGridHeaderSection.clearFilters}}" stepKey="clickClearFilters"/>
<waitForPageLoad stepKey="waitForPageLoaded"/>
</actionGroup>
</actionGroups>
1 change: 1 addition & 0 deletions app/code/Magento/Backend/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ System,System
"All Stores","All Stores"
"You saved the website.","You saved the website."
"The default store cannot be disabled","The default store cannot be disabled"
"Please enable your Store View before using this Web Site as Default","Please enable your Store View before using this Web Site as Default"
"You saved the store view.","You saved the store view."
"An inactive store view cannot be saved as default store view","An inactive store view cannot be saved as default store view"
"You saved the store.","You saved the store."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ public function getJsonConfig()
$configValue = $preConfiguredValues->getData('bundle_option/' . $optionId);
if ($configValue) {
$defaultValues[$optionId] = $configValue;
$configQty = $preConfiguredValues->getData('bundle_option_qty/' . $optionId);
if ($configQty) {
$options[$optionId]['selections'][$configValue]['qty'] = $configQty;
}
}
$options = $this->processOptions($optionId, $options, $preConfiguredValues);
}
Expand Down
10 changes: 6 additions & 4 deletions app/code/Magento/Bundle/Model/CartItemProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritDoc
*/
public function convertToBuyRequest(CartItemInterface $cartItem)
{
Expand All @@ -73,7 +73,7 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
}

/**
* {@inheritdoc}
* @inheritDoc
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function processOptions(CartItemInterface $cartItem)
Expand All @@ -84,19 +84,21 @@ public function processOptions(CartItemInterface $cartItem)
$productOptions = [];
$bundleOptions = $cartItem->getBuyRequest()->getBundleOption();
$bundleOptionsQty = $cartItem->getBuyRequest()->getBundleOptionQty();
$bundleOptionsQty = is_array($bundleOptionsQty) ? $bundleOptionsQty : [];
if (is_array($bundleOptions)) {
foreach ($bundleOptions as $optionId => $optionSelections) {
if (empty($optionSelections)) {
continue;
}
$optionSelections = is_array($optionSelections) ? $optionSelections : [$optionSelections];
$optionQty = isset($bundleOptionsQty[$optionId]) ? $bundleOptionsQty[$optionId] : 1;

/** @var \Magento\Bundle\Api\Data\BundleOptionInterface $productOption */
$productOption = $this->bundleOptionFactory->create();
$productOption->setOptionId($optionId);
$productOption->setOptionSelections($optionSelections);
$productOption->setOptionQty($optionQty);
if (isset($bundleOptionsQty[$optionId])) {
$productOption->setOptionQty($bundleOptionsQty[$optionId]);
}
$productOptions[] = $productOption;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ public function testGetJsonConfigFixedPriceBundleNoOption()

public function testGetJsonConfigFixedPriceBundle()
{
$optionId = 1;
$optionQty = 2;
$baseAmount = 123;
$basePriceValue = 123123;
$selections = [
Expand All @@ -230,7 +232,6 @@ public function testGetJsonConfigFixedPriceBundle()
true
)
];

$bundleProductPrice = $this->getMockBuilder(Price::class)
->disableOriginalConstructor()
->setMethods(['getLowestPrice'])
Expand All @@ -246,10 +247,8 @@ public function testGetJsonConfigFixedPriceBundle()
$this->bundleProductPriceFactory->expects($this->once())
->method('create')
->willReturn($bundleProductPrice);
$options = [$this->createOption($optionId, 'Title `1', $selections)];

$options = [
$this->createOption(1, 'Title `1', $selections),
];
$finalPriceMock = $this->getPriceMock(
[
'getPriceWithoutOption' => new DataObject(
Expand Down Expand Up @@ -289,7 +288,10 @@ public function testGetJsonConfigFixedPriceBundle()
$preconfiguredValues = new DataObject(
[
'bundle_option' => [
1 => 123123111,
$optionId => [123123111],
],
'bundle_option_qty' => [
$optionId => $optionQty,
],
]
);
Expand All @@ -306,7 +308,8 @@ public function testGetJsonConfigFixedPriceBundle()
$this->assertEquals(110, $jsonConfig['prices']['oldPrice']['amount']);
$this->assertEquals(100, $jsonConfig['prices']['basePrice']['amount']);
$this->assertEquals(100, $jsonConfig['prices']['finalPrice']['amount']);
$this->assertEquals([1], $jsonConfig['positions']);
$this->assertEquals([$optionId], $jsonConfig['positions']);
$this->assertEquals($optionQty, $jsonConfig['options'][$optionId]['selections'][1123]['qty']);
}

/**
Expand Down
8 changes: 7 additions & 1 deletion app/code/Magento/Bundle/Test/Unit/Model/Product/TypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Bundle\Model\Product\Type;
use Magento\Bundle\Model\ResourceModel\BundleFactory;
use Magento\Bundle\Model\ResourceModel\Option\Collection;
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as SelectionCollection;
use Magento\Bundle\Model\ResourceModel\Selection\CollectionFactory;
use Magento\Bundle\Model\Selection;
Expand All @@ -28,6 +27,7 @@
use Magento\CatalogInventory\Api\StockStateInterface;
use Magento\CatalogInventory\Model\StockRegistry;
use Magento\CatalogInventory\Model\StockState;
use Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor;
use Magento\Framework\DataObject;
use Magento\Framework\EntityManager\EntityMetadataInterface;
use Magento\Framework\EntityManager\MetadataPool;
Expand Down Expand Up @@ -1548,6 +1548,10 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
->disableOriginalConstructor()
->getMock();

$buyRequest->method('getOptions')
->willReturn([333 => ['type' => 'image/jpeg']]);
$option->method('getId')
->willReturn(333);
$this->parentClass($group, $option, $buyRequest, $product);

$product->expects($this->any())
Expand All @@ -1556,6 +1560,8 @@ public function testPrepareForCartAdvancedSpecifyProductOptions()
$buyRequest->expects($this->once())
->method('getBundleOption')
->willReturn([0, '', 'str']);
$group->expects($this->once())
->method('validateUserValue');

$result = $this->model->prepareForCartAdvanced($buyRequest, $product);
$this->assertEquals('Please specify product option(s).', $result);
Expand Down
7 changes: 5 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Catalog\Model\Product\Type;

Expand Down Expand Up @@ -605,7 +604,11 @@ protected function _prepareOptions(\Magento\Framework\DataObject $buyRequest, $p
if ($product->getSkipCheckRequiredOption() !== true) {
$group->validateUserValue($optionsFromRequest);
} elseif ($optionsFromRequest !== null && isset($optionsFromRequest[$option->getId()])) {
$transport->options[$option->getId()] = $optionsFromRequest[$option->getId()];
if (is_array($optionsFromRequest[$option->getId()])) {
$group->validateUserValue($optionsFromRequest);
} else {
$transport->options[$option->getId()] = $optionsFromRequest[$option->getId()];
}
}

} catch (LocalizedException $e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminChangeWebSiteAssignedToProductActionGroup" extends="AddWebsiteToProductActionGroup">
<annotations>
<description>Extends AddWebsiteToProductActionGroup. Changes website assigned to product from websiteToDeselect to website</description>
</annotations>
<arguments>
<argument name="websiteToDeselect" type="string"/>
</arguments>

<uncheckOption selector="{{ProductInWebsitesSection.website(websiteToDeselect)}}" stepKey="uncheckWebsite" after="checkWebsite"/>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCheckProductOnProductGridActionGroup">
<annotations>
<description>Check the checkbox for the product on the Product Grid</description>
</annotations>
<arguments>
<argument name="product" type="entity"/>
</arguments>
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminCheckProductOnProductGridActionGroup">
<annotations>
<description>Check the checkbox for the product on the Product Grid</description>
</annotations>
<arguments>
<argument name="product" type="entity"/>
</arguments>

<checkOption selector="{{AdminProductGridSection.productRowCheckboxBySku(product.sku)}}" stepKey="selectProduct"/>
<checkOption selector="{{AdminProductGridSection.productRowCheckboxBySku(product.sku)}}" stepKey="selectProduct"/>

</actionGroup>
</actionGroups>
</actionGroup>
</actionGroups>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
<actionGroup name="AdminSetPriceForMassUpdateActionGroup">
<annotations>
<description>Click the "Change" checkbox for the "Price" field. Set new price.</description>
</annotations>
<arguments>
<argument name="price" type="string"/>
</arguments>

<scrollTo stepKey="scrollToPriceCheckBox" selector="{{AdminEditProductAttributesSection.ChangeAttributePriceToggle}}" x="0" y="-160"/>
<click selector="{{AdminEditProductAttributesSection.ChangeAttributePriceToggle}}" stepKey="selectPriceCheckBox"/>
<fillField stepKey="fillPrice" selector="{{AdminEditProductAttributesSection.AttributePrice}}" userInput="{{price}}"/>

</actionGroup>
</actionGroups>
Loading

0 comments on commit 2900e74

Please sign in to comment.