Example #1
0
 /**
  * Assert prices on the product view Page.
  *
  * @param BundleProduct $product
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 protected function assertPrice(BundleProduct $product, CatalogProductView $catalogProductView)
 {
     $priceData = $product->getDataFieldConfig('price')['source']->getPriceData();
     $priceView = $product->getPriceView();
     $priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
     if ($product->hasData('special_price') || $product->hasData('group_price')) {
         $priceLow = $priceBlock->getPrice();
     } else {
         $priceLow = $priceView == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getPrice();
     }
     \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on product view page is not correct.');
     if ($priceView == 'Price Range') {
         \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on product view page is not correct.');
     }
 }
 /**
  * Test update bundle product
  *
  * @param BundleProduct $product
  * @param BundleProduct $originalProduct
  * @return array
  */
 public function test(BundleProduct $product, BundleProduct $originalProduct)
 {
     // Preconditions
     $originalProduct->persist();
     $originalCategory = $originalProduct->hasData('category_ids') ? $originalProduct->getDataFieldConfig('category_ids')['source']->getCategories() : null;
     $category = $product->hasData('category_ids') ? $product->getDataFieldConfig('category_ids')['source']->getCategories() : $originalCategory;
     // Steps
     $filter = ['sku' => $originalProduct->getSku()];
     $this->catalogProductIndex->open();
     $this->catalogProductIndex->getProductGrid()->searchAndOpen($filter);
     $this->catalogProductEdit->getProductForm()->fill($product);
     $this->catalogProductEdit->getFormPageActions()->save();
     return ['category' => $category];
 }
 /**
  * Prepare bundle options.
  *
  * @param BundleProduct $product
  * @return array
  */
 protected function prepareBundleOptions(BundleProduct $product)
 {
     $bundleSelections = $product->getBundleSelections();
     $bundleOptions = isset($bundleSelections['bundle_options']) ? $bundleSelections['bundle_options'] : [];
     $result = [];
     foreach ($bundleOptions as $optionKey => $bundleOption) {
         $optionData = ['title' => $bundleOption['title'], 'type' => $bundleOption['type'], 'is_require' => $bundleOption['required']];
         foreach ($bundleOption['assigned_products'] as $productKey => $assignedProduct) {
             $price = isset($assignedProduct['data']['selection_price_value']) ? $assignedProduct['data']['selection_price_value'] : $bundleSelections['products'][$optionKey][$productKey]->getPrice();
             if ($product->hasData('group_price')) {
                 $groupedPrice = $product->getGroupPrice();
                 $price -= $price / 100 * reset($groupedPrice)['price'];
             }
             $optionData['options'][$productKey] = ['title' => $assignedProduct['search_data']['name'], 'price' => number_format($price, 2)];
         }
         $result[$optionKey] = $optionData;
     }
     return $result;
 }