ajaxProcessGetProductInfo(); } if ($this->ajax && Tools::getValue('impactprice', 0)) { if (!Validate::isLoadedObject($this->product)) { return; } // Product Info $qty = Tools::getValue('qty', 1); $id_product_attribute = Tools::getValue('id_product_attribute', null); $productPrice = $this->product->getPrice(true, $id_product_attribute, 6, null, false, true, $qty); $productPriceWithoutReduction = $this->product->getPrice(true, $id_product_attribute, 6, null, false, false, $qty); // Options selected $detectOptGroup = 'optgroup-'; $postValues = Tools::getAllValues(); $this->optValues = array(); $impact = 0; if (count($postValues) > 0) { foreach($postValues as $p => $v) { if (!empty($v)) { if (substr($p, 0, strlen($detectOptGroup)) === $detectOptGroup) { $ids = explode('-', substr($p, strlen($detectOptGroup))); $id_configurator_opt_group = $ids[0]; $id_configurator_opt = $v; if (isset($id[1])) { $id_configurator_opt = $ids[1]; } $this->optValues[] = array( 'id_configurator_opt_group' => substr($p, strlen($detectOptGroup)), 'id_configurator_opt' => $id_configurator_opt ); } } } $impact = $this->product->getConfiguratorImpactPrice($this->optValues); } $this->impactPrice = $impact; // We want total prices $this->productPriceWithImpact = Tools::displayPrice(($productPrice * $qty) + $impact); $this->productPriceWithoutReduction = Tools::displayPrice(($productPriceWithoutReduction * $qty) + $impact); } } /* * module: antadisconfigurator * date: 2017-06-27 12:10:07 * version: 0.1 */ public function postProcess() { if ($this->ajax && Tools::getValue('impactprice', 0)) { $qty = Tools::getValue('qty', 1); $id_product_attribute = Tools::getValue('id_product_attribute', null); $return = array( 'priceUnitDisplay' => Tools::displayPrice($this->product->getPrice(true, $id_product_attribute, 6, null, false, true, $qty)), 'priceDisplay' => Tools::displayPrice($this->productPriceWithImpact), 'priceDisplayWithoutReduc' => Tools::displayPrice($this->productPriceWithoutReduction), 'price' => $this->productPriceWithImpact, ); die(Tools::jsonEncode($return)); } } public function setMedia() { parent::setMedia(); $this->addJS(_THEME_JS_DIR_.'tools/flexslider.js'); $this->addJS(_THEME_JS_DIR_.'tools/lightGallery/lightgallery.min.js'); $this->addJS(_THEME_JS_DIR_.'tools/lightGallery/lg-zoom.min.js'); $this->addJS(_THEME_JS_DIR_.'tools/lightGallery/lg-thumbnail.min.js'); $this->addCSS(_THEME_CSS_DIR_.'tools/flexslider.css'); $this->addCSS(_THEME_CSS_DIR_.'addresses.css'); $this->addCSS(_THEME_CSS_DIR_.'tools/lightgallery.css'); } public function initContent() { parent::initContent(); $id_configurator = Tools::getValue('id_configurator', 0); // How to get id_product_attribute // Get quantity if product is in cart $result = $this->context->cart->containsProduct($this->product->id, 0, 0, 0, $id_configurator); if ($result) { $this->context->smarty->assign('quantityBackup', $result['quantity']); } $impact = 0; if ($id_configurator != 0) { // Search product with id_configurator $cartProducts = $this->context->cart->getProducts(); foreach ($cartProducts as $testProduct) { if ($testProduct['id_product'] == $this->product->id && $testProduct['id_configurator'] == $id_configurator) { $id_product_attribute = $testProduct['id_product_attribute']; $combinaisonSelected = $this->product->getAttributeCombinationsById($id_product_attribute, $this->context->language->id); // On suppose uniquement 1 !!!! $this->context->smarty->assign('productIdAttributeSelected', $combinaisonSelected[0]['id_attribute']); break; } } // Product Info $impact = Product::getConfiguratorSelectedPriceTotal($this->product->id, $id_configurator); $productPrice = $this->product->getPrice(true, $id_product_attribute, 6); $this->context->smarty->assign('productPrice', $productPrice + $impact); } $this->context->smarty->assign('impactPrice', $impact); } public function ajaxProcessGetProductInfo() { $context = Context::getContext(); $product = new Product(Tools::getValue('id_product'),true,$context->cookie->id_lang); if($product) { $idCombination = null; $attributes = null; $qty = Tools::getValue('qty', 1); $product->quantity = $qty; if(Tools::getValue('idCombination')) { $idCombination = Tools::getValue('idCombination'); $attributes = $product->getAttributeCombinationsById($idCombination,$context->cookie->id_lang); } $priceDisplay = Group::getPriceDisplayMethod($context->customer->id_default_group); if (!$priceDisplay || $priceDisplay == 2) { $productPriceFloat = $product->getPrice(true, $idCombination); $productPrice = Tools::displayPrice($productPriceFloat); $productPriceWithoutReductionFloat = $product->getPriceWithoutReduct(false, $idCombination); $productPriceWithoutReduction = Tools::displayPrice($productPriceWithoutReductionFloat); $totalPrice = Tools::displayPrice($product->getPrice(true, $idCombination) * $qty); } else if( $priceDisplay == 1) { $productPriceFloat = $product->getPrice(false, $idCombination); $productPrice = Tools::displayPrice($productPriceFloat); $productPriceWithoutReductionFloat = $product->getPriceWithoutReduct(true, $idCombination); $productPriceWithoutReduction = Tools::displayPrice($productPriceWithoutReductionFloat); $totalPrice = Tools::displayPrice($product->getPrice(false, $idCombination) * $qty); } if($idCombination !== null){ $combinationImages = $product->getCombinationImages($this->context->language->id); if($combinationImages) { $img = reset($combinationImages[$idCombination]); $product->img = $context->link->getImageLink($product->link_rewrite, $img["id_image"], 'home_default'); } else { $product->img = $context->link->getImageLink($product->link_rewrite, $product->getCoverWs(), 'home_default'); } } else { $product->img = $context->link->getImageLink($product->link_rewrite, $product->getCoverWs(), 'home_default'); } $product->attributes = $attributes; $product->qty = $qty; $product->productPrice = $productPrice; $product->productPriceWithoutReduction = $productPriceWithoutReduction; $product->totalPrice = $totalPrice; $product->reduction = 0; if($productPrice != $productPriceWithoutReduction) { $product->reduction = -1 * round(100 - ($productPriceFloat * 100 / $productPriceWithoutReductionFloat)); } $to_return = array( 'product' => $product, 'found' => true ); } else { $to_return = array('found' => false); } echo Tools::jsonEncode($to_return); } }