Skip to content

Commit

Permalink
Merge branch '2.4-develop' into fix-28388
Browse files Browse the repository at this point in the history
  • Loading branch information
engcom-Kilo committed Aug 14, 2020
2 parents 62e4866 + 7198c76 commit 97df424
Show file tree
Hide file tree
Showing 438 changed files with 16,344 additions and 3,015 deletions.
20 changes: 16 additions & 4 deletions app/code/Magento/Backend/Block/Widget/Grid/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Class Export for exporting grid data as CSV file or MS Excel 2003 XML Document file
*
* @api
* @deprecated 100.2.0 in favour of UI component implementation
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -69,6 +71,8 @@ public function __construct(
}

/**
* Internal constructor, that is called from real constructor
*
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
Expand Down Expand Up @@ -242,6 +246,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -273,7 +278,12 @@ public function _exportIterateCollection($callback, array $args)

$collection = $this->_getRowCollection($originalCollection);
foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -307,7 +317,7 @@ protected function _exportCsvItem(
*/
public function getCsvFile()
{
$name = md5(microtime());
$name = hash('sha256', microtime());
$file = $this->_path . '/' . $name . '.csv';

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -432,11 +442,11 @@ public function getRowRecord(\Magento\Framework\DataObject $data)
*/
public function getExcelFile($sheetName = '')
{
$collection = $this->_getRowCollection();
$collection = $this->_getPreparedCollection();

$convert = new \Magento\Framework\Convert\Excel($collection->getIterator(), [$this, 'getRowRecord']);

$name = md5(microtime());
$name = hash('sha256', microtime());
$file = $this->_path . '/' . $name . '.xml';

$this->_directory->create($this->_path);
Expand Down Expand Up @@ -551,6 +561,8 @@ public function _getPreparedCollection()
}

/**
* Get export page size
*
* @return int
*/
public function getExportPageSize()
Expand Down
24 changes: 18 additions & 6 deletions app/code/Magento/Backend/Block/Widget/Grid/Extended.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Extended Grid Widget
*
* @api
* @deprecated 100.2.0 in favour of UI component implementation
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
Expand Down Expand Up @@ -177,7 +179,10 @@ class Extended extends \Magento\Backend\Block\Widget\Grid implements \Magento\Ba
protected $_path = 'export';

/**
* Initialization
*
* @return void
* @throws \Magento\Framework\Exception\FileSystemException
*/
protected function _construct()
{
Expand Down Expand Up @@ -297,6 +302,7 @@ public function addColumn($columnId, $column)
);
$this->getColumnSet()->getChildBlock($columnId)->setGrid($this);
} else {
// phpcs:ignore Magento2.Exceptions.DirectThrow
throw new \Exception(__('Please correct the column format and try again.'));
}

