示例#1
0
 /**
  * Fill in the option specified for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     if ($product instanceof InjectableFixture) {
         /** @var ConfigurableProductInjectable $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']];
             }
         }
     } else {
         // TODO: Removed after refactoring(removed) old product fixture.
         /** @var ConfigurableProduct $product */
         $attributesData = $product->getConfigurableAttributes();
         $checkoutData = $product->getCheckoutData();
         // Prepare attributes data
         foreach ($attributesData as $attributeKey => $attribute) {
             $attributesData[$attributeKey] = ['type' => 'dropdown', 'title' => $attribute['label']['value']];
             unset($attribute['label']);
             foreach ($attribute as $optionKey => $option) {
                 $attributesData[$attributeKey]['options'][$optionKey] = ['title' => $option['option_label']['value']];
             }
         }
     }
     $configurableCheckoutData = isset($checkoutData['configurable_options']) ? $checkoutData['configurable_options'] : [];
     $checkoutOptionsData = $this->prepareCheckoutData($attributesData, $configurableCheckoutData);
     $this->getCustomOptionsBlock()->fillCustomOptions($checkoutOptionsData);
     parent::fillOptions($product);
 }
 /**
  * Assert prices on the shopping cart
  *
  * @param FixtureInterface $product
  * @param CheckoutCart $checkoutCart
  * @return void
  */
 protected function assertOnShoppingCart(FixtureInterface $product, CheckoutCart $checkoutCart)
 {
     $customOptions = $product->getCustomOptions();
     $checkoutData = $product->getCheckoutData();
     $checkoutCustomOptions = isset($checkoutData['custom_options']) ? $checkoutData['custom_options'] : [];
     $fixturePrice = $product->getPrice();
     $groupPrice = $product->getGroupPrice();
     $specialPrice = $product->getSpecialPrice();
     $cartItem = $checkoutCart->getCartBlock()->getCartItem($product);
     $formPrice = $cartItem->getPrice();
     if ($groupPrice) {
         $groupPrice = reset($groupPrice);
         $fixturePrice = $groupPrice['price'];
     }
     if ($specialPrice) {
         $fixturePrice = $specialPrice;
     }
     $fixtureActualPrice = $fixturePrice;
     foreach ($checkoutCustomOptions as $checkoutOption) {
         $attributeKey = $checkoutOption['title'];
         $optionKey = $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(number_format($fixtureActualPrice, 2), $formPrice, 'Product price in shopping cart is not correct.');
 }
示例#3
0
 /**
  * @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'] = isset($cartItem['options']) ? $cartItem['options'] + $checkoutCustomOptions : $checkoutCustomOptions;
     $this->data = $cartItem;
 }
示例#4
0
 /**
  * Fill specified option for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     /** @var DownloadableProductInjectable $product */
     $productData = $product->getData();
     $downloadableLinks = isset($productData['downloadable_links']['downloadable']['link']) ? $productData['downloadable_links']['downloadable']['link'] : [];
     $data = $product->getCheckoutData()['options'];
     // Replace link key to label
     foreach ($data['links'] as $key => $linkData) {
         $linkKey = str_replace('link_', '', $linkData['label']);
         $linkData['label'] = isset($downloadableLinks[$linkKey]['title']) ? $downloadableLinks[$linkKey]['title'] : $linkData['label'];
         $data['links'][$key] = $linkData;
     }
     $this->getDownloadableLinksBlock()->fill($data['links']);
     parent::fillOptions($product);
 }
示例#5
0
 /**
  * Fill options for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     $productOptions = $product->getCheckoutData();
     if (!empty($productOptions['configurable_options'])) {
         $configurableAttributesData = $product->getData('fields/configurable_attributes_data/value');
         $checkoutData = [];
         foreach ($productOptions['configurable_options'] as $optionData) {
             $titleKey = $optionData['title'];
             $valueKey = $optionData['value'];
             $checkoutData[] = ['title' => $configurableAttributesData[$titleKey]['label']['value'], 'value' => $configurableAttributesData[$titleKey][$valueKey]['option_label']['value']];
         }
         foreach ($checkoutData as $option) {
             $select = $this->_rootElement->find('//div[@class="product-options"]//label[text()="' . $option['title'] . '"]//following-sibling::*//select', Locator::SELECTOR_XPATH, 'select');
             $select->setValue($option['value']);
         }
         $this->_rootElement->find('.ui-dialog-buttonset button:nth-of-type(2)')->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 ConfigurableProductInjectable) {
         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['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;
 }
示例#7
0
 /**
  * Fill in the option specified for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     $dataConfig = $product->getDataConfig();
     $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null;
     /** @var CatalogProductSimple $product */
     if ($this->hasRender($typeId)) {
         $this->callRender($typeId, 'fillOptions', ['product' => $product]);
     } else {
         $optionsCheckoutData = [];
         if ($product instanceof InjectableFixture) {
             /** @var CatalogProductSimple $product */
             $customOptions = $product->hasData('custom_options') ? $product->getDataFieldConfig('custom_options')['source']->getCustomOptions() : [];
             $checkoutData = $product->getCheckoutData();
             $productCheckoutData = isset($checkoutData['custom_options']) ? $checkoutData['custom_options'] : [];
             $optionsCheckoutData = $this->prepareCheckoutData($customOptions, $productCheckoutData);
         }
         $this->getCustomOptionsBlock()->fillCustomOptions($optionsCheckoutData);
     }
 }
示例#8
0
 /**
  * Fill in the option specified for the product
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fillOptions(FixtureInterface $product)
 {
     if ($product instanceof InjectableFixture) {
         /** @var \Magento\Bundle\Test\Fixture\CatalogProductBundle $product */
         $checkoutData = $product->getCheckoutData();
         $bundleCheckoutData = isset($checkoutData['bundle_options']) ? $checkoutData['bundle_options'] : [];
     } else {
         // TODO: Removed after refactoring(removed) old product fixture.
         /** @var \Magento\Bundle\Test\Fixture\BundleFixed $product */
         $bundleCheckoutData = $product->getSelectionData();
     }
     $this->_rootElement->find($this->customizeButton)->click();
     $this->getBundleBlock()->fillBundleOptions($bundleCheckoutData);
     parent::fillOptions($product);
 }
示例#9
0
 /**
  * Fill product options on view page
  *
  * @param FixtureInterface $product
  * @return void
  */
 public function fill(FixtureInterface $product)
 {
     /** @var GroupedProductInjectable $product */
     $associatedProducts = $product->getAssociated()['products'];
     $data = $product->getCheckoutData()['options'];
     // Replace link key to label
     foreach ($data as $key => $productData) {
         $productKey = str_replace('product_key_', '', $productData['name']);
         $data[$key]['name'] = $associatedProducts[$productKey]->getName();
     }
     // Fill
     foreach ($data as $productData) {
         $subProduct = $this->_rootElement->find(sprintf($this->subProductByName, $productData['name']), Locator::SELECTOR_XPATH);
         $subProduct->find($this->qty)->setValue($productData['qty']);
     }
 }