Skip to content

Commit

Permalink
Merge pull request #272 from Pinelab-studio/fix/popularity-postgresql
Browse files Browse the repository at this point in the history
Fix Popularity Plugin Error on Postgres Databases
  • Loading branch information
martijnvdbrug authored Oct 25, 2023
2 parents be36aec + b2159d5 commit e882ed2
Show file tree
Hide file tree
Showing 4 changed files with 2,092 additions and 2,315 deletions.
4 changes: 3 additions & 1 deletion packages/vendure-plugin-popularity-scores/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// TODO set correct version number + date and the changes you've made connected to the PR. See this example for the correct format: https://github.com/Pinelab-studio/pinelab-vendure-plugins/blob/main/packages/vendure-plugin-invoices/CHANGELOG.md
# 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/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pinelab/vendure-plugin-popularity-scores",
"version": "1.0.2",
"version": "1.1.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
25 changes: 9 additions & 16 deletions packages/vendure-plugin-popularity-scores/src/sort.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,12 @@ export class SortService implements OnModuleInit {
ordersAfter.setMonth(ordersAfter.getMonth() - 12);
const groupedOrderLines = await orderLineRepo
.createQueryBuilder('orderLine')
.select([
'SUM(orderLine.quantity) as count',
'orderLine.productVariant',
'orderLine.order',
])
.select(['SUM(orderLine.quantity) as count'])
.innerJoin('orderLine.productVariant', 'productVariant')
.addSelect([
'productVariant.deletedAt',
'productVariant.enabled',
'productVariant.id',
])
.innerJoin('orderLine.order', 'order')
.innerJoin('productVariant.product', 'product')
.addSelect(['product.deletedAt', 'product.enabled', 'product.id'])
.addSelect(['product.id'])
.leftJoin('productVariant.collections', 'collection')
.addSelect(['collection.id'])
.innerJoin('order.channels', 'order_channel')
.andWhere('order.orderPlacedAt > :ordersAfter', {
ordersAfter: ordersAfter.toISOString(),
Expand Down Expand Up @@ -138,11 +128,14 @@ export class SortService implements OnModuleInit {
.createQueryBuilder('product')
.select('SUM(product.customFields.popularityScore) AS productScoreSum');
for (const col of allCollectionIds) {
const variantsPartialInfo = await variantsPartialInfoQuery
.andWhere('collection.id= :id', { id: col.collection_id })
.getRawMany();
const variantsPartialInfo = await variantsPartialInfoQuery.andWhere(
'collection.id= :id',
{ id: col.collection_id }
);

const variantsPartialInfoResults = await variantsPartialInfo.getRawMany();

const productIds = variantsPartialInfo
const productIds = variantsPartialInfoResults
.filter((i) => i.product_id != null)
.map((i) => i.product_id);

Expand Down
Loading

0 comments on commit e882ed2

Please sign in to comment.