objectFactory = $objectFactory; $this->configurationPool = $configurationPool; $this->itemProcessor = $itemProcessor; $this->layoutFactory = $layoutFactory; $this->productFactory = $productFactory; $this->pricingHelper = $pricingHelper; } public function execute() { $result['status'] = false; $data = $this->getRequest()->getParams(); $resultRedirect = $this->resultRedirectFactory->create(); if ($data) { try { $product = $this->productFactory->create(); $product->load($data['product']); $options = []; parse_str($data['options'], $options); if (isset($options['super_group']) && $options['super_group']) { $price = 0; $html = '
'; foreach ($options['super_group'] as $productId => $qty) { if ($qty) { $product1 = $this->productFactory->create(); $product1->load($productId); $buyeRequest = $this->objectFactory->create([ 'product' => $productId, 'qty' => $qty ]); $item = $this->getItem($product1, $buyeRequest); $html .= '
' . $qty . ' x ' . $product1->getName() . '
'; $html .= '
' . $this->pricingHelper->currency($item->getProduct()->getFinalPrice(), true, false) . '
'; $price += $item->getProduct()->getFinalPrice() * $qty; } } $html .= '
'; $result['price'] = $price; $result['options'] = $html; } else { $options = $this->objectFactory->create($options); $item = $this->getItem($product, $options); $result['price'] = $item->getProduct()->getFinalPrice(); $optionList = $this->configurationPool->getByProductType($item->getProductType())->getOptions($item); $layout = $this->layoutFactory->create(); $block = $layout->createBlock('\Magento\Framework\View\Element\Template'); $block->setTemplate('Magezon_QuickOrder::product/options.phtml')->setOptionList($optionList); $result['options'] = $block->toHtml(); } $result['status'] = true; } catch (LocalizedException $e) { $result['message'] = $e->getMessage(); } catch (\Exception $e) { $result['message'] = __('Something went wrong while processing the request.'); } } $this->getResponse()->representJson( $this->_objectManager->get(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($result) ); return; } /** * @return \Magento\Quote\Model\Quote\Item */ public function getItem($product, $buyRequest) { $candidate = $this->getCandidate($product, $buyRequest); $item = $this->itemProcessor->init($candidate, $buyRequest); $item->setOptions($candidate->getCustomOptions()); $item->setProduct($product); return $item; } public function getCandidate($product, $buyRequest) { $cartCandidates = $product->getTypeInstance()->prepareForCartAdvanced($buyRequest, $product, \Magento\Catalog\Model\Product\Type\AbstractType::PROCESS_MODE_FULL); /** * Error message */ if (is_string($cartCandidates) || $cartCandidates instanceof \Magento\Framework\Phrase) { return strval($cartCandidates); } /** * If prepare process return one object */ if (!is_array($cartCandidates)) { $cartCandidates = [$cartCandidates]; } return $cartCandidates[0]; } }