nicola10 Posted October 24, 2018 Share Posted October 24, 2018 I use Prestashop 1.6.1.22 and I have installed a module that allows you to manage attribute groups without creating combinations between them. The form is used from each product configuration page when necessary. For products that do not use this add-on module on the frontend page everything works as always. For products for which the add-on module was used, the relevant tab in the frontend is updated with the tpl files of the add-on module, one of which is the cart block. I think I have identified the two smarty assign arrays blocks with the variables but I have no idea how to merge them or how to pass them to a single tpl cart file that collects the variables coming from these two sources. This is the code of blockcart.php (in root/modules/blockcart folder): $this->smarty->assign(array( 'products' => $products, 'customizedDatas' => Product::getAllCustomizedDatas((int)($params['cart']->id)), 'CUSTOMIZE_FILE' => Product::CUSTOMIZE_FILE, 'CUSTOMIZE_TEXTFIELD' => Product::CUSTOMIZE_TEXTFIELD, 'discounts' => $cart_rules, 'nb_total_products' => (int)($nbTotalProducts), 'shipping_cost' => $shipping_cost, 'shipping_cost_float' => $shipping_cost_float, 'show_wrapping' => $wrappingCost > 0 ? true : false, 'show_tax' => (int)(Configuration::get('PS_TAX_DISPLAY') == 1 && (int)Configuration::get('PS_TAX')), 'wrapping_cost' => Tools::displayPrice($wrappingCost, $currency), 'product_total' => Tools::displayPrice($params['cart']->getOrderTotal($useTax, Cart::BOTH_WITHOUT_SHIPPING), $currency), 'total' => Tools::displayPrice($totalToPay, $currency), 'order_process' => Configuration::get('PS_ORDER_PROCESS_TYPE') ? 'order-opc' : 'order', 'ajax_allowed' => (int)(Configuration::get('PS_BLOCK_CART_AJAX')) == 1 ? true : false, 'static_token' => Tools::getToken(false), 'free_shipping' => $total_free_shipping )); if (is_array($errors) && count($errors)) $this->smarty->assign('errors', $errors); if (isset($this->context->cookie->ajax_blockcart_display)) $this->smarty->assign('colapseExpandStatus', $this->context->cookie->ajax_blockcart_display); And this is the code in the add-on module: public function getPreviewHtml() { $tpl = $this->context->smarty->createTemplate($this->getTemplatePath('elements/cart_preview.tpl'), $this->context->smarty); $tpl->assign(array( 'base_product' => $this->configurator_product, 'product' => $this->configuratorCartDetail->product, 'cartDetail' => $this->configuratorCartDetail->getDetail(), 'priceDisplay' => Product::getTaxCalculationMethod((int)$this->context->cookie->id_customer), 'priceDisplayPrecision' => _PS_PRICE_DISPLAY_PRECISION_, 'display_tax_label' => (bool)$this->context->country->display_tax_label, 'tax_enabled' => Configuration::get('PS_TAX'), 'update_cart' => $this->updateCart, 'DISPLAY_PROGRESS' => (int)Configuration::get('CONFIGURATOR_PROGRESS_COMPENENT') )); return $tpl->fetch(); } And this is the code of cart_preview.tpl file of add-on module: {if !isset($priceDisplayPrecision)} {assign var='priceDisplayPrecision' value=2} {/if} {if !$priceDisplay || $priceDisplay == 2} {assign var='productPrice' value=$product->getPrice(true, $smarty.const.NULL, $priceDisplayPrecision)} {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(false, $smarty.const.NULL, $priceDisplayPrecision)} {elseif $priceDisplay == 1} {assign var='productPrice' value=$product->getPrice(false, $smarty.const.NULL, $priceDisplayPrecision)} {assign var='productPriceWithoutReduction' value=$product->getPriceWithoutReduct(true, $smarty.const.NULL, $priceDisplayPrecision)} {/if} <div class="box"> <div class="page-subheading">{l s='Your configuration:' mod='configurator'}</div> {* PROGRESS BAR *} {if $DISPLAY_PROGRESS} <div id="configurator-progress"><strong></strong></div> <hr /> {/if} {* PREVIEW PRICES *} {if $priceDisplay >= 0 && $priceDisplay <= 2} {if $productPrice-$productPriceWithoutReduction neq 0} <dl class="dl-horizontal"> <dt> {l s='Base price' mod='configurator'} {if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) || !isset($display_tax_label))} ({if $priceDisplay == 1}{l s='tax excl.' mod='configurator'}{else}{l s='tax incl.' mod='configurator'}{/if}) {/if} </dt> <dd id="old_price">{convertPrice price=$productPriceWithoutReduction}</dd> <dt class="advantage">{l s='After reducing your advantage' mod='configurator'}</dt> <dd class="advantage">{convertPrice price=($productPrice-$productPriceWithoutReduction)}</dd> </dl> <hr /> {/if} <dl id="dl-final-price" class="dl-horizontal"> <dt> {l s='Final price' mod='configurator'} {if $tax_enabled && ((isset($display_tax_label) && $display_tax_label == 1) || !isset($display_tax_label))} ({if $priceDisplay == 1}{l s='tax excl.' mod='configurator'}{else}{l s='tax incl.' mod='configurator'}{/if}) {/if} </dt> <dd id="final_price">{convertPrice price=$productPrice}</dd> </dl> {/if} {* PREVIEW CONTENT *} <div class="list-group"> {foreach $cartDetail as $step} {assign var=display value=false} {foreach $step.options as $option} {if $option.selected || !empty($option.value)} {assign var=display value=true} {/if} {/foreach} {if $step.displayed_in_preview && $display} <a href="#step_{$step.id|escape:'htmlall':'UTF-8'}" class="list-group-item"> {*<strong>{$step.name|escape:'html':'UTF-8'} : </strong>*} {assign var=k value=0} {foreach $step.options as $option} {if !empty($option.value)} <span class="option_value">{$option.name|escape:'html':'UTF-8'} : {$option.value|escape:'html':'UTF-8'}{$step.input_suffix|escape:'htmlall':'UTF-8'}</span> {elseif $option.selected} <span class="option">{if $k > 0}, {/if}{$option.name|escape:'html':'UTF-8'}</span> {assign var=k value=$k+1} {/if} {/foreach} </a> {/if} {/foreach} </div> {* PREVIEW CONTENT *} <div class="buttons_container"> <form action=" {if $update_cart} {$link->getProductLink($product)|escape:'html':'UTF-8'} {else} {$link->getProductLink($base_product)|escape:'html':'UTF-8'} {/if} "> <input type="hidden" name="add" value="1" /> <div class="form-group"> <label for="quantity-configurator">{l s='Quantity :' mod='configurator'}</label> <input id="quantity-configurator" class="form-control" type="text" name="qty" value="1" /> </div> <button type="submit" id="add_configurator_to_cart" class="button btn btn-default"> {if $update_cart} <span>{l s='Update the cart' mod='configurator'}</span> {else} <span>{l s='Add to cart' mod='configurator'}</span> {/if} </button> </form> </div> </div> I attach a file that shows a simulation Thanks in advance for any help Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now