Skip to content

Commit 82e64c5

Browse files
committed
MTA-3519: Update Products Using Mass Action change Stock Availability
1 parent fe0aecc commit 82e64c5

File tree

12 files changed

+98
-116
lines changed

12 files changed

+98
-116
lines changed

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Action/Tab/AdvancedInventory.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Action/Tab/Attributes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Mtf\Client\Element\SimpleElement;
1212

1313
/**
14-
* Product update attributes Attributes tab.
14+
* Attributes tab on Product update attributes Form.
1515
*/
1616
class Attributes extends Tab
1717
{

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Edit/Action/UpdateAttribute.php

Lines changed: 0 additions & 72 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Action;
8+
9+
use Magento\Backend\Test\Block\Widget\FormTabs;
10+
use Magento\Mtf\Fixture\InjectableFixture;
11+
12+
/**
13+
* Product update Attributes Form.
14+
*/
15+
class UpdateAttributeForm extends FormTabs
16+
{
17+
/**
18+
* Checkbox array mapping.
19+
*
20+
* @var array
21+
*/
22+
private $checkboxMapping = [
23+
'attributes' => [
24+
'price' => 'toggle_price'
25+
],
26+
'advanced_inventory' => [
27+
'stock_data' => 'stock_data_checkbox'
28+
]
29+
];
30+
31+
/**
32+
* Advanced Inventory Tab selector.
33+
*
34+
* @var string
35+
*/
36+
protected $advancedInventoryTab = '#attributes_update_tabs_inventory';
37+
38+
/**
39+
* Create data array for filling containers.
40+
*
41+
* Returns data in format
42+
* [[abstract_container_name => [field_name => [attribute_name => attribute_value, ..], ..], ..]
43+
* where container name should be set to 'null' if a field is not present on the form.
44+
*
45+
* @param InjectableFixture $fixture
46+
* @return array
47+
*/
48+
protected function getFixtureFieldsByContainers(InjectableFixture $fixture)
49+
{
50+
$dataByContainer = [];
51+
$data = $fixture->getData();
52+
53+
foreach ($this->containers as $key => $container) {
54+
foreach ($container['fields'] as $fieldKey => $field) {
55+
if (isset($data[$fieldKey])) {
56+
$dataByContainer[$key][$fieldKey]['value'] = $data[$fieldKey];
57+
if (isset($this->checkboxMapping[$key][$fieldKey])) {
58+
$dataByContainer[$key][$this->checkboxMapping[$key][$fieldKey]]['value'] = 'Yes';
59+
}
60+
}
61+
}
62+
if (isset($dataByContainer[$key])) {
63+
$dataByContainer[$key] = array_reverse($dataByContainer[$key]);
64+
}
65+
}
66+
67+
return $dataByContainer;
68+
}
69+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
<selector>#attributes_update_tabs_inventory</selector>
2525
<fields>
2626
<stock_data_checkbox>
27-
<selector>[id=inventory_stock_availability_checkbox]</selector>
27+
<selector>#inventory_stock_availability_checkbox</selector>
2828
<input>checkbox</input>
2929
</stock_data_checkbox>
3030
<stock_data>
31-
<selector>[id=inventory_stock_availability]</selector>
31+
<selector>#inventory_stock_availability</selector>
3232
<input>select</input>
3333
</stock_data>
3434
</fields>

dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/Grid.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Grid extends DataGrid
7878
*/
7979
public function updateAttributes(array $items = [])
8080
{
81-
$productsSku = [];
81+
$products = [];
8282
/** @var FixtureInterface $product */
8383
foreach ($items as $product) {
8484
$dataConfig = $product->getDataConfig();
@@ -87,12 +87,12 @@ public function updateAttributes(array $items = [])
8787
$renderArguments = [
8888
'product' => $product,
8989
];
90-
$productsSku = $this->callRender($typeId, 'updateAttributes', $renderArguments);
90+
$products = $this->callRender($typeId, 'prepareData', $renderArguments);
9191
} else {
92-
$productsSku[] = ["sku" => $product->getSku()];
92+
$products[] = ["sku" => $product->getSku()];
9393
}
9494
}
95-
$this->massaction($productsSku, 'Update attributes');
95+
$this->massaction($products, 'Update attributes');
9696
}
9797

9898
/**

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertMassProductUpdateSuccessMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class AssertMassProductUpdateSuccessMessage extends AbstractConstraint
2323
* Assert that after mass update successful message appears.
2424
*
2525
* @param CatalogProductIndex $productGrid
26-
* @param $productsCount
26+
* @param string $productsCount
2727
* @return void
2828
*/
2929
public function processAssert(CatalogProductIndex $productGrid, $productsCount)

dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductsInStock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public function processAssert(
4242
*/
4343
public function toString()
4444
{
45-
return 'In stock control is visible.';
45+
return 'In stock control is visible for each product.';
4646
}
4747
}

dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductActionAttributeEdit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd">
99
<page name="CatalogProductActionAttributeEdit" area="Adminhtml" mca="catalog/product_action_attribute/edit" module="Magento_Catalog">
10-
<block name="attributesBlockForm" class="Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Action\UpdateAttribute" locator="body" strategy="css selector" />
10+
<block name="attributesBlockForm" class="Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Action\UpdateAttributeForm" locator="body" strategy="css selector" />
1111
<block name="formPageActions" class="Magento\Catalog\Test\Block\Adminhtml\Product\Edit\Action\FormPageActions" locator=".page-main-actions" strategy="css selector" />
1212
</page>
1313
</config>

dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product/MassProductUpdateTest.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,12 @@ public function __inject(
9898
* @param CatalogProductSimple $product
9999
* @param string $configData
100100
* @param array $initialProducts
101-
* @param string $checkbox
102101
* @return array
103102
*/
104103
public function test(
105104
CatalogProductSimple $product,
106105
$configData,
107-
array $initialProducts,
108-
$checkbox
106+
array $initialProducts
109107
) {
110108
$this->configData = $configData;
111109

@@ -123,9 +121,22 @@ public function test(
123121
// Steps
124122
$this->productGrid->open();
125123
$this->productGrid->getProductGrid()->updateAttributes($products);
126-
$this->attributeMassActionPage->getAttributesBlockForm()->fillForm($product, $checkbox);
124+
$this->attributeMassActionPage->getAttributesBlockForm()->fill($product);
127125
$this->attributeMassActionPage->getFormPageActions()->save();
126+
$updatedProducts = $this->prepareUpdatedProducts($products, $product);
127+
128+
return ['products' => $updatedProducts];
129+
}
128130

131+
/**
132+
* Prepare updated products.
133+
*
134+
* @param array $products
135+
* @param CatalogProductSimple $product
136+
* @return array
137+
*/
138+
private function prepareUpdatedProducts(array $products, CatalogProductSimple $product)
139+
{
129140
$productsReturn = [];
130141
/** @var FixtureInterface $item */
131142
foreach ($products as $item) {
@@ -134,8 +145,8 @@ public function test(
134145
['data' => array_merge($item->getData(), $product->getData())]
135146
);
136147
}
137-
138-
return ['products' => $productsReturn];
148+
149+
return $productsReturn;
139150
}
140151

141152
/**

0 commit comments

Comments
 (0)