dongzangchui2072 2019-01-22 08:48
浏览 24

数组3维智能

I wish to realize a table in 3 dimensions with smarty. I have a database with values, that's how it works:

range

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: price1 price2

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 &gt;=</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 &lt;</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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
    • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥120 计算机网络的新校区组网设计
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等