You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function returns a `ProductQueryExtended`, so you can include additional query parameters as needed. The `id` parameter is already set and shouldn't be overridden.
25
+
The function returns a `ProductQueryExtended`, so you can include additional
26
+
query parameters as needed. The `id` parameter is already set and shouldn't be
27
+
overridden.
23
28
24
29
```twig
25
30
{% set customersAlsoBought = craft.purchasePatterns.related(
@@ -30,7 +35,10 @@ The function returns a `ProductQueryExtended`, so you can include additional que
30
35
31
36
Setting `fixedOrder` to true will sort the products by times purchased together.
32
37
33
-
The `paddingQuery` allows you to specify a `ProductQuery` that will be used to pad out the related results if they fall below the given `limit`. This query should NOT include things like `order`, `limit`, or execution commands like `all`.
38
+
The `paddingQuery` allows you to specify a `ProductQuery` that will be used to
39
+
pad out the related results if they fall below the given `limit`. This query
40
+
should NOT include things like `order`, `limit`, or execution commands like
41
+
`all`.
34
42
35
43
```twig
36
44
{% set customersAlsoBought = craft.purchasePatterns.related(
@@ -42,11 +50,29 @@ The `paddingQuery` allows you to specify a `ProductQuery` that will be used to p
42
50
43
51
**Editor's Note:**`random()` is Postgres specific. Use `RAND()` for MySQL.
44
52
53
+
`filter` expects an array of properties that will be used to filter the final
54
+
result. You can use this to ensure your query always returns the expected number
55
+
of results. You can pass any properties that you would otherwise include in the
56
+
outer query:
57
+
58
+
```twig
59
+
{% set customersAlsoBought = craft.purchasePatterns.related(
60
+
order,
61
+
20,
62
+
craft.products.relatedTo(product.myCategory),
63
+
{ availableForPurchase: 1 }
64
+
).all() %}
65
+
```
66
+
67
+
For more info on the filter feature (added by [jmauzyk](https://github.com/jmauzyk))
68
+
see [#3](https://github.com/ethercreative/purchase-patterns/pull/3).
69
+
45
70
### Extended Product Query
46
71
47
-
The extended product query allows you to sort the products by `qtyCount` and `orderCount`.
48
-
It extends the base product query, to you can use it the same way as you would `craft.products`.
49
-
The `related` query above returns an extended query, as does:
72
+
The extended product query allows you to sort the products by `qtyCount` and
73
+
`orderCount`. It extends the base product query, to you can use it the same way
74
+
as you would `craft.products`. The `related` query above returns an extended
75
+
query, as does:
50
76
51
77
```twig
52
78
{% set products = craft.purchasePatterns.extended().orderBy('orderCount DESC').all() %}
0 commit comments