/** * Assert prices on the shopping cart * * @param FixtureInterface $product * @param CheckoutCart $checkoutCart * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart) { $checkoutCart->open(); /** @var CatalogProductSimple $product */ $customOptions = $product->getCustomOptions(); $checkoutData = $product->getCheckoutData(); $checkoutCartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; $fixturePrice = $product->getPrice(); $specialPrice = $product->getSpecialPrice(); $cartItem = $checkoutCart->getCartBlock()->getCartItem($product); $formPrice = $cartItem->getPrice(); if ($specialPrice) { $fixturePrice = $specialPrice; } if (isset($checkoutCartItem['price'])) { $fixturePrice = $checkoutCartItem['price']; } $fixtureActualPrice = $fixturePrice; foreach ($checkoutCustomOptions as $checkoutOption) { $attributeKey = str_replace('attribute_key_', '', $checkoutOption['title']); $optionKey = str_replace('option_key_', '', $checkoutOption['value']); $option = $customOptions[$attributeKey]['options'][$optionKey]; if ('Fixed' == $option['price_type']) { $fixtureActualPrice += $option['price']; } else { $fixtureActualPrice += $fixturePrice / 100 * $option['price']; } } \PHPUnit_Framework_Assert::assertEquals($fixtureActualPrice, $formPrice, 'Product price in shopping cart is not correct.'); }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void */ public function configProduct(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $this->fillOptions($product); if (isset($checkoutData['qty'])) { $this->setQty($checkoutData['qty']); } $this->clickOk(); }
/** * Prepare options * * @param FixtureInterface $product * @return array */ protected function prepareOptions(FixtureInterface $product) { $productOptions = []; $checkoutData = $product->getCheckoutData()['options']; $customOptions = $product->getCustomOptions(); if (isset($checkoutData['custom_options'])) { foreach ($checkoutData['custom_options'] as $option) { $optionKey = str_replace('attribute_key_', '', $option['title']); $valueKey = str_replace('option_key_', '', $option['value']); $productOptions[] = ['option_name' => $customOptions[$optionKey]['title'], 'value' => isset($customOptions[$optionKey]['options'][$valueKey]['title']) ? $customOptions[$optionKey]['options'][$valueKey]['title'] : $valueKey]; } } return $productOptions; }
/** * Prepare options * * @param FixtureInterface $product * @return array */ protected function prepareOptions(FixtureInterface $product) { /** @var GroupedProduct $product */ $productOptions = []; $checkoutData = $product->getCheckoutData()['options']; if (count($checkoutData)) { $associated = $product->getAssociated(); foreach ($checkoutData as $optionData) { $productKey = str_replace('product_key_', '', $optionData['name']); $productOptions[] = ['option_name' => $associated['assigned_products'][$productKey]['name'], 'value' => $optionData['qty']]; } } return $productOptions; }
/** * Get configurable product price * * @param FixtureInterface $product * @throws \Exception * @return int */ protected function getProductPrice(FixtureInterface $product) { $price = $product->getPrice(); if (!$this->productsIsConfigured) { return $price; } if (!$product instanceof ConfigurableProduct) { throw new \Exception("Product '{$product->getName}()' is not configurable product."); } $checkoutData = $product->getCheckoutData(); if ($checkoutData === null) { return 0; } return $price; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $cartItem = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $customOptions = $product->hasData('custom_options') ? $product->getCustomOptions() : []; $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; foreach ($checkoutCustomOptions as $key => $checkoutCustomOption) { $attribute = str_replace('attribute_key_', '', $checkoutCustomOption['title']); $option = str_replace('option_key_', '', $checkoutCustomOption['value']); $checkoutCustomOptions[$key] = ['title' => isset($customOptions[$attribute]['title']) ? $customOptions[$attribute]['title'] : $attribute, 'value' => isset($customOptions[$attribute]['options'][$option]['title']) ? $customOptions[$attribute]['options'][$option]['title'] : $option]; } $cartItem['options'] = $checkoutCustomOptions; $cartItem['qty'] = isset($checkoutData['qty']) ? $checkoutData['qty'] : 1; $this->data = $cartItem; }
/** * Fill specified option for the product * * @param FixtureInterface $product * @return void */ public function fillOptions(FixtureInterface $product) { /** @var DownloadableProduct $product */ $productData = $product->getData(); $downloadableLinks = isset($productData['downloadable_links']['downloadable']['link']) ? $productData['downloadable_links']['downloadable']['link'] : []; $checkoutData = $product->getCheckoutData(); if (isset($checkoutData['options'])) { // Replace link key to label foreach ($checkoutData['options']['links'] as $key => $linkData) { $linkKey = str_replace('link_', '', $linkData['label']); $linkData['label'] = isset($downloadableLinks[$linkKey]['title']) ? $downloadableLinks[$linkKey]['title'] : $linkData['label']; $checkoutData['options']['links'][$key] = $linkData; } $this->getDownloadableLinksBlock()->fill($checkoutData['options']['links']); } }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void * * @SuppressWarnings(PHPMD.NPathComplexity) */ public function fillOptions(FixtureInterface $product) { $dataConfig = $product->getDataConfig(); $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; $checkoutData = null; /** @var CatalogProductSimple $product */ if ($this->hasRender($typeId)) { $this->callRender($typeId, 'fillOptions', ['product' => $product]); } /** @var CatalogProductSimple $product */ $checkoutData = $product->getCheckoutData(); $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : []; $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : []; $checkoutCustomOptions = $this->prepareCheckoutData($customOptions, $checkoutCustomOptions); $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions); }
/** * Select order item. * * @param FixtureInterface $product * @return void */ public function selectItem(FixtureInterface $product) { /** @var BundleProduct $product */ $checkoutData = $product->getCheckoutData(); $bundleSelection = $product->getBundleSelections(); $bundleOptions = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : []; $labels = []; foreach ($bundleOptions as $optionKey => $option) { $optionKey = substr($optionKey, -1); $productKey = substr($option['value']['name'], -1); $labels[] = $bundleSelection[$optionKey]['assigned_products'][$productKey]['name']; } $this->searchAndSelect(['name' => $product->getName()]); $this->getTemplateBlock()->waitLoader(); $this->getSelectItemsBlock()->fill($labels); $this->getTemplateBlock()->waitLoader(); }
/** * Fill in the option specified for the product * * @param FixtureInterface $product * @return void */ public function fillOptions(FixtureInterface $product) { /** @var ConfigurableProduct $product */ $attributesData = $product->getConfigurableAttributesData()['attributes_data']; $checkoutData = $product->getCheckoutData(); // Prepare attribute data foreach ($attributesData as $attributeKey => $attribute) { $attributesData[$attributeKey] = ['type' => $attribute['frontend_input'], 'title' => $attribute['label'], 'options' => []]; foreach ($attribute['options'] as $optionKey => $option) { $attributesData[$attributeKey]['options'][$optionKey] = ['title' => $option['label']]; } $attributesData[$attributeKey]['options'] = array_values($attributesData[$attributeKey]['options']); } $attributesData = array_values($attributesData); $configurableCheckoutData = isset($checkoutData['options']['configurable_options']) ? $checkoutData['options']['configurable_options'] : []; $checkoutOptionsData = $this->prepareCheckoutData($attributesData, $configurableCheckoutData); $this->getCustomOptionsBlock()->fillCustomOptions($checkoutOptionsData); parent::fillOptions($product); }
/** * Fill product options on view page. * * @param FixtureInterface $product * @return void */ public function fill(FixtureInterface $product) { /** @var GroupedProduct $product */ $associatedProducts = $product->getAssociated()['products']; $checkoutData = $product->getCheckoutData(); if (isset($checkoutData['options'])) { // Replace link key to label foreach ($checkoutData['options'] as $key => $productData) { $productKey = str_replace('product_key_', '', $productData['name']); $checkoutData['options'][$key]['name'] = $associatedProducts[$productKey]->getName(); } // Fill foreach ($checkoutData['options'] as $productData) { $this->browser->selectWindow(); $subProduct = $this->_rootElement->find(sprintf($this->subProductByName, $productData['name']), Locator::SELECTOR_XPATH); $subProduct->find($this->qty)->setValue($productData['qty']); $this->_rootElement->click(); } } }
/** * Get configurable product price * * @param FixtureInterface $product * @throws \Exception * @return int */ protected function getProductPrice(FixtureInterface $product) { $price = $product->getPrice(); if (!$this->productsIsConfigured) { return $price; } if (!$product instanceof ConfigurableProduct) { throw new \Exception("Product '{$product->getName}()' is not configurable product."); } $checkoutData = $product->getCheckoutData(); if ($checkoutData === null) { return 0; } $attributesData = $product->getConfigurableAttributesData()['attributes_data']; foreach ($checkoutData['options']['configurable_options'] as $option) { $itemOption = $attributesData[$option['title']]['options'][$option['value']]; $itemPrice = $itemOption['is_percent'] == 'No' ? $itemOption['pricing_value'] : $product->getPrice() / 100 * $itemOption['pricing_value']; $price += $itemPrice; } return $price; }
/** * @constructor * @param FixtureInterface $product */ public function __construct(FixtureInterface $product) { /** @var GroupedProduct $product */ $checkoutData = $product->getCheckoutData(); $this->data = isset($checkoutData['cartItem']) ? $checkoutData['cartItem'] : []; $associatedProducts = []; $cartItem = []; foreach ($product->getAssociated()['products'] as $key => $product) { $key = 'product_key_' . $key; $associatedProducts[$key] = $product; } // Replace key in checkout data foreach ($this->data as $fieldName => $fieldValues) { foreach ($fieldValues as $key => $value) { $product = $associatedProducts[$key]; $cartItem[$fieldName][$product->getSku()] = $value; } } // Add empty "options" field foreach ($associatedProducts as $product) { $cartItem['options'][] = ['title' => $product->getName(), 'value' => $cartItem['qty'][$product->getSku()]]; } $this->data = $cartItem; }
/** * Prepare data for simple product. * * @param FixtureInterface $product * @return array */ protected function prepareSimpleData(FixtureInterface $product) { return ['qty' => $product->getCheckoutData()['qty']]; }
/** * Fill in the option specified for the product. * * @param FixtureInterface $product * @return void */ public function fillOptions(FixtureInterface $product) { /** @var \Magento\Bundle\Test\Fixture\BundleProduct $product */ $checkoutData = $product->getCheckoutData(); $bundleCheckoutData = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : []; if (!$this->getBundleBlock()->isVisible()) { $this->clickCustomize(); } $this->getBundleBlock()->fillBundleOptions($bundleCheckoutData); }
/** * Get product price. * * @param FixtureInterface $product * @return int */ protected function getProductPrice(FixtureInterface $product) { return isset($product->getCheckoutData()['cartItem']['price']) ? $product->getCheckoutData()['cartItem']['price'] : $product->getPrice(); }