Ejemplo n.º 1
0
 /**
  * Assert prices on the product view page and shopping cart page.
  *
  * @param BundleProduct $product
  * @param CatalogProductView $catalogProductView
  * @param CheckoutCart $checkoutCartView
  * @param BundleProduct $originalProduct [optional]
  * @return void
  *
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 protected function assertPrice(BundleProduct $product, CatalogProductView $catalogProductView, CheckoutCart $checkoutCartView, BundleProduct $originalProduct = null)
 {
     $customerGroup = 'NOT LOGGED IN';
     $bundleData = $product->getData();
     $this->productPriceType = $originalProduct !== null ? $originalProduct->getPriceType() : $product->getPriceType();
     $catalogProductView->getViewBlock()->addToCart($product);
     $catalogProductView->getMessagesBlock()->waitSuccessMessage();
     $checkoutCartView->open();
     $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['options']['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']->getPriceData()['cart_price'];
     $subTotal = number_format($cartItem->getPrice(), 2);
     \PHPUnit_Framework_Assert::assertEquals($sumOptionsPrice, $subTotal, 'Bundle unit price on frontend doesn\'t equal to fixture.');
 }
 /**
  * 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']->getPreset();
     $priceBlock = $catalogProductView->getViewBlock()->getPriceBlock();
     $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 BundleProduct $bundle
  * @param CatalogCategoryView $catalogCategoryView
  * @return void
  */
 protected function assertPrice(BundleProduct $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.');
     }
 }
 /**
  * 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();
             $optionData['options'][$productKey] = ['title' => $assignedProduct['search_data']['name'], 'price' => number_format($price, 2)];
         }
         $result[$optionKey] = $optionData;
     }
     return $result;
 }
 /**
  * Test update bundle product
  *
  * @param BundleProduct $product
  * @param BundleProduct $originalProduct
  * @return void
  */
 public function test(BundleProduct $product, BundleProduct $originalProduct)
 {
     $originalProduct->persist();
     $this->catalogProductIndex->open();
     $filter = ['sku' => $originalProduct->getSku()];
     $this->catalogProductIndex->getProductGrid()->searchAndOpen($filter);
     $this->catalogProductEdit->getProductForm()->fill($product);
     $this->catalogProductEdit->getFormPageActions()->save();
 }
Ejemplo n.º 7
0
 /**
  * Parse bundle selections in response.
  *
  * @param string $response
  * @return array
  */
 protected function parseResponseSelections($response)
 {
     $selectionIdKey = 1;
     $optionIdKey = 2;
     $productNameKey = 3;
     $responseSelections = [];
     $bundleSelections = $this->fixture->getBundleSelections();
     preg_match_all('/{.*"selection_id":"(\\d+)".*"option_id":"(\\d+)".*"name":"([^"]+)".*}/', $response, $matches, PREG_SET_ORDER);
     foreach ($matches as $match) {
         $productName = $match[$productNameKey];
         $responseSelections[$productName] = ['selection_id' => $match[$selectionIdKey], 'option_id' => $match[$optionIdKey]];
     }
     foreach ($bundleSelections['bundle_options'] as $optionKey => $option) {
         foreach ($option['assigned_products'] as $assignedKey => $optionValue) {
             $productName = $optionValue['search_data']['name'];
             $bundleSelections['bundle_options'][$optionKey]['assigned_products'][$assignedKey] += $responseSelections[$productName];
         }
     }
     return ['bundle_selections' => $bundleSelections];
 }
Ejemplo n.º 8
0
 /**
  * Prepare data for bundle product.
  *
  * @param BundleProduct $product
  * @return array
  *
  * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  */
 protected function prepareBundleData(BundleProduct $product)
 {
     $result = [];
     $checkoutData = $product->getCheckoutData();
     $bundleOptions = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : [];
     $bundleSelections = $product->getBundleSelections();
     $bundleSelectionsData = [];
     $result['qty'] = $checkoutData['qty'];
     foreach ($bundleSelections['bundle_options'] as $option) {
         foreach ($option['assigned_products'] as $productData) {
             $productName = $productData['search_data']['name'];
             $bundleSelectionsData[$productName] = ['selection_id' => $productData['selection_id'], 'option_id' => $productData['option_id']];
         }
     }
     foreach ($bundleOptions as $option) {
         $productName = $option['value']['name'];
         foreach ($bundleSelectionsData as $fullProductName => $value) {
             if (null !== strpos($fullProductName, $productName)) {
                 $productName = $fullProductName;
             }
         }
         if (isset($bundleSelectionsData[$productName])) {
             $optionId = $bundleSelectionsData[$productName]['option_id'];
             $selectionId = $bundleSelectionsData[$productName]['selection_id'];
             $result['bundle_option'][$optionId] = $selectionId;
         }
     }
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Prepare bundle product options.
  *
  * @param BundleProduct $product
  * @return array
  */
 protected function prepareBundleOptions(BundleProduct $product)
 {
     $options = [];
     foreach ($product->getCheckoutData()['options']['bundle_options'] as $checkoutOption) {
         foreach ($product->getBundleSelections()['bundle_options'] as $productOption) {
             if (strpos($productOption['title'], $checkoutOption['title']) !== false) {
                 $option = [];
                 foreach ($productOption['assigned_products'] as $productData) {
                     if (strpos($productData['search_data']['name'], $checkoutOption['value']['name']) !== false) {
                         $qty = isset($checkoutOption['qty']) ? $checkoutOption['qty'] : $productData['data']['selection_qty'];
                         $option['option_id'] = $productData['option_id'];
                         $option['option_selections'][] = $productData['selection_id'];
                         $option['option_qty'] = $qty;
                     }
                 }
                 $options[] = $option;
             }
         }
     }
     return ['extension_attributes' => ['bundle_options' => $options]];
 }