/** * Prepare bundle selections data. * * @param array $bundleData * @return array */ protected function prepareBundleSelections(array $bundleData) { $result = []; $products = $this->fixture->getDataFieldConfig('bundle_selections')['source']->getProducts(); foreach ($bundleData as $optionKey => $option) { $result[$optionKey] = $this->prepareItemSelectionData($option['assigned_products'], $products[$optionKey]); } return $result; }
/** * 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->getBundleViewBlock()->getPriceBlock(); $priceLow = $product->getPriceView() == 'Price Range' ? $priceBlock->getPriceFrom() : $priceBlock->getRegularPrice(); \PHPUnit_Framework_Assert::assertEquals($priceData['price_from'], $priceLow); if ($product->getPriceView() == 'Price Range') { \PHPUnit_Framework_Assert::assertEquals($priceData['price_to'], $priceBlock->getPriceTo()); } }
/** * 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 bundle options. * * @return array|null */ protected function prepareBundleOptions() { $result = []; $bundleSelections = $this->product->getBundleSelections(); $assignedProducts = $this->product->getDataFieldConfig('bundle_selections')['source']->getProducts(); foreach ($bundleSelections as $optionKey => $bundleOption) { $options = $this->getOptions($bundleOption['assigned_products'], $assignedProducts[$optionKey], $bundleOption['type']); $optionData = ['title' => $bundleOption['title'], 'type' => $bundleOption['type'], 'is_require' => $bundleOption['required'], 'options' => $options]; $result[$optionKey] = $this->sortDataByPath($optionData, 'options::title'); } return $this->sortDataByPath($result, '::title'); }
/** * 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; }