I wish to realize a table in 3 dimensions with smarty. I have a database with values, that's how it works:
I have several slice of weight -> From 0 to 250, from 250 to 500, .... each slice of weight has 3 prices per zone. France -> 3 prices and tests -> 3 prices
The table should look like this but the problem is that my base resembles this:
I have 2 tables, 1 for prices and 1 for zones.
Here is what I already start doing in PHP and HTML, I recover the single slice but cons I do not see how to display the 3 prices according to the zone and its slice
PHP:
public function displayForm()
{
$html = '';
$id_langue = $this->context->language->id;
$state = OrderState::getOrderStates($id_langue);
$familyProductList = BddProductFamily::getFamilyProduct();
$prices = BddPrice::getPricesRange();
$ranges = BddPrice::getRanges();
$baseUrl = __PS_BASE_URI__;
$this->context->smarty->assign(array(
'zones' => BddZone::getZones(),
'ranges' => $ranges,
'pricesRange' => $prices,
'urlSite' => $baseUrl,
'states' => $state,
'ps16x' => version_compare(_PS_VERSION_, '1.6', '>='),
'ps_version' => _PS_VERSION_,
'module_dir' => $this->url,
'images_url' => $this->url . '/views/img/',
'tpl_url' => dirname(__FILE__) . '/views/templates/admin'
));
$this->context->controller->addCSS($this->_path . '/views/css/styles.css', 'all');
$this->context->controller->addCSS('https://use.fontawesome.com/releases/v5.6.3/css/all.css');
$this->context->controller->addJS($this->_path . '/views/js/configuration.js');
$this->context->controller->addJS($this->_path . '/views/js/tabs.js');
$this->context->controller->addJS($this->_path . '/views/js/script.js');
$html .= $this->context->smarty->fetch(dirname(__FILE__) . '/views/templates/admin/header.tpl');
$html .= $this->context->smarty->fetch(dirname(__FILE__) . '/views/templates/admin/configuration.tpl');
return $html;
}
Request for RANGES:
public static function getRanges()
{
Return Db::getInstance()->executeS('
SELECT DISTINCT ap.weight_min as Mini, ap.weight_max as Maxi
FROM '._DB_PREFIX_.'bdd_price ap');
}
Request for prices:
public static function getPricesRange()
{
Return Db::getInstance()->executeS('
SELECT apz.label as Zone, ap.weight_min as Mini, ap.weight_max as Maxi, ap.shipping_fr as France, ap.shipping_ext as DOMTOM, ap.shipping_aerial as Aerial
FROM '._DB_PREFIX_.'bdd_price ap
LEFT JOIN ps_bdd_price_zone apz ON(ap.id_zone = apz.id_zone)');
}
HTML:
<table class="table table-striped" id="costTable">
<thead>
<tr data-add_range="range_inf">
<th class="range_type">Sera appliquée lorsque le poids est >=</th>
{foreach key=key item=range from=$ranges}
<th class="border_bottom" style="" data-range="{$key}">
<div class="input-group fixed-width-md">
<span class="input-group-addon weight_unit">g</span>
<input required class="form-control" name="weights[{$key}][minWeight]"
type="text" value="{$range.Mini}">
</div>
</th>
{/foreach}
</tr>
<tr data-add_range="range_sup">
<th class="range_type">Sera appliquée lorsque le poids est <</th>
{foreach key=key item=range from=$ranges}
<th class="range_data" style="" data-range="{$key}">
<div class="input-group fixed-width-md">
<span class="input-group-addon weight_unit">g</span>
<input required class="form-control" name="weights[{$key}][maxWeight]"
type="text" value="{$range.Maxi}">
</div>
</th>
{/foreach}
</tr>
</thead>
<tbody>
{foreach $zones as $zone}
<tr data-add_range="data" data-add_range_data="{$zone.id_zone}">
<td>{$zone.label}</td>
{foreach key=key item=price from=$pricesRange}
<td data-range="{$key}">
<div class="input-group fixed-width-md">
<span class="input-group-addon">€</span>
<input required class="form-control" name="costs[{$zone.id_zone}][{$price.shipping_fr}]" type="text"
value="">
</div>
<div class="input-group fixed-width-md">
<span class="input-group-addon">€</span>
<input required class="form-control" name="costs[{$zone.id_zone}][{$price.shipping_ext}]" type="text"
value="">
</div>
<div class="input-group fixed-width-md">
<span class="input-group-addon">€</span>
<input required class="form-control" name="costs[{$zone.id_zone}][{$price.shipping_aerial}]" type="text"
value="">
</div>
<input id="inputId" name="costs[{$zone.id_zone}][{$key}][id]" type="hidden" value="">
</td>
{/foreach}
</tr>
{/foreach}
<td>
<a href="#" onclick="add_new_range();return false;" class="btn btn-default"
id="add_new_range">
Ajouter une nouvelle tranche
</a>
</td>
<td data-range="">
<a href="#" onclick="remove_range();return false;" class="btn btn-default"
id="add_new_range">Supprimer la tranche</a>
</td>
</tbody>
</table>
Thanks for your help.