Opencart的。显示过滤器"缺货状态"在“产品列表”管理面板中

时间:2018-04-26 05:26:55

标签: opencart

朋友,请帮助添加过滤器"缺货"在“产品列表”管理面板中。

enter image description here

做了什么:

添加product_list

      <div class="form-group">            
        <label class="control-label" for="input-stock-status">{{ entry_stock_status }}</label>
          <select name="stock_status_id" id="input-stock-status" class="form-control">
            {% for stock_status in stock_statuses %}
            {% if stock_status.stock_status_id == stock_status_id %}
            <option value="{{ stock_status.stock_status_id }}" selected="selected">{{ stock_status.name }}</option>
            {% else %}
            <option value="{{ stock_status.stock_status_id }}">{{ stock_status.name }}</option>
            {% endif %}
            {% endfor %}
          </select>
      </div>

{{ product.status }}我添加{{ product.stock_status }}的列中,但我明白这是错误的:(

现在需要向控制器或型号添加一些信息吗?

1 个答案:

答案 0 :(得分:1)

在admin / controller / catalog / product.php

在线号附近。 259 添加: -

if (isset($this->request->get['filter_stock_status'])) {
        $filter_stock_status = $this->request->get['filter_stock_status'];
    } else {
        $filter_stock_status = '';
    }
$this->load->model('localisation/stock_status');

    $data['stock_statuses'] = $this->model_localisation_stock_status->getStockStatuses();

添加在filter_status之后无处不在(重要)):

if (isset($this->request->get['filter_stock_status'])) {
        $url .= '&filter_stock_status=' . $this->request->get['filter_stock_status'];
    }

之后:

if (isset($this->request->get['filter_status'])) {
        $url .= '&filter_status=' . $this->request->get['filter_status'];
    }

添加

'filter_stock_status' => $filter_stock_status,

之后:

'filter_quantity' => $filter_quantity,
        'filter_status'   => $filter_status,

添加:

$data['filter_stock_status'] = $filter_stock_status;

<强>后:

$data['filter_status'] = $filter_status;
product_list.twig中的

添加:

<div class="form-group">
          <label class="control-label" for="input-stock-status">{{ entry_stock_status }}</label>
          <select name="filter_stock_status" id="input-stock-status" class="form-control">
             <option value="" {% if filter_stock_status == "" %} {{ 'selected' }} {% endif %}></option>
            {% for stock_status in stock_statuses %}
                <option value="{{ stock_status.stock_status_id}}" {% if filter_stock_status == stock_status.stock_status_id %} {{ 'selected' }} {% endif %}>{{ stock_status.name }}</option>
            {% endfor %}
            <option value="-1" {% if filter_stock_status == -1 %} {{ 'selected' }} {% endif %}>All except out of stock</option>
          </select>
        </div>

添加

var filter_stock_status = $('select[name=\'filter_stock_status\']').val();

if (filter_stock_status !== '') {
    url += '&filter_stock_status=' + encodeURIComponent(filter_stock_status);
}

之后:

var filter_status = $('select[name=\'filter_status\']').val();

if (filter_status !== '') {
    url += '&filter_status=' + encodeURIComponent(filter_status);
}
admin / model / catalog / product.php中的

添加

if (isset($data['filter_stock_status']) && $data['filter_stock_status'] !== '' ) {
        if($data['filter_stock_status'] == -1){
            $sql .= " AND p.stock_status_id <> 5";
        }elseif($data['filter_stock_status'] != -1){    
            $sql .= " AND p.stock_status_id = '" . (int)$data['filter_stock_status'] . "'";
        }
    }

在getProducts函数中

之前

$sql .= " GROUP BY p.product_id";

添加

if (isset($data['filter_stock_status']) && $data['filter_stock_status'] !== '' ) {
        if($data['filter_stock_status'] == -1){
            $sql .= " AND p.stock_status_id <> 5";
        }elseif($data['filter_stock_status'] != -1){    
            $sql .= " AND p.stock_status_id = '" . (int)$data['filter_stock_status'] . "'";
        }
    }

在getTotalProducts($ data = array())函数

中 之前

    $query = $this->db->query($sql);