在 opencart 管理面板中过滤所有产品 <= 10 数量

Filter all products <= 10 quantity in opencart admin panel

我想在管理面板中获取数量在 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);

我想告诉 url 我想要所有数量 <= 10 且状态 = 1 的产品 这是 url:

http://local.loc/admin/index.php?route=catalog/product&token=lNcGHcKRXDz02nQlrw83sRB7UzV4HViz&filter_quantity<=10&filter_status=1

问题是如果它们只等于特定数量,我就可以获得所有产品。我还尝试了以下 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

但是没有用。我怎样才能获得数量 <=10 的所有产品?

从 REST 的角度来看,您应该像 url

中那样传递它
&lesseq=10&filter_status=1

对于 filter_quantity 变量,lesseq 应该是 <= 但是请检查 REST URL design for greater than, less than operations 因为我相信你可以实现完全相同的答案

使用以下方法之一:

admin\model\catalog\product.php

查找:$sql .= " AND p.quantity = '" . (int)$data['filter_quantity'] . "'";

有两场比赛。

将它们更改为:$sql .= " AND p.quantity <= '" . (int)$data['filter_quantity'] . "'";

现在这将显示所有数量为 10 或少于 10 的产品:

http://local.loc/admin/index.php?route=catalog/product&token=lNcGHcKRXDz02nQlrw83sRB7UzV4HViz&filter_quantity=10&filter_status=1

admin\controller\catalog\product.php

查找:'filter_quantity' => $filter_quantity,

在之后添加:'filter_quantity_less' => isset($this->request->get['filter_quantity_less']) ? $this->request->get['filter_quantity_less'] : null,

admin\model\catalog\product.php

查找:if (isset($data['filter_quantity']) && !is_null($data['filter_quantity'])) {

有两个匹配项,在它们之前添加:

if (isset($data['filter_quantity_less']) && !is_null($data['filter_quantity_less'])) {
    $sql .= " AND p.quantity <= '" . (int)$data['filter_quantity_less'] . "'";
}

现在您可以像这样在 url 中使用它:

filter_quantity_less=10