WinterCMS/ Octoctcms Builder-分类产品分类

发布于 2025-02-01 05:07:01 字数 184 浏览 4 评论 0原文

我在有产品和类别的地方构建了插件(带有构建器)。产品和类别是通过关系表“定义”的。我有产品列表和另一个类别列表。在页面上,我列出了所有类别都可以正常工作。问题在于单个类别视图。现在,单个类别中的产品按添加订单列出。但是我想拥有自己的产品订单或某种重新排序。建筑商在记录列表(类别页面)中提供排序,但在记录详细信息中不提供排序(单类页面)。 感谢您的回答。

I built the plugin (with builder) where I have products and categories. Product and categories are "conected" by relation table. I have list of products and another list of categories. On page where I list my all categories everthing works fine. The problem is with the single category view. Now products in a single category are listed by add order. But I want to have my own order of products or some sort of reordering. Builder delivers sorting in record list (categories page) but not in record details (single category page).
Thanks for answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡墨 2025-02-08 05:07:01

在您的模型中,您已经添加了类别< - >的关系。产品
在这里,您可以添加订单选项以设置订单。

// inside category model
public $hasMany = [
    'products' => [
        \Acme\Shop\Models\Product::class,
        'order' => 'title desc', // <- here although its hardcoded
    ]
];

或者如果您喜欢动态订单,则在页面内代码部分,您可以添加onstart函数并手动获取产品。

function onStart() {
    $id = 1; // just for example you can get category based on slug
    $sortedProducts = Category::find($id)
         ->products()->orderBy('title')->get();
    // dynamic as per your need  ^
    $this['products'] = $sortedProducts;
}

// now in the code section you can use `products` and they will be sorted

如果有疑问,请发表评论

In your model, you have already added relationship like category <-> products
Here you can add an order option to set the order.

// inside category model
public $hasMany = [
    'products' => [
        \Acme\Shop\Models\Product::class,
        'order' => 'title desc', // <- here although its hardcoded
    ]
];

Or if you prefer dynamic order then inside your page code section you can add the onStart function and fetch the product manually.

function onStart() {
    $id = 1; // just for example you can get category based on slug
    $sortedProducts = Category::find($id)
         ->products()->orderBy('title')->get();
    // dynamic as per your need  ^
    $this['products'] = $sortedProducts;
}

// now in the code section you can use `products` and they will be sorted

if any doubt please comment

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文