/**
  * Assert prices on the product view page and shopping cart page.
  *
  * @param CatalogProductBundle $product
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCartView
  * @param CatalogProductBundle $originalProduct [optional]
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function assertPrice(CatalogProductBundle $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCartView, CatalogProductBundle $originalProduct = null)
 {
     $customerGroup = 'NOT LOGGED IN';
     $bundleData = $product->getData();
     $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType();
     $catalogProductView->getViewBlock()->addToCart($product);
     $cartItem = $checkoutCartView->getCartBlock()->getCartItem($product);
     $specialPrice = 0;
     if (isset($bundleData['group_price'])) {
         $specialPrice = $bundleData['group_price'][array_search($customerGroup, $bundleData['group_price'])]['price'] / 100;
     }
     $optionPrice = [];
     $fillData = $product->getCheckoutData();
     foreach ($fillData['bundle_options'] as $key => $data) {
         $subProductPrice = 0;
         foreach ($bundleData['bundle_selections']['products'][$key] as $productKey => $itemProduct) {
             if (strpos($itemProduct->getName(), $data['value']['name']) !== false) {
                 $data['value']['key'] = $productKey;
                 $subProductPrice = $itemProduct->getPrice();
             }
         }
         $optionPrice[$key]['price'] = $this->productPriceType == 'Fixed' ? number_format($bundleData['bundle_selections']['bundle_options'][$key]['assigned_products'][$data['value']['key']]['data']['selection_price_value'], 2) : number_format($subProductPrice, 2);
     }
     foreach ($optionPrice as $index => $item) {
         $item['price'] -= $item['price'] * $specialPrice;
         \PHPUnit_Framework_Assert::assertEquals(number_format($item['price'], 2), $cartItem->getPriceBundleOptions($index + 1), 'Bundle item ' . ($index + 1) . ' options on frontend don\'t equal to fixture.');
     }
     $sumOptionsPrice = $product->getDataFieldConfig('price')['source']->getPreset()['cart_price'];
     $subTotal = number_format($cartItem->getPrice(), 2);
     \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.');
 }
Example #2
0
 /**
  * Assert prices on the product view Page
  *
  * @param CatalogProductBundle $product
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 protected function assertPrice(CatalogProductBundle $product, CatalogProductView $catalogProductView)
 {
     $priceData = $product->getDataFieldConfig('price')['source']->getPreset();
     $priceBlock = $catalogProductView->getViewBlock()->getProductPriceBlock();
     $priceLow = $product->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice();
     \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on product view page is not correct.');
     if ($product->getPriceView() == 'Price Range') {
         \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on product view page is not correct.');
     }
 }
 /**
  * Verify product price on category view page
  *
  * @param CatalogProductBundle $bundle
  * @param CatalogCategoryView $catalogCategoryView
  * @return void
  */
 protected function assertPrice(CatalogProductBundle $bundle, CatalogCategoryView $catalogCategoryView)
 {
     $priceData = $bundle->getDataFieldConfig('price')['source']->getPreset();
     //Price from/to verification
     $priceBlock = $catalogCategoryView->getListProductBlock()->getProductPriceBlock($bundle->getName());
     $priceLow = $bundle->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice();
     \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow, 'Bundle price From on category page is not correct.');
     if ($bundle->getPriceView() == 'Price Range') {
         \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo(), 'Bundle price To on category page is not correct.');
     }
 }
 /**
  * Prepare bundle options
  *
  * @param CatalogProductBundle $product
  * @return array
  */
 protected function prepareBundleOptions(CatalogProductBundle $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();
             $optionData['options'][$productKey] = ['title' => $assignedProduct['search_data']['name'], 'price' => number_format($price, 2)];
         }
         $result[$optionKey] = $optionData;
     }
     return $result;
 }
 /**
  * Test update bundle product
  *
  * @param CatalogProductBundle $product
  * @param CatalogProductBundle $originalProduct
  * @return void
  */
 public function test(CatalogProductBundle $product, CatalogProductBundle $originalProduct)
 {
     $originalProduct->persist();
     $this->catalogProductIndex->open();
     $filter = ['sku' => $originalProduct->getSku()];
     $this->catalogProductIndex->getProductGrid()->searchAndOpen($filter);
     $this->catalogProductEdit->getForm()->fill($product);
     $this->catalogProductEdit->getFormAction()->save();
 }
 /**
  * Displayed bundle block on frontend with correct fixture product
  *
  * @param CatalogProductView $catalogProductView
  * @param CatalogProductBundle $product
  * @return string|null
  */
 protected function displayedBundleBlock(CatalogProductView $catalogProductView, CatalogProductBundle $product)
 {
     $fields = $product->getData();
     $bundleOptions = $fields['bundle_selections']['bundle_options'];
     if (!isset($bundleOptions)) {
         return 'Bundle options data on product page is not equals to fixture preset.';
     }
     $catalogProductView->getViewBlock()->clickCustomize();
     foreach ($bundleOptions as $index => $item) {
         foreach ($item['assigned_products'] as &$selection) {
             $selection = $selection['search_data'];
         }
         $result = $catalogProductView->getBundleViewBlock()->getBundleBlock()->displayedBundleItemOption($item, ++$index);
         if ($result !== true) {
             return $result;
         }
     }
     return null;
 }
Example #7
0
 /**
  * Fill bundle option on frontend add click "Add to cart" button
  *
  * @param CatalogProductBundle $product
  * @param CatalogProductView $catalogProductView
  * @return void
  */
 public function addToCart(CatalogProductBundle $product, CatalogProductView $catalogProductView)
 {
     $fillData = $product->getDataFieldConfig('checkout_data')['source']->getPreset();
     if (isset($fillData['bundle_options'])) {
         $this->fillBundleOptions($fillData['bundle_options']);
     }
     if (isset($fillData['custom_options'])) {
         $catalogProductView->getCustomOptionsBlock()->fillCustomOptions($product, $fillData['custom_options']);
     }
     $catalogProductView->getViewBlock()->clickAddToCart();
 }