diff --git a/CHANGELOG.md b/CHANGELOG.md index b6c5987..2cdcd2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## 1.1.4 - 2019-12-17 +### Added +- Add ability to pre-filter purchase patterns (via [@jmauzyk](https://github.com/jmauzyk)) + +### Fixed +- Fix query issues (via [@jmauzyk](https://github.com/jmauzyk)) + ## 1.1.3 - 2019-12-04 ### Fixed - Fix widget error when showing disabled products (Fixes #2) diff --git a/README.md b/README.md index 6396d84..43ed351 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ ![Purchase Patterns](resources/banner.png) # Purchase Patterns -Easily keep track of and show products customers bought together. Plus, sorting by individual and order sales. +Easily keep track of and show products customers bought together. Plus, sorting +by individual and order sales. ## Requirements -This plugin requires Craft CMS 3.0.0 or later, and Craft Commerce 2.0.0-beta.2 or later. +This plugin requires Craft CMS 3.0.0 or later, and Craft Commerce 2.0.0-beta.2 +or later. ## Installation @@ -13,13 +15,16 @@ Purchasable via the Plugin Store. ## Usage -Use the `craft.purchasePatterns.related` function in your templates to get related products that customers also bought. +Use the `craft.purchasePatterns.related` function in your templates to get +related products that customers also bought. ```php -ProductQueryExtended related ( Product|Order $target [, int $limit = 8 [, ProductQuery $paddingQuery = null ] ] ) +ProductQueryExtended related ( Product|Order $target [, int $limit = 8 [, ProductQuery $paddingQuery = null [, array $filter = [] ] ] ] ) ``` -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. +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. ```twig {% set customersAlsoBought = craft.purchasePatterns.related( @@ -30,7 +35,10 @@ The function returns a `ProductQueryExtended`, so you can include additional que Setting `fixedOrder` to true will sort the products by times purchased together. -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`. +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`. ```twig {% set customersAlsoBought = craft.purchasePatterns.related( @@ -42,11 +50,29 @@ The `paddingQuery` allows you to specify a `ProductQuery` that will be used to p **Editor's Note:** `random()` is Postgres specific. Use `RAND()` for MySQL. +`filter` expects an array of properties that will be used to filter the final +result. You can use this to ensure your query always returns the expected number +of results. You can pass any properties that you would otherwise include in the +outer query: + +```twig +{% set customersAlsoBought = craft.purchasePatterns.related( + order, + 20, + craft.products.relatedTo(product.myCategory), + { availableForPurchase: 1 } +).all() %} +``` + +For more info on the filter feature (added by [jmauzyk](https://github.com/jmauzyk)) +see [#3](https://github.com/ethercreative/purchase-patterns/pull/3). + ### Extended Product Query -The extended product query allows you to sort the products by `qtyCount` and `orderCount`. -It extends the base product query, to you can use it the same way as you would `craft.products`. -The `related` query above returns an extended query, as does: +The extended product query allows you to sort the products by `qtyCount` and +`orderCount`. It extends the base product query, to you can use it the same way +as you would `craft.products`. The `related` query above returns an extended +query, as does: ```twig {% set products = craft.purchasePatterns.extended().orderBy('orderCount DESC').all() %} diff --git a/composer.json b/composer.json index 41ae819..ba1e9cf 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ether/purchase-patterns", "description": "Easily keep track of and show products customers bought together. Plus, sorting by individual and order sales.", - "version": "1.1.3", + "version": "1.1.4", "type": "craft-plugin", "license": "proprietary", "minimum-stability": "dev", diff --git a/src/Variable.php b/src/Variable.php index bfdc32a..1895f68 100644 --- a/src/Variable.php +++ b/src/Variable.php @@ -45,7 +45,7 @@ public function related ( $target, $limit = 8, ProductQuery $paddingQuery = null, - array $filters = [] + array $filters = [] ) { $service = PurchasePatterns::getInstance()->getService();