/**
  * Assert prices on the product view page and shopping cart page.
  *
  * @param CheckoutCart $checkoutCartView
  * @return void
  */
 protected function assertPrice(CheckoutCart $checkoutCartView)
 {
     $formCartItem = $checkoutCartView->getCartBlock()->getCartItem($this->product);
     $fixtureCartItem = $this->product->getCheckoutData()['cartItem'];
     $this->assertCartOptions($fixtureCartItem['options']['bundle_options'], $formCartItem->getOptions());
     $this->assertCartPrice($fixtureCartItem['price'], $formCartItem->getCartItemTypePrice('price'));
 }
 /**
  * Get assigned products.
  *
  * @param BundleProduct $bundleProduct
  * @return array
  */
 protected function getBundleAssignedItems(BundleProduct $bundleProduct)
 {
     $result = [];
     $options = $bundleProduct->getCheckoutData()['options']['bundle_options'];
     $productsKeys = $this->getProductsKeys($options);
     $products = $bundleProduct->getDataFieldConfig('bundle_selections')['source']->getProducts();
     foreach ($productsKeys as $optionKey => $optionProduct) {
         $result[] = $products[$optionKey][$optionProduct];
     }
     return $result;
 }
 /**
  * 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 as $option) {
         foreach ($option['assigned_products'] as $productData) {
             $bundleSelectionsData[] = ['selection_id' => $productData['selection_id'], 'option_id' => $productData['option_id']];
         }
     }
     foreach ($bundleOptions as $option) {
         $key = substr($option['value']['name'], -1);
         if (isset($bundleSelectionsData[$key])) {
             $optionId = $bundleSelectionsData[$key]['option_id'];
             $selectionId = $bundleSelectionsData[$key]['selection_id'];
             $result['bundle_option'][$optionId] = $selectionId;
         }
     }
     return $result;
 }
 /**
  * Prepare checkout data for fill bundle options.
  *
  * @param BundleProduct $product
  * @return array
  */
 protected function prepareBundleCheckoutData(BundleProduct $product)
 {
     $assignedProducts = $product->getDataFieldConfig('bundle_selections')['source']->getProducts();
     $bundleOptions = $product->getBundleSelections();
     $checkoutData = $product->getCheckoutData();
     $checkoutData = isset($checkoutData['options']['bundle_options']) ? $checkoutData['options']['bundle_options'] : [];
     foreach ($checkoutData as $optionKey => $option) {
         $optionIndex = str_replace('option_key_', '', $optionKey);
         $names = explode(',', $checkoutData[$optionKey]['value']['name']);
         $checkoutData[$optionKey]['title'] = $bundleOptions[$optionIndex]['title'];
         $checkoutData[$optionKey]['type'] = $bundleOptions[$optionIndex]['type'];
         $checkoutData[$optionKey]['value']['name'] = $this->prepareOptionValue($names, $assignedProducts[$optionIndex]);
     }
     return $checkoutData;
 }