I have a problem that I can not solve.
in prestashop 1.7 I have a tpl file called product.tpl where inside, besides the various data, I call a file with the following code:
<div class="product-actions">
{block name='product_buy'}
<form action="{$urls.pages.cart}" method="post" id="add-to-cart-or-refresh">
<input type="hidden" name="token" value="{$static_token}">
<input type="hidden" name="id_product" value="{$product.id}" id="product_page_product_id">
<input type="hidden" name="id_customization" value="{$product.customization_id}" id="product_customization_id">
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
{block name='product_pack'}
{if $packItems}
<section class="product-pack">
<h3 class="h4">{l s='This pack contains' d='Shop.Theme.Catalog'}</h3>
{foreach from=$packItems item="product_pack"}
{block name='product_miniature'}
{include file='catalog/_partials/miniatures/pack-product.tpl' product=$product_pack}
{/block}
{/foreach}
</section>
{/if}
{/block}
{block name='product_discounts'}
{include file='catalog/_partials/product-discounts.tpl'}
{/block}
{block name='product_add_to_cart'}
{include file='catalog/_partials/product-add-to-cart.tpl'}
{/block}
{block name='product_additional_info'}
{include file='catalog/_partials/product-additional-info.tpl'}
{/block}
{block name='product_refresh'}
<input class="product-refresh ps-hidden-by-js" name="refresh" type="submit" value="{l s='Refresh' d='Shop.Theme.Actions'}">
{/block}
</form>
{/block}
</div>
and everything works correctly.
what interests me most specifically is the portion of code referred to in this block
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
The code is:
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>
then I modified the tpl file of the module ps_featuredproducts and inside the main file "ps_featuredproducts.tpl", inside the foreach I inserted a part of the code to display the variants and some product html design.
what happens is that I visualize perfectly the formatting but all the values of the variants do not let me see them, specifically this portion of code does not work
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>
Obviously the same code in the product page recalls all the variables, while in the home where I recall the contents on the homepage I can not recover them. Where am I wrong? I put hands on prestashop only a few weeks ago and I think I have a confused ideas.
I hope little I have been clear, thanks to those who have the patience to answer.
The variable $groups does not exist in ps_featuredproducts. You have to add it to the module if you want to use it on your home page.
In order to do that, you have to modify function getWidgetVariables() in ps_featuredproducts.php like this.
public function getWidgetVariables($hookName = null, array $configuration = [])
{
$products = $this->getProducts();
foreach ($products as &$product) {
$product_object = new Product((int)$product['id_product']);
$groups = array();
$attributes_groups = $product_object->getAttributesGroups($this->context->language->id);
if (is_array($attributes_groups) && $attributes_groups) {
foreach ($attributes_groups as $k => $row) {
if (!isset($groups[$row['id_attribute_group']])) {
$groups[$row['id_attribute_group']] = array(
'group_name' => $row['group_name'],
'name' => $row['public_group_name'],
'group_type' => $row['group_type'],
'default' => -1,
);
}
$groups[$row['id_attribute_group']]['attributes'][$row['id_attribute']] = array(
'name' => $row['attribute_name'],
'html_color_code' => $row['attribute_color'],
'texture' => (#filemtime(_PS_COL_IMG_DIR_.$row['id_attribute'].'.jpg')) ? _THEME_COL_DIR_.$row['id_attribute'].'.jpg' : '',
'selected' => (isset($product_for_template['attributes'][$row['id_attribute_group']]['id_attribute']) && $product_for_template['attributes'][$row['id_attribute_group']]['id_attribute'] == $row['id_attribute']) ? true : false,
);
if ($row['default_on'] && $groups[$row['id_attribute_group']]['default'] == -1) {
$groups[$row['id_attribute_group']]['default'] = (int) $row['id_attribute'];
}
if (!isset($groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']])) {
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] = 0;
}
$groups[$row['id_attribute_group']]['attributes_quantity'][$row['id_attribute']] += (int) $row['quantity'];
}
// wash attributes list (if some attributes are unavailables and if allowed to wash it)
if (!Product::isAvailableWhenOutOfStock($product_object->out_of_stock) && Configuration::get('PS_DISP_UNAVAILABLE_ATTR') == 0) {
foreach ($groups as &$group) {
foreach ($group['attributes_quantity'] as $key => &$quantity) {
if ($quantity <= 0) {
unset($group['attributes'][$key]);
}
}
}
}
}
$product['groups'] = $groups;
}
if (!empty($products)) {
return array(
'products' => $products,
'allProductsLink' => Context::getContext()->link->getCategoryLink($this->getConfigFieldsValues()['HOME_FEATURED_CAT']),
);
}
return false;
}
I am using here a part of the code from the function ProductController::assignAttributesGroups() to get only $groups variable.
Finally, in ps_featuredproducts.tpl, you have to replace:
<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
By:
<div class="product-variants">
{foreach from=$product.groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
And then, all variables will be displayed like on product page.
The variable $groups that is used in catalog/_partials/product-variants.tpl is passed from PoductController.php and is available only on product info page. You cannot use it on your homepage or elsewhere. If you want to achieve the same result you need to create some similar variable within your module and pass it to your own template. The variable created in the file controller/front/ProductController.php within method assignAttributesGroups but it is pretty complicated I think you can create something much simpler.
Related
I am trying to save my data from a dynamic selected dropdown into my database but I'm having errors doing so.
This is the error I am getting.
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'county_id' cannot be null (SQL: insert into `properties` (`National_id`, `Plot_No`, `Property_Ad`, `Property_Photo`, `Property_features`, `county_id`, `sc_id`, `town_id`, `type`, `updated_at`, `created_at`) values (63636, 424545, Duplex Apartments, test.jpg, Free parking, ?, ?, ?, ?, 2023-02-18 09:42:30, 2023-02-18 09:42:30))
I need help on how to save a selected drop down to a database which is a foreign key referencing another table (county_id references id on the county table, sc_id references id on the subcounty table and town_id references id on the town table).
This is my livewire page.
<form id="add-property-form" method="POST" action="{{URL::to('saveProperty')}}">
#csrf
<div class="col-md-8">
<div class="card">
<div class="card-body">
#if ($errors->any())
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li class="text-white">{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<div class= "form-group">
<!--input pattern= "[a-zA-Z]{2,10}$" required-->
<p>National id</p><input type="number" required name="National_id" value="{{old('National_id')}}" class="form-control #error('National_id') is-invalid #enderror"
placeholder="Confirm your National id number">
<div class="invalid-feedback">
#error('National_id') {{$message}} #enderror
</div>
<p>Plot No</p><input type="number" required name="plot_no" value="{{old('plot_no')}}" class="form-control #error('plot_no') is-invalid #enderror"
placeholder="Please enter plot number">
<div class="invalid-feedback">
#error('plot_no') {{$message}} #enderror
</div>
<p>Property Description</p><input type="text" required name="Property_Ad" value="{{old('Property_Ad')}}" class="form-control #error('Property_Ad') is-invalid #enderror"
placeholder="Please enter property description">
<div class="invalid-feedback">
#error('Property_Ad') {{$message}} #enderror
</div>
<p>Property Features</p><input type="text" required name="Property features" value="{{old('Property_features')}}" class="form-control #error('Property_features') is-invalid #enderror"
placeholder="Please enter property features">
<div class="invalid-feedback">
#error('Property_features') {{$message}} #enderror
</div>
<p>Property Images</p><input type="file" required name="Property_Photo" value="{{old('Property_Photo')}}" class="form-control"
>
<p>Location</p>
<div class="row align-items-start">
<div class="col">
<select id="County" class="form-select-lg mb-3 form-control" wire:model = "selectedCounty" name="County">
<option value="" >County</option>
#foreach ($counties as $co)
<option value="{{$co->id}}">{{$co->name}}</option>
#endforeach
</select>
</div>
#if (!is_null($subcounty))
<div class="col">
<select id="subCounty" class="form-select-lg mb-3 form-control" wire:model = "selectedSubCounty" name="subCounty">
<option value="">SubCounty</option>
#foreach ($subcounty as $su)
<option value="{{$su->id}}">{{$su->name}}</option>
#endforeach
</select>
</div>
#endif
#if (!is_null($town))
<div class="col">
<select id="Town" class="form-select-lg mb-3 form-control" wire:model = "selectedTown" name="Town">
<option value="">Town</option>
#foreach ($town as $to)
<option value="{{$to->id}}">{{$to->name}}</option>
#endforeach
</select>
</div>
#endif
</div>
<p>Property Type</p><input type="text" required name="property_type" value="{{old('type')}}" title="2-10 characters" class="form-control #error('type') is-invalid #enderror"
placeholder="Please enter your property type">
<div class="invalid-feedback">
#error('type') {{$message}} #enderror
</div>
</div>
<input type="submit" name="submit" class="form-control btn btn-success" >
</div>
</div>
</div>
</div>
</form>
This is my view page
#extends('layout')
#section('headTitle', 'Your Properties / Add Property')
#section('pageTitle', 'Your Properties / Add Property')
#section('content')
<livewire:subcounty />
#endsection
This is my controller page.
<?php
namespace App\Http\Controllers;
use App\Models\home_owners;
use App\Models\property;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class ProController extends Controller
{
public function viewProperties(){
$allPros = property::paginate(7);
//dd is the laravel version of var_dump() & die();
//dd($allRoles);
return view('HO.properties', ['properties'=>$allPros]);
}
public function addProperty(){
return view('HO.addproperty');
}
public function saveProperty(Request $request){
$prop = new property();
$prop->National_id=$request->National_id;
$prop->Plot_No=$request->plot_no;
$prop->Property_Ad=$request->Property_Ad;
$prop->Property_Photo=$request->Property_Photo;
$prop->Property_features=$request->Property_features;
$prop->county_id=$request->county_id;
$prop->sc_id=$request->sc_id;
$prop->town_id=$request->town_id;
$prop->type=$request->type;
if($request->hasFile('Property_photo')){
$file = $request->file('Property_photo');
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('uploads/properties', $filename);
$prop->Property_Photo = $filename;
}
$prop->save();
return redirect('properties')->with('status',"New Property added.");
}
public function editProperty(){
}
}
basically it is indicating that the county_id field is being sent empty or null to the database, in your form the county_id field is called County, you need to change it:
<select id="County" class="form-select-lg mb-3 form-control" wire:model = "selectedCounty" name="County">
to
<select id="County" class="form-select-lg mb-3 form-control" wire:model = "selectedCounty" name="county_id">
https://prnt.sc/vo986i - this is the default select dropdown menu that WHMCS provides.
https://prnt.sc/vo98m5 - this is the design I made in Figma.
I don't often work with WHMCS, I want to keep the functionality and just make it a multiple boxes choice rather than a dropdown.
{if $pricing.type eq "recurring"}
<div class="field-container">
<div class="form-group">
<label for="inputBillingcycle">{$LANG.cartchoosecycle}</label>
<select name="billingcycle" id="inputBillingcycle" class="form-control select-inline" onchange="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}">
{if $pricing.monthly}
<option value="monthly"{if $billingcycle eq "monthly"} selected{/if}>
{$pricing.monthly}
</option>
{/if}
{if $pricing.quarterly}
<option value="quarterly"{if $billingcycle eq "quarterly"} selected{/if}>
{$pricing.quarterly}
</option>
{/if}
{if $pricing.semiannually}
<option value="semiannually"{if $billingcycle eq "semiannually"} selected{/if}>
{$pricing.semiannually}
</option>
{/if}
{if $pricing.annually}
<option value="annually"{if $billingcycle eq "annually"} selected{/if}>
{$pricing.annually}
</option>
{/if}
{if $pricing.biennially}
<option value="biennially"{if $billingcycle eq "biennially"} selected{/if}>
{$pricing.biennially}
</option>
{/if}
{if $pricing.triennially}
<option value="triennially"{if $billingcycle eq "triennially"} selected{/if}>
{$pricing.triennially}
</option>
{/if}
</select>
</div>
</div>
{/if}
This is the code that WHMCS provides for the default billing cycle choice.
Thanks
Give this a go, it should work, changed the option values to radio boxes and stripped out the select box.
You will need to add your own classes for the design.
<div class="field-container">
<div class="form-group">
<label for="inputBillingcycle">{$LANG.cartchoosecycle}</label>
{if $pricing.monthly}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="monthly" name="billingcycle" value="monthly"> {$pricing.monthly}
{/if}
{if $pricing.quarterly}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="quarterly" name="billingcycle" value="quarterly"> {$pricing.quarterly}
{/if}
{if $pricing.semiannually}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="semiannually" name="billingcycle" value="semiannually"> {$pricing.semiannually}
{/if}
{if $pricing.annually}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="annually" name="billingcycle" value="annually"> {$pricing.annually}
{/if}
{if $pricing.biennially}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="biennially" name="billingcycle" value="biennially"> {$pricing.biennially}
{/if}
{if $pricing.triennially}
<input onclick="{if $configurableoptions}updateConfigurableOptions({$i}, this.value);{else}recalctotals();{/if}" type="radio" id="biennially" name="billingcycle" value="biennially"> {$pricing.triennially}
{/if}
</div>
</div>
{/if}```
I use Prestashop 1.7.6
I need to display the product availability on each product detail on Cart.
What have i to add to the cart-detailed-product-line.tpl and/or other files?
Try with:
{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && !$product.allow_oosp}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="available-dif">
<link itemprop="availability" href="http://schema.org/LimitedAvailability" />{l s='Product available with different options'}
</span>
{else}
<span class="out-of-stock">
<link itemprop="availability" href="http://schema.org/OutOfStock" />{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}
Add it where you want to display this information.
**UPDATE*
Try with this code:
<div class="product-line-grid">
<!-- product left content: image-->
<div class="product-line-grid-left col-md-3 col-xs-3">
<span class="product-image media-middle">
<img src="{$product.cover.bySize.cart_default.url}" alt="{$product.name|escape:'quotes'}">
</span>
</div>
<!-- product left body: description -->
<div class="product-line-grid-body col-md-4 col-xs-6">
<div class="product-line-info">
<a class="label" href="{$product.url}" data-id_customization="{$product.id_customization|intval}">{$product.name}</a>
</div>
<div class="product-line-info product-price h5 {if $product.has_discount}has-discount{/if}">
{if $product.has_discount}
<div class="product-discount">
<span class="regular-price">{$product.regular_price}</span>
<!--{if $product.discount_type === 'percentage'}
<span class="discount discount-percentage">
-{$product.discount_percentage_absolute}
</span>
{else}
<span class="discount discount-amount">
-{$product.discount_to_display}
</span>
{/if}-->
</div>
{/if}
<!--<div class="current-price">
<span class="price">{$product.price}</span>
{if $product.unit_price_full}
<div class="unit-price-cart">{$product.unit_price_full}</div>
{/if}
</div>-->
{if (!$PS_CATALOG_MODE && $PS_STOCK_MANAGEMENT && ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
{if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}
<span itemprop="offers" itemscope itemtype="http://schema.org/Offer" class="availability">
{if ($product.allow_oosp || $product.quantity > 0)}
<span class="{if $product.quantity <= 0 && !$product.allow_oosp}out-of-stock{else}available-now{/if}">
<link itemprop="availability" href="http://schema.org/InStock" />{if $product.quantity <= 0}{if $product.allow_oosp}{if isset($product.available_later) && $product.available_later}{$product.available_later}{else}{l s='In Stock'}{/if}{else}{l s='Out of stock'}{/if}{else}{if isset($product.available_now) && $product.available_now}{$product.available_now}{else}{l s='In Stock'}{/if}{/if}
</span>
{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}
<span class="available-dif">
<link itemprop="availability" href="http://schema.org/LimitedAvailability" />{l s='Product available with different options'}
</span>
{else}
<span class="out-of-stock">
<link itemprop="availability" href="http://schema.org/OutOfStock" />{l s='Out of stock'}
</span>
{/if}
</span>
{/if}
{/if}
</div>
<br/>
{foreach from=$product.attributes key="attribute" item="value"}
<div class="product-line-info">
<span class="label">{$attribute}:</span>
<span class="value">{$value}</span>
</div>
{/foreach}
<div class="col-md-2 col-xs-6 text-xs-right delete">
<div class="cart-line-product-actions">
<a
class = "remove-from-cart"
rel = "nofollow"
href = "{$product.remove_from_cart_url}"
data-link-action = "delete-from-cart"
data-id-product = "{$product.id_product|escape:'javascript'}"
data-id-product-attribute = "{$product.id_product_attribute|escape:'javascript'}"
data-id-customization = "{$product.id_customization|escape:'javascript'}"
>
{if !isset($product.is_gift) || !$product.is_gift}
<span class="float-xs-left"><!--<i class="material-icons">delete_forever</i>-->Rimuovi</span>
{/if}
</a>
{block name='hook_cart_extra_product_actions'}
{hook h='displayCartExtraProductActions' product=$product}
{/block}
</div>
</div>
{if is_array($product.customizations) && $product.customizations|count}
<br>
{block name='cart_detailed_product_line_customization'}
{foreach from=$product.customizations item="customization"}
{l s='Product customization' d='Shop.Theme.Catalog'}
<div class="modal fade customization-modal" id="product-customizations-modal-{$customization.id_customization}" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">{l s='Product customization' d='Shop.Theme.Catalog'}</h4>
</div>
<div class="modal-body">
{foreach from=$customization.fields item="field"}
<div class="product-customization-line row">
<div class="col-sm-3 col-xs-4 label">
{$field.label}
</div>
<div class="col-sm-9 col-xs-8 value">
{if $field.type == 'text'}
{if (int)$field.id_module}
{$field.text nofilter}
{else}
{$field.text}
{/if}
{elseif $field.type == 'image'}
<img src="{$field.image.small.url}">
{/if}
</div>
</div>
{/foreach}
</div>
</div>
</div>
</div>
{/foreach}
{/block}
{/if}
</div>
<!-- product left body: description -->
<div class="product-line-grid-right product-line-actions col-md-5 col-xs-3">
<div class="row">
<!--<div class="col-xs-4 hidden-md-up"></div>-->
<div class="col-md-10 col-xs-12">
<div class="row">
<div class="col-md-6 col-xs-12 price">
<span class="product-price">
<strong>
{if isset($product.is_gift) && $product.is_gift}
<span class="gift">{l s='Gift' d='Shop.Theme.Checkout'}</span>
{else}
{$product.total}
{/if}
</strong>
</span>
</div>
<div class="col-md-6 col-xs-12 qty">
{if isset($product.is_gift) && $product.is_gift}
<span class="gift-quantity">{$product.quantity}</span>
{else}
<input
class="js-cart-line-product-quantity"
data-down-url="{$product.down_quantity_url}"
data-up-url="{$product.up_quantity_url}"
data-update-url="{$product.update_quantity_url}"
data-product-id="{$product.id_product}"
type="number"
value="{$product.quantity}"
name="product-quantity-spin"
min="{$product.minimal_quantity}"
/>
{/if}
</div>
</div>
</div>
</div>
</div>
<div class="clearfix"></div>
</div>
In product-details.tpl the features, when grouped, are printed inside a single
For example:
<dl>
<dt>FEATURE</dt>
<dd>Value1 Value2 Value3</dd>
</dl>
I want to print the following:
Code:
<dl>
<dt>FEATURE</dt>
<dd>
<span title="value1">Value1</span>
<span title="value2">Value2</span>
<span title="value2">Value3</span>
</dd>
</dl>
This is the original code
{block name='product_features'}
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
<dd>{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}
I tried
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
<dd>{foreach $feature.value}<span title="{$feature.value|replace:' ':'_'}">{$feature.value|escape:'htmlall'|nl2br nofilter}</span>{/foreach}</dd>
{/foreach}
</dl>
</section>
{/if}
But of course doesn't work..
Most grateful for any help possible.
Thank you
Try with:
{block name='product_features'}
{if $product.grouped_features}
<section>
<h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3>
<dl>
{foreach from=$product.grouped_features item=feature}
<dt>{$feature.name}</dt>
{assign var=detail_feature value="<br />"|explode:$feature.value}
<dd>
{foreach from=$detail_feature item=det_feature}
<span title="{$det_feature|escape:'htmlall'|nl2br nofilter}">{$det_feature|escape:'htmlall'|nl2br nofilter}</span>
{/foreach}
</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}
I have a problem that I can not solve. in prestashop 1.7 I have a tpl file called product.tpl where inside, besides the various data, I call a file with the following code:
`{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
{block name='product_miniature_item'}
<article class="product-miniature js-product-miniature" data-id-product="{$product.id_product}" data-id-product-attribute="{$product.id_product_attribute}" itemscope itemtype="http://schema.org/Product">
<div class="thumbnail-container">
{block name='product_thumbnail'}
<a href="{$product.url}" class="thumbnail product-thumbnail">
<img
src = "{$product.cover.bySize.home_default.url}"
alt = "{if !empty($product.cover.legend)}{$product.cover.legend}{else}{$product.name|truncate:30:'...'}{/if}"
data-full-size-image-url = "{$product.cover.large.url}"
>
</a>
{/block}
<div class="product-description">
{block name='product_name'}
<h1 class="h3 product-title" itemprop="name">{$product.name|truncate:30:'...'}</h1>
{/block}
{block name='product_price_and_shipping'}
{if $product.show_price}
<div class="product-price-and-shipping">
{if $product.has_discount}
{hook h='displayProductPriceBlock' product=$product type="old_price"}
<span class="sr-only">{l s='Regular price' d='Shop.Theme.Catalog'}</span>
<span class="regular-price">{$product.regular_price}</span>
{if $product.discount_type === 'percentage'}
<span class="discount-percentage">{$product.discount_percentage}</span>
{/if}
{/if}
{hook h='displayProductPriceBlock' product=$product type="before_price"}
<span class="sr-only">{l s='Price' d='Shop.Theme.Catalog'}</span>
<span itemprop="price" class="price">{$product.price}</span>
{hook h='displayProductPriceBlock' product=$product type='unit_price'}
{hook h='displayProductPriceBlock' product=$product type='weight'}
<div class="add">
<form action="{$urls.pages.cart}" method="post">
<input type="hidden" value="{$product.id_product}" name="id_product">
<!--<input type="number" style="padding: 3px 13px; float:left; width:30%; margin-left: 10px;" class="input-group form-control" name="qty" min="1" value="1">-->
<a style="cursor: pointer; padding: 3px 13px; margin-left: 10px; background: #ff9600; color: #fff;" data-button-action="add-to-cart" class="addtocart-btn"
{if !$product.add_to_cart_url}
disabled
{/if}>
<i class="material-icons shopping-cart"></i>
{l s='Add' d='Shop.Theme.Actions'}
<a href="{$product.url}" style=" padding: 3px 13px; margin-left: 10px;" class="view-dtls-btn">
{if {$language.iso_code} === 'ar'}
{l s='رأي' d='Shop.Theme.Actions'}
{else}
{l s='View' d='Shop.Theme.Actions'}
{/if}
</a>
</form>
</div>
</div>
{/if}
{/block}
{block name='product_reviews'}
{hook h='displayProductListReviews' product=$product}
{/block}
</div>
{block name='product_flags'}
<ul class="product-flags">
{foreach from=$product.flags item=flag}
<li class="product-flag {$flag.type}">{$flag.label}</li>
{/foreach}
</ul>
{/block}
<div class="highlighted-informations{if !$product.main_variants} no-variants{/if} hidden-sm-down">
{block name='quick_view'}
<a class="quick-view" href="#" data-link-action="quickview">
<i class="material-icons search"></i> {l s='Quick view' d='Shop.Theme.Actions'}
</a>
{/block}
{block name='product_variants'}
{if $product.main_variants}
{include file='catalog/_partials/variant-links.tpl' variants=$product.main_variants}
{/if}
{/block}
</div>
</div>
</article>
{/block}`
and everything works correctly.
what interests me most specifically is the portion of code referred to in this block
{block name='product_variants'}
{include file='catalog/_partials/product-variants.tpl'}
{/block}
The code is:
`<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>`
then I modified the tpl file of the module product.tpl and modal.tpl and inside the main file "product.tpl and modal.tpl", inside the foreach I inserted a part of the code to display the variants and some product html design.
what happens is that I visualize perfectly the formatting but all the values of the variants do not let me see them, specifically this portion of code does not work`<div class="product-variants">
{foreach from=$groups key=id_attribute_group item=group}
<div class="clearfix product-variants-item">
<span class="control-label">{$group.name}</span>
{if $group.group_type == 'select'}
<select
class="form-control form-control-select"
id="group_{$id_attribute_group}"
data-product-attribute="{$id_attribute_group}"
name="group[{$id_attribute_group}]">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<option value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} selected="selected"{/if}>{$group_attribute.name}</option>
{/foreach}
</select>
{elseif $group.group_type == 'color'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="float-xs-left input-container">
<label>
<input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span
{if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if}
{if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if}
><span class="sr-only">{$group_attribute.name}</span></span>
</label>
</li>
{/foreach}
</ul>
{elseif $group.group_type == 'radio'}
<ul id="group_{$id_attribute_group}">
{foreach from=$group.attributes key=id_attribute item=group_attribute}
<li class="input-container float-xs-left">
<label>
<input class="input-radio" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}>
<span class="radio-label">{$group_attribute.name}</span>
</label>
</li>
{/foreach}
</ul>
{/if}
</div>
{/foreach}
</div>`
Obviously the same code in the product page recalls all the variables, while in the home where I recall the contents on the homepage I can not recover them. Where am I wrong? I put hands on prestashop only a few weeks ago and I think I have a confused ideas. I hope little I have been clear, thanks to those who have the patience to answer.
or optional we want to pass the $groups variable in modal.tpl inside ps_shoppingcart please help me..
thnx in advance