Beispiel #1
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $attributesData = $product->getConfigurableAttributesData()['attributes_data'];
         $matrix = $product->getConfigurableAttributesData()['matrix'];
         $checkoutOptions = $product->getCheckoutData()['options']['configurable_options'];
         $optionsDetails = [];
         $matrixKey = [];
         $optionsPrice = 0;
         foreach ($checkoutOptions as $checkoutOption) {
             $titleKey = $checkoutOption['title'];
             $valueKey = $checkoutOption['value'];
             $attributeName = $attributesData[$titleKey]['frontend_label'];
             $optionLabel = $attributesData[$titleKey]['options'][$valueKey]['label'];
             $optionsDetails[] = "{$attributeName}{$optionLabel}";
             $matrixKey[] = "{$titleKey}:{$valueKey}";
             $optionsPrice += $attributesData[$titleKey]['options'][$valueKey]['pricing_value'];
         }
         $optionsDetails = implode(' ', $optionsDetails);
         $matrixKey = implode(' ', $matrixKey);
         $productDisplay = $productName . 'SKU: ' . $matrix[$matrixKey]['sku'] . $optionsDetails;
     } else {
         $productDisplay = $productName . 'SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->escapeCurrency($this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText());
 }
Beispiel #2
0
 /**
  * Check out with PayPal.
  *
  * @param InjectableFixture $product
  * @return void
  */
 public function paypalCheckout(InjectableFixture $product)
 {
     /** @var CatalogProductSimple $product */
     $checkoutData = $product->getCheckoutData();
     if (isset($checkoutData['options'])) {
         $this->fillOptions($product);
     }
     if (isset($checkoutData['qty'])) {
         $this->setQty($checkoutData['qty']);
     }
     $this->_rootElement->find($this->paypalCheckout)->click();
 }
