Skip to content

Commit

Permalink
Finish 1.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Dec 17, 2019
1 parent 1540299 commit df09565
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
44 changes: 35 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
![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

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(
Expand All @@ -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(
Expand All @@ -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() %}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function related (
$target,
$limit = 8,
ProductQuery $paddingQuery = null,
array $filters = []
array $filters = []
) {
$service = PurchasePatterns::getInstance()->getService();

Expand Down

0 comments on commit df09565

Please sign in to comment.