9 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductEdit;
10 use Magento\Catalog\Test\Page\Adminhtml\CatalogProductIndex;
12 use Magento\Mtf\TestStep\TestStepInterface;
13 use Magento\Mtf\Fixture\FixtureFactory;
25 private $attributeKey =
'attribute_key_0';
53 private $fixtureFactory;
60 private $productUpdate;
71 CatalogProductIndex $productGrid,
72 CatalogProductEdit $productEdit,
73 FixtureFactory $fixtureFactory,
77 $this->productGrid = $productGrid;
78 $this->productEdit = $productEdit;
79 $this->fixtureFactory = $fixtureFactory;
80 $this->productUpdate = $productUpdate;
90 $items = explode(
',', $this->productUpdate[
'optionNumber']);
92 foreach (
$items as $itemIndex) {
93 $index = (int)$itemIndex - 1;
94 $optionKey =
'option_key_' .
$index;
95 $matrixIndex = $this->attributeKey .
':' . $optionKey;
96 $sku = $this->product->getConfigurableAttributesData()[
'matrix'][$matrixIndex][
'sku'];
97 $this->fillChildProductData($sku);
98 $this->prepareResultProduct($matrixIndex, $optionKey);
101 return [
'product' => $this->product];
111 private function prepareResultProduct($matrixIndex, $optionKey)
113 $product = $this->product->getData();
114 $attributeKey =
'configurable_attributes_data';
116 if (isset($this->productUpdate[
'newPrice'])) {
117 $product[$attributeKey][
'matrix'][$matrixIndex][
'price'] = $this->productUpdate[
'newPrice'];
118 $product[$attributeKey][
'attributes_data'][$this->attributeKey][
'options'][$optionKey][
'pricing_value']
119 = $this->productUpdate[
'newPrice'];
121 unset($product[$attributeKey][
'matrix'][$matrixIndex]);
122 unset($product[$attributeKey][
'attributes_data'][$this->attributeKey][
'options'][$optionKey]);
125 $product[
'category_ids'][
'category']
126 = $this->product->getDataFieldConfig(
'category_ids')[
'source']->getCategories()[0];
127 $product[
'price'] = $this->getLowestConfigurablePrice($product);
129 if (!empty($product[
'configurable_attributes_data'][
'attributes_data'][$this->attributeKey][
'options'])) {
130 $this->product = $this->fixtureFactory->createByCode(
'configurableProduct', [
'data' => $product]);
140 private function fillChildProductData($sku)
142 $this->productGrid->open();
143 $this->productGrid->getProductGrid()->searchAndOpen([
'sku' => $sku]);
145 if (isset($this->productUpdate[
'switchScope']) && $this->productUpdate[
'switchScope']) {
146 $store = $this->fixtureFactory->createByCode(
'store', [
'dataset' =>
'default']);
147 $this->productEdit->getFormPageActions()->changeStoreViewScope(
$store);
150 if (isset($this->productUpdate[
'childProductUpdate'][
'unassignFromWebsite'])) {
151 $this->productEdit->getProductForm()->unassignFromWebsite(
152 $this->productUpdate[
'childProductUpdate'][
'unassignFromWebsite']
155 $fixture = $this->fixtureFactory->createByCode(
156 'catalogProductSimple',
157 $this->productUpdate[
'childProductUpdate']
159 $this->productEdit->getProductForm()->fill($fixture);
162 $this->productEdit->getFormPageActions()->save();
171 private function getLowestConfigurablePrice(array $product)
175 $price = isset($attributeOption[
'price']) ? $attributeOption[
'price'] :
"0";
__construct(ConfigurableProduct $product, CatalogProductIndex $productGrid, CatalogProductEdit $productEdit, FixtureFactory $fixtureFactory, array $productUpdate)