Skip to content

Commit

Permalink
Merge pull request #280 from Pinelab-studio/fix/empty-collection-popu…
Browse files Browse the repository at this point in the history
…larity-calculation

Empty Collection Score Calculation Bug fix
  • Loading branch information
martijnvdbrug authored Nov 2, 2023
2 parents da443e1 + 017c119 commit dc89db3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions packages/vendure-plugin-popularity-scores/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.3.0(2023-10-30)

- Add condition to check if a collection is empty as specified in (here)[https://github.com/Pinelab-studio/pinelab-vendure-plugins/issues/279]

# 1.1.0

- Remove unused select statement's while calculating product popularity scores to support Postgres
2 changes: 1 addition & 1 deletion packages/vendure-plugin-popularity-scores/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins: [

## How it works

This plugin exposes an endpoint that can be periodically called: `/order-by-popularity/calculate-scores/your-secret`. This will push a job named `calculate-popularity` to the worker. The worker will handle this message and do the following:
This plugin exposes an endpoint that can be periodically called: `/popularity-scores/:yourchanneltoken/:yoursecret`. This will push a job named `calculate-popularity` to the worker. The worker will handle this message and do the following:

1. Get all orders from the past 12 months. The amount of months should be configurable.
2. Calculate the amount of times each Variant has been sold.
Expand Down
2 changes: 1 addition & 1 deletion packages/vendure-plugin-popularity-scores/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-plugin-popularity-scores",
"version": "1.1.0",
"version": "1.3.0",
"description": "Sort products and collections by popularity based on previously placed orders",
"author": "Martijn van de Brug <[email protected]>",
"homepage": "https://pinelab-plugins.com/",
Expand Down
17 changes: 9 additions & 8 deletions packages/vendure-plugin-popularity-scores/src/sort.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,15 @@ export class SortService implements OnModuleInit {
.map((i) => i.product_id);

const uniqueProductIds = [...new Set(productIds)];

const summedProductsValue = await productSummingQuery
.andWhere('product.id IN (:...ids)', { ids: uniqueProductIds })
.getRawOne();
productScoreSums.push({
id: col.collection_id,
score: summedProductsValue.productScoreSum,
});
if (uniqueProductIds.length) {
const summedProductsValue = await productSummingQuery
.andWhere('product.id IN (:...ids)', { ids: uniqueProductIds })
.getRawOne();
productScoreSums.push({
id: col.collection_id,
score: summedProductsValue.productScoreSum ?? 0,
});
}
}
await collectionsRepo.save(
productScoreSums.map((collection) => {
Expand Down

0 comments on commit dc89db3

Please sign in to comment.