/** * Choose affected attribute set * * @param ConfigurableProduct $fixture */ public function chooseAttributeSet(ConfigurableProduct $fixture) { $attributeSetName = $fixture->getAffectedAttributeSet(); if ($attributeSetName) { $this->_rootElement->find($this->affectedAttributeSet)->click(); $this->_rootElement->find($this->attributeSetName)->setValue($attributeSetName); } $this->_rootElement->find($this->confirmButton)->click(); }
/** * Get variations data for curl * * @param ConfigurableProduct $fixture * @return array */ protected function _getVariationMatrix(ConfigurableProduct $fixture) { $config = $fixture->getDataConfig(); $variationData = $fixture->getData('fields/variations-matrix/value'); $curlData = array(); $variationNumber = 0; foreach ($config['options'] as $attributeId => $options) { foreach ($options['id'] as $option) { foreach ($variationData[$variationNumber]['value'] as $fieldName => $fieldData) { if ($fieldName == 'qty') { $curlData[$option]['quantity_and_stock_status'][$fieldName] = $fieldData['value']; } else { $curlData[$option][$fieldName] = $fieldData['value']; } } if (!isset($curlData[$option]['weight']) && $fixture->getData('fields/weight/value')) { $curlData[$option]['weight'] = $fixture->getData('fields/weight/value'); } $curlData[$option]['configurable_attribute'] = '{"' . $config['attributes'][$attributeId]['code'] . '":"' . $option . '"}'; ++$variationNumber; } } return $curlData; }
/** * Assert configurable product on Frontend * * @param ConfigurableProduct $product * @return void */ protected function assertOnFrontend(ConfigurableProduct $product) { //Pages $frontendHomePage = Factory::getPageFactory()->getCmsIndexIndex(); $categoryPage = Factory::getPageFactory()->getCatalogCategoryView(); $productPage = Factory::getPageFactory()->getCatalogProductView(); //Steps $frontendHomePage->open(); $frontendHomePage->getTopmenu()->selectCategoryByName($product->getCategoryName()); //Verification on category product list $productListBlock = $categoryPage->getListProductBlock(); $this->assertTrue($productListBlock->isProductVisible($product->getName()), 'Product is absent on category page.'); //Verification on product detail page $productViewBlock = $productPage->getViewBlock(); $productListBlock->openProductViewPage($product->getName()); $this->assertEquals($product->getName(), $productViewBlock->getProductName(), 'Product name does not correspond to specified.'); $price = $product->getProductPrice(); $blockPrice = $productViewBlock->getProductPrice(); $this->assertEquals(number_format($price, 2), number_format($blockPrice['price_regular_price'], 2), 'Product price does not correspond to specified.'); $this->assertTrue($productViewBlock->verifyProductOptions($product), 'Added configurable options are absent'); }
/** * Verify configurable product options * * @param ConfigurableProduct $product * @return bool */ public function verifyProductOptions(ConfigurableProduct $product) { $attributes = $product->getConfigurableOptions(); foreach ($attributes as $attributeName => $attribute) { foreach ($attribute as $optionName) { $option = $this->_rootElement->find('//*[*[@class="field configurable required"]//span[text()="' . $attributeName . '"]]//select/option[contains(text(), "' . $optionName . '")]', Locator::SELECTOR_XPATH); if (!$option->isVisible()) { return false; } } } return true; }
/** * Fill product variations * * @param ConfigurableProduct $variations * @return void */ public function fillVariations(ConfigurableProduct $variations) { $variationsBlock = $this->getVariationsBlock(); $variationsBlock->fillAttributeOptions($variations->getConfigurableAttributes()); $variationsBlock->generateVariations(); $variationsBlock->fillVariationsMatrix($variations->getVariationsMatrix()); }