/** * 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')); }
/** * 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; }
/** * Parse bundle selections in response. * * @param string $id * @return array */ protected function parseResponseSelections($id) { $url = $_ENV['app_backend_url'] . "bundle_product_edit/form/id/{$id}/back/edit/tab/product_info_tabs_group_7/"; $curl = new BackendDecorator(new CurlTransport(), $this->_configuration); $curl->write(CurlInterface::POST, $url, '1.1'); $response = $curl->read(); $curl->close(); $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 as $optionKey => $option) { foreach ($option['assigned_products'] as $assignedKey => $optionValue) { $productName = $optionValue['name']; $bundleSelections[$optionKey]['assigned_products'][$assignedKey] += $responseSelections[$productName]; } } return ['bundle_selections' => $bundleSelections]; }
/** * Get item option price for item bundle selection. * * @param float $assignedProductPrice * @param string $customerGroup [optional] * @return string */ protected function getOptionPrice($assignedProductPrice, $customerGroup = 'NOT LOGGED IN') { if ($this->product->hasData('group_price')) { $groupPrice = $this->product->getGroupPrice(); $groupPriceType = array_search($customerGroup, $groupPrice); $assignedProductPrice -= $assignedProductPrice / 100 * $groupPrice[$groupPriceType]['price']; } $assignedProductPrice *= $this->product->hasData('special_price') ? $this->product->getSpecialPrice() / 100 : 1; return number_format($assignedProductPrice, 2); }
/** * 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; }