朋友,请帮助添加过滤器"缺货"在“产品列表”管理面板中。
做了什么:
添加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 }}
的列中,但我明白这是错误的:(
现在需要向控制器或型号添加一些信息吗?
答案 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);