[英]Filter all products <= 10 quantity in opencart admin panel
I want to get all product between 1 and 10 quantity in my admin panel Here's the data in my controller: 我想在管理面板中获取1到10数量之间的所有产品这是控制器中的数据:
$enabled_product = $this->model_catalog_product->getTotalNumberOfEnabledProductsWithLessOrEqualTo10Quantity();
$data['enabled_product'] = $enabled_product;
$data['enabled_product_link'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&filter_quantity=10&filter_status=1', true);
$data['enabled_product_link'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . '&filter_quantity<=10&filter_status=1', true);
I'm trying to tell the url that i want all products with quantity <= 10 and status = 1 Here's the url: 我试图告诉url,我想要数量<= 10且status = 1的所有产品。这是url:
http://local.loc/admin/index.php?route=catalog/product&token=lNcGHcKRXDz02nQlrw83sRB7UzV4HViz&filter_quantity<=10&filter_status=1
The problem is that i can get all products if they are only equal to specific number. 问题是,如果它们仅等于特定数量,我可以获得所有产品。 I also tried the following url: 我也尝试了以下网址:
http://local.loc/admin/index.php?route=catalog/product&token=lNcGHcKRXDz02nQlrw83sRB7UzV4HViz&filter_quantity=10&filter_quantity=9&filter_quantity=8&filter_quantity=7&filter_quantity=6&filter_quantity=5&filter_status=1
But did not work. 但是没有用。 Any ideas how can i get all products with quantity <=10 ? 任何想法我怎么能得到数量小于等于10的所有产品?
from a REST perspective you should pass it like that in the url 从REST的角度来看,您应该像在url中那样传递它
&lesseq=10&filter_status=1
where lesseq should be <=
for the filter_quantity variable however please check REST URL design for greater than, less than operations as i believe you can implement exactly the same Answer 其中lesseq应该<=
对于filter_quantity变量,但是请检查REST URL设计是否大于,小于操作,因为我相信您可以实现完全相同的答案
Use one of these methods: 使用以下方法之一:
In admin\\model\\catalog\\product.php
在admin\\model\\catalog\\product.php
Find: $sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
查找: $sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";
There are two matches. 有两场比赛。
Change them to: $sql .= " AND p.quantity <= '" . (int)$data['filter_quantity'] . "'";
将它们更改为: $sql .= " AND p.quantity <= '" . (int)$data['filter_quantity'] . "'";
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity'] . "'";
Now this will show all products with quantity 10 or less than 10: 现在,这将显示数量为10或少于10的所有产品:
http://local.loc/admin/index.php?route=catalog/product&token=lNcGHcKRXDz02nQlrw83sRB7UzV4HViz&filter_quantity=10&filter_status=1
OR 要么
In admin\\controller\\catalog\\product.php
在admin\\controller\\catalog\\product.php
Find: 'filter_quantity' => $filter_quantity,
查找: 'filter_quantity' => $filter_quantity,
Add after: 'filter_quantity_less' => isset($this->request->get['filter_quantity_less']) ? $this->request->get['filter_quantity_less'] : null,
在以下位置添加: 'filter_quantity_less' => isset($this->request->get['filter_quantity_less']) ? $this->request->get['filter_quantity_less'] : null,
'filter_quantity_less' => isset($this->request->get['filter_quantity_less']) ? $this->request->get['filter_quantity_less'] : null,
In admin\\model\\catalog\\product.php
在admin\\model\\catalog\\product.php
Find: if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
查找: if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {
There are two matches, add before them: 有两个匹配项,在它们之前添加:
if (isset($data['filter_quantity_less']) && !is_null($data['filter_quantity_less'])) {
$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_less'] . "'";
}
Now you can use it in url like this: 现在,您可以像这样在网址中使用它:
filter_quantity_less=10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.