Skip to content

Commit

Permalink
Merge pull request #8311 from magento-l3/PR-05242023
Browse files Browse the repository at this point in the history
L3- PR 05242023
  • Loading branch information
dhorytskyi authored Jul 5, 2023
2 parents 09eaf9f + 275148c commit 41883fa
Show file tree
Hide file tree
Showing 34 changed files with 905 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,7 @@
<element name="priceType" type="select" selector="[name='product[options][0][price_type]']" />
<element name="priceTypeSelectPercent" type="select" selector="//*[@name='product[options][0][price_type]']/option[2]" />
<element name="weightFieldLabel" type="input" selector="//div[@data-index='weight']/div/label/span"/>
<!--Errors-->
<element name="fieldError" type="text" selector=".admin__field-error[data-bind='attr: {for: {{field}}}, text: error']" parameterized="true"/>
</section>
</sections>
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="AdminAddDecimalDefaultToBundleItemsTest">
<annotations>
<features value="Bundle"/>
<stories value="Create/Edit bundle product in Admin"/>
<title value="Admin should be able to set decimal default to bundle item when item allows it"/>
<description value="Admin should be able to set decimal default value to new bundle option"/>
<severity value="AVERAGE"/>
<testCaseId value="AC-8646"/>
<useCaseId value="ACP2E-1799"/>
<group value="Bundle"/>
</annotations>
<before>
<createData entity="_defaultCategory" stepKey="createPreReqCategory"/>
<createData entity="SimpleProduct2" stepKey="simpleProduct1"/>
<createData entity="SimpleProduct2" stepKey="simpleProduct2"/>
<actionGroup stepKey="loginToAdminPanel" ref="AdminLoginActionGroup"/>
</before>
<after>
<deleteData createDataKey="createPreReqCategory" stepKey="deletePreReqCategory"/>
<deleteData createDataKey="simpleProduct1" stepKey="deleteSimpleProduct1"/>
<deleteData createDataKey="simpleProduct2" stepKey="deleteSimpleProduct2"/>
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="navigateToProductIndex"/>
<actionGroup ref="ResetAdminDataGridToDefaultViewActionGroup" stepKey="clearFilters"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
</after>

<!-- Open simpleProduct1 in Admin -->
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="filterSimpleProduct1">
<argument name="product" value="SimpleProduct2"/>
</actionGroup>
<click selector="{{AdminProductGridSection.productGridNameProduct('$$simpleProduct1.name$$')}}" stepKey="clickOpenProductForEdit"/>
<waitForPageLoad time="30" stepKey="waitForProductEditOpen"/>
<!-- Open *Advanced Inventory* pop-up (Click on *Advanced Inventory* link). Set *Qty Uses Decimals* to *Yes*. Click on button *Done* -->
<actionGroup ref="AdminClickOnAdvancedInventoryLinkActionGroup" stepKey="clickOnAdvancedInventoryLink"/>
<actionGroup ref="AdminSetQtyUsesDecimalsConfigActionGroup" stepKey="setQtyUsesDecimalsConfig">
<argument name="value" value="Yes"/>
</actionGroup>
<actionGroup ref="AdminSubmitAdvancedInventoryFormActionGroup" stepKey="clickOnDoneButton"/>
<actionGroup ref="AdminProductFormSaveActionGroup" stepKey="clickOnSaveButton"/>

<!-- Create new Bundle product -->
<actionGroup ref="AdminOpenCreateBundleProductPageActionGroup" stepKey="goToBundleProductCreationPage"/>
<actionGroup ref="AdminClickAddOptionOnBundleProductEditPageActionGroup" stepKey="clickAddOption1"/>
<actionGroup ref="AdminFillBundleOptionTitleActionGroup" stepKey="fillOptionTitle">
<argument name="optionTitle" value="{{BundleProduct.optionTitle1}}"/>
</actionGroup>
<actionGroup ref="AdminFillBundleOptionTypeActionGroup" stepKey="selectInputType"/>

<actionGroup ref="AdminClickAddProductToOptionByOptionIndexActionGroup" stepKey="clickAddProductsToOption"/>
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterBundleProductOptions">
<argument name="product" value="$$simpleProduct1$$"/>
</actionGroup>
<actionGroup ref="AdminCheckFirstCheckboxInAddProductsToOptionPanelGridActionGroup" stepKey="selectFirstGridRow"/>
<actionGroup ref="FilterProductGridBySkuActionGroup" stepKey="filterBundleProductOptions2">
<argument name="product" value="$$simpleProduct2$$"/>
</actionGroup>
<actionGroup ref="AdminCheckFirstCheckboxInAddProductsToOptionPanelGridActionGroup" stepKey="selectFirstGridRow2"/>
<actionGroup ref="AdminClickAddSelectedProductsOnAddProductsToOptionPanelActionGroup" stepKey="clickAddSelectedBundleProducts"/>