Beispiel #3
0
 /**
  * Filling the options specified for the product.
  *
  * @param InjectableFixture $product
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function fillOptions(InjectableFixture $product)
 {
     /** @var DownloadableProduct $product */
     $downloadableLinks = isset($product->getDownloadableLinks()['downloadable']['link']) ? $product->getDownloadableLinks()['downloadable']['link'] : [];
     $checkoutData = $product->getCheckoutData();
     if (isset($checkoutData['options'])) {
         foreach ($checkoutData['options']['links'] as $key => $linkData) {
             $linkKey = str_replace('link_', '', $linkData['label']);
             $linkData['label'] = $downloadableLinks[$linkKey]['title'];
             $checkoutData['options']['links'][$key] = $linkData;
         }
         $this->getDownloadableLinksBlock()->fill($checkoutData['options']['links']);
     }
     parent::fillOptions($product);
 }
 /**
  * Get configurable product price.
  *
  * @param InjectableFixture $product
  * @return int
  */
 protected function getProductPrice(InjectableFixture $product)
 {
     $price = $product->getPrice();
     if (!$this->productsIsConfigured) {
         return $price;
     }
     $checkoutData = $product->getCheckoutData();
     if ($checkoutData === null) {
         return 0;
     }
     $attributesData = $product->getConfigurableOptions()['attributes_data'];
     foreach ($checkoutData['options']['configurable_options'] as $option) {
         $itemOption = $attributesData[$option['title']]['options'][$option['value']];
         $price += $itemOption['price_type'] == 'Fixed' ? $itemOption['price'] : $product->getPrice() / 100 * $itemOption['price'];
     }
     return $price;
 }
 /**
  * Fill in the option specified for the product.
  *
  * @param InjectableFixture $product
  * @return void
  */
 public function fillOptions(InjectableFixture $product)
 {
     /** @var ConfigurableProduct $product */
     $attributesData = $product->getConfigurableOptions()['attributes_data'];
     $checkoutData = $product->getCheckoutData();
     // Prepare attribute data
     foreach ($attributesData as $attributeKey => $attribute) {
         $attributesData[$attributeKey] = ['type' => $attribute['frontend_input'], 'title' => $attribute['frontend_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->getConfigurableOptionsBlock()->fillOptions($checkoutOptionsData);
 }
Beispiel #6
0
 /**
  * Returns the item price for the specified product.
  *
  * @param InjectableFixture $product
  * @return array|string
  */
 public function getPrice(InjectableFixture $product)
 {
     $productName = $product->getName();
     if ($product instanceof ConfigurableProduct) {
         // Find the price for the specific configurable product that was purchased
         $configurableAttributes = $product->getConfigurableAttributes();
         $productOptions = $product->getCheckoutData()['options']['configurable_options'];
         $checkoutOption = reset($productOptions);
         $attributeKey = $checkoutOption['title'];
         $optionKey = $checkoutOption['value'];
         $attributeValue = $configurableAttributes[$attributeKey]['label']['value'];
         $optionValue = $configurableAttributes[$attributeKey][$optionKey]['option_label']['value'];
         $productDisplay = $productName . ' SKU: ' . $product->getVariationSku($checkoutOption);
         $productDisplay .= ' ' . $attributeValue . ' ' . $optionValue;
     } else {
         $productDisplay = $productName . ' SKU: ' . $product->getSku();
     }
     $selector = '//tr[normalize-space(td)="' . $productDisplay . '"]' . $this->priceSelector;
     return $this->_rootElement->find($selector, Locator::SELECTOR_XPATH)->getText();
 }
Beispiel #7
0
 /**
  * Add product to Wishlist.
  *
  * @param InjectableFixture $product
  * @return void
  */
 public function addToWishlist(InjectableFixture $product)
 {
     $checkoutData = $product->getCheckoutData();
     $this->fillOptions($product);
     if (isset($checkoutData['qty'])) {
         $this->setQty($checkoutData['qty']);
     }
     $this->clickAddToWishlist();
 }
 /**
  * Fill grouped product options.
  *
  * @param InjectableFixture $product
  * @return void
  */
 public function fillOptions(InjectableFixture $product)
 {
     $checkoutData = $checkoutData = $product->getCheckoutData();
     $associatedProducts = $product->getAssociated();
     if (isset($checkoutData['options'])) {
         $groupedBlock = $this->getGroupedProductBlock();
         foreach ($checkoutData['options'] as $key => $option) {
             $groupedBlock->getGroupedItemForm($associatedProducts[$key]['name'])->fillOption($option);
         }
     }
 }
Beispiel #9
0
 /**
  * Fill in the option specified for the product.
  *
  * @param InjectableFixture $product
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function fillOptions(InjectableFixture $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();
     if (!isset($checkoutData['options']['custom_options'])) {
         return;
     }
     $customOptions = $product->getCustomOptions();
     if (isset($customOptions)) {
         $checkoutCustomOptions = $this->prepareCheckoutData($customOptions, $checkoutData['options']['custom_options']);
         $this->getCustomOptionsBlock()->fillCustomOptions($checkoutCustomOptions);
     }
 }
 /**
  * Prepare product price from fixture.
  *
  * @param InjectableFixture $product
  * @return float
  */
 protected function prepareFixturePrice(InjectableFixture $product)
 {
     /** @var CatalogProductSimple $product */
     $customOptions = $product->getCustomOptions();
     $checkoutData = $product->getCheckoutData();
     $checkoutCustomOptions = isset($checkoutData['options']['custom_options']) ? $checkoutData['options']['custom_options'] : [];
     if (isset($checkoutData['cartItem'])) {
         $fixturePrice = $checkoutData['cartItem']['price'];
     } else {
         $fixturePrice = $product->getPrice();
         $groupPrice = $product->getGroupPrice();
         $specialPrice = $product->getSpecialPrice();
         if ($groupPrice) {
             $groupPrice = reset($groupPrice);
             $fixturePrice = $groupPrice['price'];
         }
         if ($specialPrice) {
             $fixturePrice = $specialPrice;
         }
         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']) {
                 $fixturePrice += $option['price'];
             } else {
                 $fixturePrice += $fixturePrice / 100 * $option['price'];
             }
         }
     }
     return $fixturePrice;
 }
 /**
  * Get default item data.
  *
  * @param InjectableFixture $product
  * @param array|null $verifyData
  * @return array
  */
 protected function getDefaultItemData(InjectableFixture $product, array $verifyData = null)
 {
     /** @var CatalogProductSimple $product */
     $checkoutData = $product->getCheckoutData();
     $defaultData['item_qty'] = isset($verifyData['qty']) ? $verifyData['qty'] : $checkoutData['qty'];
     $defaultData = array_merge($defaultData, $this->getProductData($product));
     return $defaultData;
 }
 /**
  * Get checkout data options.
  *
  * @param InjectableFixture $product
  * @param string $optionKey
  * @return array
  */
 protected function getCheckoutDataOptions(InjectableFixture $product, $optionKey = '')
 {
     $checkoutData = $product->getCheckoutData();
     return $optionKey == '' ? isset($checkoutData['options']) ? $checkoutData['options'] : [] : (isset($checkoutData['options'][$optionKey]) ? $checkoutData['options'][$optionKey] : []);
 }
 /**
  * Fill checkout data.
  *
  * @param InjectableFixture $product
  * @return void
  */
 protected function fillCheckoutData(InjectableFixture $product)
 {
     $qty = $product->getCheckoutData()['qty'];
     $this->catalogProductView->getViewBlock()->fillOptions($product);
     $this->catalogProductView->getViewBlock()->setQty($qty);
 }
 /**
  * Get product price.
  *
  * @param InjectableFixture $product
  * @return int
  */
 protected function getProductPrice(InjectableFixture $product)
 {
     return isset($product->getCheckoutData()['cartItem']['price']) ? $product->getCheckoutData()['cartItem']['price'] : $product->getPrice();
 }