diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php index f1e0ce8b4692a..fe20855033bed 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Adminhtml/Product/ProductForm.php @@ -72,6 +72,13 @@ class ProductForm extends FormSections */ protected $newAttributeModal = '.product_form_product_form_add_attribute_modal_create_new_attribute_modal'; + /** + * Website checkbox xpath selector. + * + * @var string + */ + protected $websiteCheckbox = '//label[text()="%s"]/../input'; + /** * Fill the product form. * @@ -138,6 +145,17 @@ public function openSection($sectionName) return $this; } + /** + * Unassign product from website by website name. + * + * @param string $name + */ + public function unassignFromWebsite($name) + { + $this->openSection('websites'); + $this->_rootElement->find(sprintf($this->websiteCheckbox, $name), Locator::SELECTOR_XPATH)->click(); + } + /** * Wait page to load. * diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductEdit.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductEdit.xml index 4c11ab84b57ad..fb795bdb3d7f3 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductEdit.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Adminhtml/CatalogProductEdit.xml @@ -12,5 +12,6 @@ + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml index 878f990c352f8..3bfa4ad040f72 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/CustomOptions.xml @@ -592,6 +592,30 @@ + + + custom menu + No + Select/Drop-down + + + first + 1 + Fixed + sku_radio_buttons_drop_down_1 + 0 + + + second + 2 + Fixed + sku_radio_buttons_drop_down_2 + 0 + + + + + custom option drop down %isolation% diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml index d7649b2978a3c..092e9e6860073 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/Product/TierPrice.xml @@ -101,5 +101,16 @@ + + + + 5 + All Websites [USD] + 1 + + ALL_GROUPS + + + diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test3.png b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test3.png new file mode 100644 index 0000000000000..f2ce1e259df50 Binary files /dev/null and b/dev/tests/functional/tests/app/Magento/Catalog/Test/_files/test3.png differ diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config.php index 08a35d8c25885..4a424262f9e6f 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config.php +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config.php @@ -84,14 +84,16 @@ public function setFieldsData(array $fields, SimpleElement $element = null) ? $fields['configurable_attributes_data']['value'] : []; - $attributesValue = isset($fields['configurable_attributes_data']['source']) - ? $fields['configurable_attributes_data']['source']->getAttributesData() - : []; + $attributeSource = isset($fields['configurable_attributes_data']['source']) + ? $fields['configurable_attributes_data']['source'] + : null; + $attributesValue = $attributeSource !== null ? $attributeSource->getAttributesData() : []; + foreach ($attributesValue as $key => $value) { $attributesValue[$key] = array_merge($value, $attributes['attributes_data'][$key]); } $this->createConfigurations(); - $this->getAttributeBlock()->fillAttributes($attributesValue); + $this->getAttributeBlock()->fillAttributes($attributesValue, $attributeSource); if (!empty($attributes['matrix'])) { $this->generateVariations(); $this->getVariationsBlock()->fillVariations($attributes['matrix']); diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.php index ddcd50a7565e4..66333d9f4de2d 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.php +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.php @@ -7,6 +7,7 @@ namespace Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Section\Variations\Config; use Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Edit\Section\Variations\Config\Attribute\AttributeSelector; +use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct\ConfigurableAttributesData; use Magento\Mtf\Block\Form; use Magento\Mtf\Client\Element\SimpleElement; use Magento\Mtf\Client\Locator; @@ -159,13 +160,21 @@ class Attribute extends Form */ private $selectedAttributes = 'span[data-bind*="selectedAttributes"]'; + /** + * Wizard Images step CSS selector. + * + * @var string + */ + private $wizardImagesStep = '#variation-steps-wizard_step3'; + /** * Fill attributes * * @param array $attributes + * @param ConfigurableAttributesData $attributeSource * @return void */ - public function fillAttributes(array $attributes) + public function fillAttributes(array $attributes, ConfigurableAttributesData $attributeSource) { $attributesFilters = []; foreach ($attributes as $attribute) { @@ -197,6 +206,7 @@ public function fillAttributes(array $attributes) } $this->browser->find($this->nextButton)->click(); + $this->fillBulkImagesPriceAndQuantity($attributeSource, $attributes); $this->getTemplateBlock()->waitLoader(); $this->browser->find($this->nextButton)->click(); } @@ -469,4 +479,47 @@ protected function getTemplateBlock() ['element' => $this->_rootElement->find($this->templateBlock, Locator::SELECTOR_XPATH)] ); } + + /** + * Fill Step 3: Bulk Images, Price and Quantity. + * + * @param ConfigurableAttributesData $attributeSource + * @param array $attributes + * @return void + */ + private function fillBulkImagesPriceAndQuantity(ConfigurableAttributesData $attributeSource, array $attributes) + { + if (empty($attributeSource->getBulkImagesPriceQuantity())) { + return; + } + + $wizardStep = $this->browser->find($this->wizardImagesStep); + $data = $this->prepareImageStepData($attributeSource->getBulkImagesPriceQuantity(), $attributes); + $mapping = $this->dataMapping($data); + $this->_fill($mapping, $wizardStep); + } + + /** + * Prepare data for Step 3: Bulk Images, Price and Quantity. + * + * @param array $data + * @param array $attributes + * @return array + */ + private function prepareImageStepData(array $data, array $attributes) + { + if (isset($data['images'])) { + $data['images']['image_attribute'] = $attributes['attribute_key_0']['attribute_code']; + $data['images']['black_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']); + $data['images']['white_option_image'] = MTF_TESTS_PATH . array_shift($data['images']['images']); + unset($data['images']['images']); + } + + if (isset($data['price'])) { + $data['price']['price_option'] = $attributes['attribute_key_1']['attribute_code']; + ksort($data['price']); + } + + return $data; + } } diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.xml index 1890f6997a46c..ebea1c11727b2 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Block/Adminhtml/Product/Edit/Section/Variations/Config/Attribute.xml @@ -10,5 +10,61 @@ + + + #apply-unique-images-radio + css selector + radiobutton + + + #apply-images-attributes + css selector + select + + + //input[@name="image" and not(@id) and not(@class)] + xpath + upload + + + //input[@name="image" and not(@id) and not(@class)] + xpath + upload + + + + + #apply-unique-prices-radio + css selector + radiobutton + + + #select-each-price + css selector + select + + + #apply-single-price-input-0 + css selector + input + + + #apply-single-price-input-1 + css selector + input + + + + + #apply-single-inventory-radio + css selector + radiobutton + + + #apply-single-inventory-input + css selector + input + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductImages.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductImages.php new file mode 100644 index 0000000000000..d03efea45e376 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Constraint/AssertConfigurableProductImages.php @@ -0,0 +1,105 @@ +verifyBaseImage(); + $errors[] = $this->verifyOptionsImages(); + + return array_filter($errors); + } + + /** + * Verify correct base image is shown. + * + * @return null|string + */ + private function verifyBaseImage() + { + $message = null; + $data = $this->product->getData(); + + $displayedImage = $this->productView->getBaseImageSource(); + $this->displayedImages[] = $displayedImage; + + if ($this->areImagesDifferent($displayedImage, $data['image'][0]['file'])) { + $message = 'Product image is not correct.'; + } + + return $message; + } + + /** + * Verify displayed options images on product page are different. + * + * @return string|null + */ + protected function verifyOptionsImages() + { + $message = null; + $configurableAttributes = $this->product->getData('configurable_attributes_data')['attributes_data']; + $attribute = array_shift($configurableAttributes); + $customOptions = []; + + foreach ($attribute['options'] as $option) { + $customOptions[] = [ + 'type' => $attribute['frontend_input'], + 'title' => $attribute['frontend_label'], + 'value' => $option['label'] + ]; + } + + foreach ($customOptions as $customOption) { + $this->productView->getCustomOptionsBlock()->fillCustomOptions([$customOption]); + $displayedImage = $this->productView->getBaseImageSource(); + if (in_array($displayedImage, $this->displayedImages)) { + $message = 'Option image is not correct.'; + break; + } + + $this->displayedImages[] = $displayedImage; + } + + return $message; + } + + /** + * Compare images and return true if they are different. + * + * @param string $compared + * @param string $toCompare + * @return bool + */ + private function areImagesDifferent($compared, $toCompare) + { + preg_match('`/(\w*?)\.(\w*?)$`', $compared, $shownImage); + preg_match('`/(\w*?)\.(\w*?)$`', $toCompare, $expectedImage); + + return strpos($shownImage[1], $expectedImage[1]) === false || $expectedImage[2] !== $shownImage[2]; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct.xml index 3c344f79144f8..eac8fb16a3728 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct.xml @@ -37,7 +37,7 @@ - + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php index f0a998cffcf11..ef86367a8079b 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Fixture/ConfigurableProduct/ConfigurableAttributesData.php @@ -75,6 +75,13 @@ class ConfigurableAttributesData extends DataSource */ protected $products = []; + /** + * Values for Bulk Images Price and Quantity step. + * + * @var array + */ + private $bulkImagesPriceQuantity = []; + /** * @constructor * @param RepositoryFactory $repositoryFactory @@ -109,6 +116,7 @@ public function __construct( $this->prepareProducts($data); $this->prepareVariationsMatrix($data); $this->prepareData(); + $this->prepareBulkImagesPriceQuantity($data); } } @@ -366,17 +374,20 @@ protected function addVariationMatrix(array $variationsMatrix, array $attribute, $rowName = $row['name']; $rowSku = $row['sku']; $index = 1; - foreach ($attribute['options'] as $optionKey => $option) { - $compositeKey = "{$attributeKey}:{$optionKey}"; - $row['name'] = $rowName . ' ' . $randIsolation . ' ' . $index; - $row['sku'] = $rowSku . '_' . $randIsolation . '_' . $index; - $row['price'] = $option['pricing_value']; - if ($this->addMediaGallery) { - $row['media_gallery'] = $this->prepareMediaGallery(); + + if (isset($attribute['options'])) { + foreach ($attribute['options'] as $optionKey => $option) { + $compositeKey = "{$attributeKey}:{$optionKey}"; + $row['name'] = $rowName . ' ' . $randIsolation . ' ' . $index; + $row['sku'] = $rowSku . '_' . $randIsolation . '_' . $index; + $row['price'] = $option['pricing_value']; + if ($this->addMediaGallery) { + $row['media_gallery'] = $this->prepareMediaGallery(); + } + $newRowKey = $rowKey ? "{$rowKey} {$compositeKey}" : $compositeKey; + $result[$newRowKey] = $row; + $index++; } - $newRowKey = $rowKey ? "{$rowKey} {$compositeKey}" : $compositeKey; - $result[$newRowKey] = $row; - $index++; } } @@ -481,6 +492,19 @@ protected function prepareData() } } + /** + * Prepare Bulk Image Price and Quantity value. + * + * @param array $data + * @return void + */ + private function prepareBulkImagesPriceQuantity(array $data) + { + if (isset($data['bulk_images_price_quantity'])) { + $this->bulkImagesPriceQuantity = $data['bulk_images_price_quantity']; + } + } + /** * Get prepared attributes data. * @@ -501,6 +525,16 @@ public function getVariationsMatrix() return $this->variationsMatrix; } + /** + * Bulk Image Price and Quantity value. + * + * @return array + */ + public function getBulkImagesPriceQuantity() + { + return $this->bulkImagesPriceQuantity; + } + /** * Get prepared attributes. * diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct.xml index 869c6594cae5f..a4fa22e52a003 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct.xml @@ -278,6 +278,78 @@ + + Configurable product %isolation% + sku_configurable_product_%isolation% + This item has weight + 2 + Yes + Catalog, Search + + taxable_goods + + configurable-product-%isolation% + + color_3_items + + + In Stock + + + + default + + + + default_subcategory + + + default + + + 100 + + + + + Configurable product %isolation% + sku_configurable_product_%isolation% + This item has weight + 2 + Yes + Catalog, Search + + taxable_goods + + configurable-product-%isolation% + + color_3_items + + + In Stock + + + + default + + + + default_subcategory + + + default + + + two_fixed_drop_down_options + + + 100 + + + configurable_option_3_and_custom_option_2 + + + Test configurable product with color and size %isolation% sku_test_configurable_product_%isolation% diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml index c6a0753b0223a..003c129c9f969 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/CheckoutData.xml @@ -428,6 +428,28 @@ + + + + + attribute_key_0 + option_key_2 + + + + + attribute_key_0 + option_key_1 + + + + + 32 + 1 + 32 + + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml index 048313d451f47..ee4fd90464d32 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Repository/ConfigurableProduct/ConfigurableAttributesData.xml @@ -585,6 +585,117 @@ + + + + + + 10.00 + Yes + + + 20.00 + Yes + + + 30.00 + Yes + + + + + + catalogProductAttribute::color_for_promo_rules + + + + 100 + 1 + + + 100 + 1 + + + 100 + 1 + + + + + + + + + + 10.00 + Yes + + + 10.00 + Yes + + + + + + + 10.00 + Yes + + + 10.00 + Yes + + + + + + catalogProductAttribute::color + catalogProductAttribute::size + + + + 6 + 100 + 1 + + + 8 + 100 + 1 + + + 6 + 100 + 1 + + + 8 + 100 + 1 + + + + + + + Magento/Catalog/Test/_files/test2.png + Magento/Catalog/Test/_files/test3.png + + + + + 6 + 8 + + + + 10000 + + + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml index 1a4eac869f10d..089de48d19de9 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateConfigurableProductEntityTest.xml @@ -227,5 +227,18 @@ + + color_and_size_with_images + Configurable Product %isolation% + configurable_sku_%isolation% + 6 + 2 + configurable-product-%isolation% + Magento/Catalog/Test/_files/test1.png + default_subcategory + + + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.php new file mode 100644 index 0000000000000..73f4265c166bc --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.php @@ -0,0 +1,38 @@ + Catalog. + * 3. Search and open child of configurable product from preconditions. + * 4. Fill in data according to dataset. + * 5. Save product. + * 6. Perform all assertions. + * + * @group Configurable_Product + * @ZephyrId MAGETWO-60196, MAGETWO-60206, MAGETWO-60236, MAGETWO-60296, MAGETWO-60297, MAGETWO-60325, MAGETWO-60328, + * MAGETWO-60329, MAGETWO-60330 + */ +class VerifyConfigurableProductEntityPriceTest extends Scenario +{ + /** + * Verify configurable product price. + * + * @return array + */ + public function test() + { + $this->executeScenario(); + } +} diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.xml new file mode 100644 index 0000000000000..7aa4a6e14066c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/VerifyConfigurableProductEntityPriceTest.xml @@ -0,0 +1,125 @@ + + + + + + configurableProduct::product_with_color + + + No + + + 1 + + + + + configurableProduct::product_with_color + + + + Out of Stock + + + + 1 + + + + + MAGETWO-66699: Configurable product when all child products are disabled + configurableProduct::product_with_color + + + No + + + 1,2,3 + + + + + + configurableProduct::product_with_color + + + + custom_for_qty_1 + + + + 2 + 5 + + + + + configurableProduct::product_with_color + + + 5 + + + 2 + 5 + + + + + configurableProduct::product_with_color + + + 0.07 + + + true + 2 + 0.07 + + + + + configurableProduct::product_with_color + 2 + + Main Website + + + + + + configurableProduct::product_with_color + 1,2,3 + + + + Out of Stock + + + + + + + + + configurableProduct::product_with_color_and_custom_option + 2 + + + + custom_for_qty_1 + + + + 5 + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestStep/UpdateChildProductStep.php b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestStep/UpdateChildProductStep.php new file mode 100644 index 0000000000000..ee1d34e119ada --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestStep/UpdateChildProductStep.php @@ -0,0 +1,185 @@ +product = $product; + $this->productGrid = $productGrid; + $this->productEdit = $productEdit; + $this->fixtureFactory = $fixtureFactory; + $this->productUpdate = $productUpdate; + } + + /** + * Update child of configurable product. + * + * @return array + */ + public function run() + { + $items = explode(',', $this->productUpdate['optionNumber']); + + foreach ($items as $itemIndex) { + $index = (int)$itemIndex - 1; + $optionKey = 'option_key_' . $index; + $matrixIndex = $this->attributeKey . ':' . $optionKey; + $sku = $this->product->getConfigurableAttributesData()['matrix'][$matrixIndex]['sku']; + $this->fillChildProductData($sku); + $this->prepareResultProduct($matrixIndex, $optionKey); + } + + return ['product' => $this->product]; + } + + /** + * Prepare configurable product fixture. + * + * @param string $matrixIndex + * @param string $optionKey + * @return void + */ + private function prepareResultProduct($matrixIndex, $optionKey) + { + $product = $this->product->getData(); + $attributeKey = 'configurable_attributes_data'; + + if (isset($this->productUpdate['newPrice'])) { + $product[$attributeKey]['matrix'][$matrixIndex]['price'] = $this->productUpdate['newPrice']; + $product[$attributeKey]['attributes_data'][$this->attributeKey]['options'][$optionKey]['pricing_value'] + = $this->productUpdate['newPrice']; + } else { + unset($product[$attributeKey]['matrix'][$matrixIndex]); + unset($product[$attributeKey]['attributes_data'][$this->attributeKey]['options'][$optionKey]); + } + + $product['category_ids']['category'] + = $this->product->getDataFieldConfig('category_ids')['source']->getCategories()[0]; + $product['price'] = $this->getLowestConfigurablePrice($product); + + if (!empty($product['configurable_attributes_data']['attributes_data'][$this->attributeKey]['options'])) { + $this->product = $this->fixtureFactory->createByCode('configurableProduct', ['data' => $product]); + } + } + + /** + * Fill data of child product. + * + * @param string $sku + * @return void + */ + private function fillChildProductData($sku) + { + $this->productGrid->open(); + $this->productGrid->getProductGrid()->searchAndOpen(['sku' => $sku]); + + if (isset($this->productUpdate['switchScope']) && $this->productUpdate['switchScope']) { + $store = $this->fixtureFactory->createByCode('store', ['dataset' => 'default']); + $this->productEdit->getFormPageActions()->changeStoreViewScope($store); + } + + if (isset($this->productUpdate['childProductUpdate']['unassignFromWebsite'])) { + $this->productEdit->getProductForm()->unassignFromWebsite( + $this->productUpdate['childProductUpdate']['unassignFromWebsite'] + ); + } else { + $fixture = $this->fixtureFactory->createByCode( + 'catalogProductSimple', + $this->productUpdate['childProductUpdate'] + ); + $this->productEdit->getProductForm()->fill($fixture); + } + + $this->productEdit->getFormPageActions()->save(); + } + + /** + * Returns lowest possible price of configurable product. + * + * @param array $product + * @return string + */ + private function getLowestConfigurablePrice(array $product) + { + $configurableOptions = $product['configurable_attributes_data']; + $attributeOption = reset($configurableOptions['matrix']); + $price = isset($attributeOption['price']) ? $attributeOption['price'] : "0"; + + foreach ($configurableOptions['matrix'] as $option) { + if ($price > $option['price']) { + $price = $option['price']; + } + } + + return $price; + } +} diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/testcase.xml index 075a18aad1ccf..7df8c421fedd1 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/testcase.xml @@ -6,11 +6,15 @@ */ --> - - - - - - - + + + + + + + + + + +