/**
  * Preparation options before comparing.
  *
  * @param InjectableFixture $product
  * @return array
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function prepareOptions(InjectableFixture $product)
 {
     $result = [];
     $customOptions = $product->getCustomOptions();
     $actualPrice = $this->getProductActualPrice($product);
     foreach ($customOptions as $customOption) {
         $customOptionsPriceType = isset($customOption['options']['price_type']) ? $customOption['options']['price_type'] : null;
         if ($customOptionsPriceType) {
             if ($customOptionsPriceType === 'Percent') {
                 $customOptionPrice = $customOption['options']['price'];
                 $customOption['options']['price'] = $this->calculatePrice($actualPrice, $customOptionPrice);
             }
             $customOption['options'] = array_diff_key($customOption['options'], array_flip($this->skippedFieldOptions));
         } else {
             foreach ($customOption['options'] as &$option) {
                 if ('Percent' === $option['price_type']) {
                     $option['price'] = $this->calculatePrice($actualPrice, $option['price']);
                 }
                 $option = array_diff_key($option, array_flip($this->skippedFieldOptions));
             }
         }
         $customOption['type'] = explode('/', $customOption['type'])[1];
         $result[$customOption['title']] = $customOption;
     }
     return $result;
 }
 /**
  * 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;
 }
示例#3
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);
     }
 }
示例#4
0
 /**
  * Get product options.
  *
  * @param InjectableFixture $product
  * @return array
  * @throws \Exception
  */
 public function getOptions(InjectableFixture $product)
 {
     $dataOptions = $product->hasData('custom_options') ? $product->getCustomOptions() : [];
     if (empty($dataOptions)) {
         return $dataOptions;
     }
     $listCustomOptions = $this->getListOptions();
     $result = [];
     foreach ($dataOptions as $option) {
         $title = $option['title'];
         if (!isset($listCustomOptions[$title])) {
             throw new \Exception("Can't find option: \"{$title}\"");
         }
         /** @var Element $optionElement */
         $optionElement = $listCustomOptions[$title];
         $option['type'] = explode('/', $option['type'])[1];
         $typeMethod = preg_replace('/[^a-zA-Z]/', '', $option['type']);
         $getTypeData = 'get' . ucfirst(strtolower($typeMethod)) . 'Data';
         $optionData = $this->{$getTypeData}($optionElement);
         $optionData['title'] = $title;
         $optionData['type'] = $option['type'];
         $optionData['is_require'] = $optionElement['title']->find($this->required, Locator::SELECTOR_XPATH)->isVisible() ? 'Yes' : 'No';
         $result[$title] = $optionData;
     }
     return ['custom_options' => $result];
 }