<grabValueFrom selector="{{AdminProductFormBundleSection.bundleOptionXProductYQuantity('0', '0')}}" stepKey="grabbedFirstBundleOptionQuantity"/>
<assertEquals stepKey="assertFirstBundleOptionDefaultQuantity">
<expectedResult type="string">1</expectedResult>
<actualResult type="string">$grabbedFirstBundleOptionQuantity</actualResult>
</assertEquals>
<grabValueFrom selector="{{AdminProductFormBundleSection.bundleOptionXProductYQuantity('0', '1')}}" stepKey="grabbedSecondBundleOptionQuantity"/>
<assertEquals stepKey="assertSecondBundleOptionDefaultQuantity">
<expectedResult type="string">1</expectedResult>
<actualResult type="string">$grabbedSecondBundleOptionQuantity</actualResult>
</assertEquals>

<!-- Fill first selection with decimal value -->
<actionGroup ref="AdminFillBundleItemQtyActionGroup" stepKey="fillProduct1DefaultQty">
<argument name="optionIndex" value="0"/>
<argument name="productIndex" value="0"/>
<argument name="qty" value="2.56"/>
</actionGroup>

<!-- Check there is no error message for the slection with allowed decimal value -->
<dontSee selector="{{AdminProductFormBundleSection.fieldError('uid')}}" userInput="Please enter a valid number in this field." stepKey="doNotSeeErrorMessageForProduct1"/>

<!-- Fill second selection with decimal value -->
<actionGroup ref="AdminFillBundleItemQtyActionGroup" stepKey="fillProduct2DefaultQty">
<argument name="optionIndex" value="0"/>
<argument name="productIndex" value="1"/>
<argument name="qty" value="2.56"/>
</actionGroup>

<!-- Check there is an error message for the slection with not allowed decimal value -->
<see selector="{{AdminProductFormBundleSection.fieldError('uid')}}" userInput="Please enter a valid number in this field." stepKey="seeErrorMessageForProduct2"/>

</test>
</tests>
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
use Magento\Framework\App\RequestInterface;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Model\Store;
use Magento\Ui\DataProvider\Modifier\PoolInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

class BundleDataProviderTest extends TestCase
{
const ALLOWED_TYPE = 'simple';
private const ALLOWED_TYPE = 'simple';

/**
* @var ObjectManager
Expand All @@ -46,13 +47,21 @@ class BundleDataProviderTest extends TestCase
*/
protected $dataHelperMock;

/**
* @var PoolInterface|MockObject
*/
private $modifierPool;

/**
* @return void
*/
protected function setUp(): void
{
$this->objectManager = new ObjectManager($this);

$this->modifierPool = $this->getMockBuilder(PoolInterface::class)
->getMockForAbstractClass();

$this->requestMock = $this->getMockBuilder(RequestInterface::class)
->getMockForAbstractClass();
$this->collectionMock = $this->getMockBuilder(Collection::class)
Expand Down Expand Up @@ -97,6 +106,7 @@ protected function getModel()
'addFilterStrategies' => [],
'meta' => [],
'data' => [],
'modifiersPool' => $this->modifierPool,
]);
}

Expand Down Expand Up @@ -128,6 +138,9 @@ public function testGetData()
$this->collectionMock->expects($this->once())
->method('getSize')
->willReturn(count($items));
$this->modifierPool->expects($this->once())
->method('getModifiersInstances')
->willReturn([]);

$this->assertEquals($expectedData, $this->getModel()->getData());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
use Magento\Bundle\Helper\Data;
use Magento\Framework\App\ObjectManager;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\Ui\DataProvider\Modifier\PoolInterface;

class BundleDataProvider extends ProductDataProvider
{
Expand All @@ -16,6 +19,11 @@ class BundleDataProvider extends ProductDataProvider
*/
protected $dataHelper;

/**
* @var PoolInterface
*/
private $modifiersPool;

/**
* Construct
*
Expand All @@ -24,10 +32,12 @@ class BundleDataProvider extends ProductDataProvider
* @param string $requestFieldName
* @param CollectionFactory $collectionFactory
* @param Data $dataHelper
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param array $meta
* @param array $data
* @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
* @param PoolInterface|null $modifiersPool
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
Expand All @@ -38,7 +48,8 @@ public function __construct(
array $meta = [],
array $data = [],
array $addFieldStrategies = [],
array $addFilterStrategies = []
array $addFilterStrategies = [],
PoolInterface $modifiersPool = null
) {
parent::__construct(
$name,
Expand All @@ -52,6 +63,7 @@ public function __construct(
);

$this->dataHelper = $dataHelper;
$this->modifiersPool = $modifiersPool ?: ObjectManager::getInstance()->get(PoolInterface::class);
}

/**
Expand All @@ -72,11 +84,34 @@ public function getData()
);
$this->getCollection()->load();
}

$items = $this->getCollection()->toArray();

return [
$data = [
'totalRecords' => $this->getCollection()->getSize(),
'items' => array_values($items),
];

/** @var ModifierInterface $modifier */
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
$data = $modifier->modifyData($data);
}

