/**
  * Assertion that tier prices are displayed correctly
  *
  * @param BrowserInterface $browser
  * @param CatalogProductView $catalogProductView
  * @param FixtureInterface $product
  * @return void
  */
 public function processAssert(BrowserInterface $browser, CatalogProductView $catalogProductView, FixtureInterface $product)
 {
     //Open product view page
     $browser->open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html');
     $viewBlock = $catalogProductView->getBundleViewBlock();
     $viewBlock->clickCustomize();
     //Process assertions
     $this->assertPrice($product, $viewBlock);
 }
 /**
  * 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;
 }
Exemplo n.º 3
0
 /**
  * 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';
     $catalogProductView->getViewBlock()->clickCustomize();
     $bundleData = $product->getData();
     $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType();
     $fillData = $product->getDataFieldConfig('checkout_data')['source']->getPreset();
     $bundleBlock = $catalogProductView->getBundleViewBlock()->getBundleBlock();
     $bundleBlock->addToCart($product, $catalogProductView);
     $cartBlock = $checkoutCartView->getCartBlock();
     $specialPrice = 0;
     if (isset($bundleData['group_price'])) {
         $specialPrice = $bundleData['group_price'][array_search($customerGroup, $bundleData['group_price'])]['price'] / 100;
     }
     $optionPrice = [];
     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), $cartBlock->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($cartBlock->getCartItemUnitPrice($product), 2);
     \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.');
 }