Expand Down Expand Up @@ -471,10 +477,6 @@ protected function _prepareMassactionColumn()
protected function _prepareCollection()
{
if ($this->getCollection()) {
if ($this->getCollection()->isLoaded()) {
$this->getCollection()->clear();
}

parent::_prepareCollection();

if (!$this->_isExport) {
Expand Down Expand Up @@ -663,6 +665,7 @@ public function setEmptyCellLabel($label)
*/
public function getRowUrl($item)
{
// phpstan:ignore "Call to an undefined static method"
$res = parent::getRowUrl($item);
return $res ? $res : '#';
}
Expand All @@ -680,6 +683,7 @@ public function getMultipleRows($item)

/**
* Retrieve columns for multiple rows
*
* @return array
*/
public function getMultipleRowColumns()
Expand Down Expand Up @@ -943,6 +947,7 @@ protected function _getExportTotals()

/**
* Iterate collection and call callback method per item
*
* For callback method first argument always is item object
*
* @param string $callback
Expand Down Expand Up @@ -972,7 +977,12 @@ public function _exportIterateCollection($callback, array $args)
$page++;

foreach ($collection as $item) {
call_user_func_array([$this, $callback], array_merge([$item], $args));
//phpcs:ignore Magento2.Functions.DiscouragedFunction
call_user_func_array(
[$this, $callback],
// phpcs:ignore Magento2.Performance.ForeachArrayMerge
array_merge([$item], $args)
);
}
}
}
Expand Down Expand Up @@ -1009,6 +1019,7 @@ public function getCsvFile()
$this->_isExport = true;
$this->_prepareGrid();

// phpcs:ignore Magento2.Security.InsecureFunction
$name = md5(microtime());
$file = $this->_path . '/' . $name . '.csv';

Expand Down Expand Up @@ -1153,6 +1164,7 @@ public function getExcelFile($sheetName = '')
[$this, 'getRowRecord']
);

// phpcs:ignore Magento2.Security.InsecureFunction
$name = md5(microtime());
$file = $this->_path . '/' . $name . '.xml';

Expand Down Expand Up @@ -1244,7 +1256,7 @@ public function setCollection($collection)
}

/**
* get collection object
* Get collection object
*
* @return \Magento\Framework\Data\Collection
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public function testPrepareLoadedCollection()
$layout->expects($this->any())->method('getBlock')->willReturn($columnSet);

$collection = $this->createMock(Collection::class);
$collection->expects($this->atLeastOnce())->method('isLoaded')->willReturn(true);
$collection->expects($this->atLeastOnce())->method('clear');
$collection->expects($this->never())->method('isLoaded');
$collection->expects($this->never())->method('clear');
$collection->expects($this->atLeastOnce())->method('load');

/** @var Extended $block */
Expand Down
96 changes: 76 additions & 20 deletions app/code/Magento/Bundle/Model/Product/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace Magento\Bundle\Model\Product;

use Magento\Bundle\Model\Option;
use Magento\Bundle\Model\ResourceModel\Option\Collection;
use Magento\Bundle\Model\ResourceModel\Selection\Collection as Selections;
use Magento\Bundle\Model\ResourceModel\Selection\Collection\FilterApplier as SelectionCollectionFilterApplier;
use Magento\Catalog\Api\ProductRepositoryInterface;
Expand Down Expand Up @@ -414,16 +416,13 @@ public function beforeSave($product)
if ($product->getCanSaveBundleSelections()) {
$product->canAffectOptions(true);
$selections = $product->getBundleSelectionsData();
if ($selections && !empty($selections)) {
$options = $product->getBundleOptionsData();
if ($options) {
foreach ($options as $option) {
if (empty($option['delete']) || 1 != (int)$option['delete']) {
$product->setTypeHasOptions(true);
if (1 == (int)$option['required']) {
$product->setTypeHasRequiredOptions(true);
break;
}
if (!empty($selections) && $options = $product->getBundleOptionsData()) {
foreach ($options as $option) {
if (empty($option['delete']) || 1 != (int)$option['delete']) {
$product->setTypeHasOptions(true);
if (1 == (int)$option['required']) {
$product->setTypeHasRequiredOptions(true);
break;
}
}
}
Expand Down Expand Up @@ -464,7 +463,7 @@ public function getOptionsIds($product)
public function getOptionsCollection($product)
{
if (!$product->hasData($this->_keyOptionsCollection)) {
/** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
/** @var Collection $optionsCollection */
$optionsCollection = $this->_bundleOption->create()
->getResourceCollection();
$optionsCollection->setProductIdFilter($product->getEntityId());
Expand Down Expand Up @@ -530,10 +529,10 @@ public function getSelectionsCollection($optionIds, $product)
* Example: the catalog inventory validation of decimal qty can change qty to int,
* so need to change quote item qty option value too.
*
* @param array $options
* @param \Magento\Framework\DataObject $option
* @param mixed $value
* @param \Magento\Catalog\Model\Product $product
* @param array $options
* @param \Magento\Framework\DataObject $option
* @param mixed $value
* @param \Magento\Catalog\Model\Product $product
* @return $this
*/
public function updateQtyOption($options, \Magento\Framework\DataObject $option, $value, $product)
Expand Down Expand Up @@ -682,6 +681,11 @@ protected function _prepareProduct(\Magento\Framework\DataObject $buyRequest, $p
$options
);

$this->validateRadioAndSelectOptions(
$optionsCollection,
$options
);

$selectionIds = array_values($this->arrayUtility->flatten($options));
// If product has not been configured yet then $selections array should be empty
if (!empty($selectionIds)) {
Expand Down Expand Up @@ -1184,9 +1188,11 @@ public function canConfigure($product)
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
// @codingStandardsIgnoreStart
public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
{
}
// @codingStandardsIgnoreEnd

/**
* Return array of specific to type product entities
Expand All @@ -1196,18 +1202,19 @@ public function deleteTypeSpecificData(\Magento\Catalog\Model\Product $product)
*/
public function getIdentities(\Magento\Catalog\Model\Product $product)
{
$identities = parent::getIdentities($product);
$identities = [];
$identities[] = parent::getIdentities($product);
/** @var \Magento\Bundle\Model\Option $option */
foreach ($this->getOptions($product) as $option) {
if ($option->getSelections()) {
/** @var \Magento\Catalog\Model\Product $selection */
foreach ($option->getSelections() as $selection) {
$identities = array_merge($identities, $selection->getIdentities());
$identities[] = $selection->getIdentities();
}
}
}

return $identities;
return array_merge([], ...$identities);
}

/**
Expand Down Expand Up @@ -1272,6 +1279,53 @@ protected function checkIsAllRequiredOptions($product, $isStrictProcessMode, $op
}
}

/**
* Validate Options for Radio and Select input types
*
* @param Collection $optionsCollection
* @param int[] $options
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function validateRadioAndSelectOptions($optionsCollection, $options): void
{
$errorTypes = [];

if (is_array($optionsCollection->getItems())) {
foreach ($optionsCollection->getItems() as $option) {
if ($this->isSelectedOptionValid($option, $options)) {
$errorTypes[] = $option->getType();
}
}
}

if (!empty($errorTypes)) {
throw new \Magento\Framework\Exception\LocalizedException(
__(
'Option type (%types) should have only one element.',
['types' => implode(", ", $errorTypes)]
)
);
}
}

/**
* Check if selected option is valid
*
* @param Option $option
* @param array $options
* @return bool
*/
private function isSelectedOptionValid($option, $options): bool
{
return (
($option->getType() == 'radio' || $option->getType() == 'select') &&
isset($options[$option->getOptionId()]) &&
is_array($options[$option->getOptionId()]) &&
count($options[$option->getOptionId()]) > 1
);
}

/**
* Check if selection is salable
*
Expand Down Expand Up @@ -1333,16 +1387,18 @@ protected function checkIsResult($_result)
*/
protected function mergeSelectionsWithOptions($options, $selections)
{
$selections = [];

foreach ($options as $option) {
$optionSelections = $option->getSelections();
if ($option->getRequired() && is_array($optionSelections) && count($optionSelections) == 1) {
$selections = array_merge($selections, $optionSelections);
$selections[] = $optionSelections;
} else {
$selections = [];
break;
}
}

return $selections;
return array_merge([], ...$selections);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,9 @@
<actionGroup ref="FilterProductGridByNameActionGroup" stepKey="filterBundleProductOptionsDownToName">
<argument name="product" value="BundleProduct"/>
</actionGroup>
<click selector="{{AdminProductFiltersSection.allCheckbox}}" stepKey="SelectAllOnly1"/>
<waitForPageLoad stepKey="loading2"/>

<!--Delete-->
<click selector="{{AdminProductFiltersSection.actions}}" stepKey="ClickOnActionsChangingView"/>
<click selector="{{AdminProductFiltersSection.delete}}" stepKey="ClickDelete"/>
<click selector="//button[@class='action-primary action-accept']" stepKey="ConfirmDelete"/>
<waitForPageLoad stepKey="loading3"/>
<actionGroup ref="AdminDeleteAllProductsFromGridActionGroup" stepKey="selectAndDeleteProducts"/>

<!--Locating delete message-->
<seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="deleteMessage"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,7 @@
<actionGroup ref="BundleProductFilter" stepKey="FilterForOnlyBundleProducts"/>

<!--Delete-->
<click selector="{{AdminProductFiltersSection.allCheckbox}}" stepKey="SelectAllOnly1"/>
<waitForPageLoad stepKey="loading"/>
<click selector="{{AdminProductFiltersSection.actions}}" stepKey="ClickOnActionsChangingView"/>
<click selector="{{AdminProductFiltersSection.delete}}" stepKey="ClickDelete"/>
<click selector="//button[@class='action-primary action-accept']" stepKey="ConfirmDelete"/>
<waitForPageLoad stepKey="loading3"/>
<actionGroup ref="AdminDeleteAllProductsFromGridActionGroup" stepKey="selectAndDeleteProducts"/>

<!--Locating delete message-->
<seeElement selector="{{AdminCategoryMessagesSection.SuccessMessage}}" stepKey="deleteMessage"/>
Expand Down
Loading

0 comments on commit 97df424

Please sign in to comment.