return $data;
}

/**
* @inheritdoc
*/
public function getMeta()
{
$meta = parent::getMeta();

/** @var ModifierInterface $modifier */
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
$meta = $modifier->modifyMeta($meta);
}

return $meta;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Bundle\Ui\DataProvider\Product\Form\Modifier;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
use Magento\CatalogInventory\Model\StockRegistryPreloader;

/**
* Affects Qty field for newly added selection
*/
class AddSelectionQtyTypeToProductsData implements ModifierInterface
{
/**
* @var StockRegistryPreloader
*/
private StockRegistryPreloader $stockRegistryPreloader;

/**
* Initializes dependencies
*
* @param StockRegistryPreloader $stockRegistryPreloader
*/
public function __construct(StockRegistryPreloader $stockRegistryPreloader)
{
$this->stockRegistryPreloader = $stockRegistryPreloader;
}

/**
* Modify Meta
*
* @param array $meta
* @return array
*/
public function modifyMeta(array $meta)
{
return $meta;
}

/**
* Modify Data - checks if new selection can have decimal quantity
*
* @param array $data
* @return array
* @throws NoSuchEntityException
*/
public function modifyData(array $data): array
{
$productIds = array_column($data['items'], 'entity_id');

$stockItems = [];
if ($productIds) {
$stockItems = $this->stockRegistryPreloader->preloadStockItems($productIds);
}

$isQtyDecimals = [];
foreach ($stockItems as $stockItem) {
$isQtyDecimals[$stockItem->getProductId()] = $stockItem->getIsQtyDecimal();
}

foreach ($data['items'] as &$item) {
if (isset($isQtyDecimals[$item['entity_id']])) {
$item['selection_qty_is_integer'] = !$isQtyDecimals[$item['entity_id']];
}
}

return $data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ protected function getBundleOptions()
'selection_price_type' => '',
'selection_price_value' => '',
'selection_qty' => '',
'selection_qty_is_integer'=> 'selection_qty_is_integer',
],
'links' => [
'insertData' => '${ $.provider }:${ $.dataProvider }',
Expand Down
17 changes: 17 additions & 0 deletions app/code/Magento/Bundle/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,21 @@
</argument>
</arguments>
</type>
<virtualType name="Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\ModifiersPool" type="Magento\Ui\DataProvider\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="add_selection_qty_type_to_products_data" xsi:type="array">
<item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\AddSelectionQtyTypeToProductsData</item>
<item name="sortOrder" xsi:type="number">200</item>
</item>
</argument>
</arguments>
</virtualType>
<type name="Magento\Bundle\Ui\DataProvider\Product\BundleDataProvider">
<arguments>
<argument name="modifiersPool" xsi:type="object">
Magento\Bundle\Ui\DataProvider\Product\Form\Modifier\ModifiersPool
</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<before>
<!-- Login as admin -->
<actionGroup ref="AdminLoginActionGroup" stepKey="login"/>
<actionGroup ref="AdminOpenProductIndexPageActionGroup" stepKey="openProductIndexPageBefore"/>
<!-- remove the Filter From the page-->
<amOnPage url="{{AdminProductIndexPage.url}}" stepKey="visitAdminProductPage"/>
<actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFilterFromProductIndex"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<createData entity="SimpleSubCategory" stepKey="categoryEntity"/>
</before>
<after>
<actionGroup ref="AdminProductCatalogPageOpenActionGroup" stepKey="openProductCatalogPage1"/>
<actionGroup ref="AdminDeleteAllProductsFromGridActionGroup" stepKey="selectAndDeleteProducts"/>
<actionGroup ref="ClearFiltersAdminProductGridActionGroup" stepKey="clearFilterFromProductIndex"/>
<deleteData stepKey="deleteSimpleSubCategory" createDataKey="initialCategoryEntity"/>
<deleteData stepKey="deleteSimpleSubCategory2" createDataKey="categoryEntity"/>
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
Expand Down
Loading

0 comments on commit 41883fa

Please sign in to comment.