Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channel awareness for FacetService findByCode #3201

Open
wants to merge 4 commits into
base: minor
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion license/signatures/version1/cla.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@
"created_at": "2024-10-31T08:42:52Z",
"repoId": 136938012,
"pullRequestNo": 3174
},
{
"name": "kkerti",
"id": 47832952,
"comment_id": 2458191015,
"created_at": "2024-11-05T21:33:05Z",
"repoId": 136938012,
"pullRequestNo": 3187
},
{
"name": "shingoaoyama1",
"id": 17615101,
"comment_id": 2459213307,
"created_at": "2024-11-06T10:15:37Z",
"repoId": 136938012,
"pullRequestNo": 3192
}
]
}
}
63 changes: 41 additions & 22 deletions packages/core/src/service/services/facet.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,29 +111,48 @@ export class FacetService {
lang?: LanguageCode,
): Promise<Translated<Facet> | undefined> {
const relations = ['values', 'values.facet'];
const [repository, facetCode, languageCode] =
ctxOrFacetCode instanceof RequestContext
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
[this.connection.getRepository(ctxOrFacetCode, Facet), facetCodeOrLang, lang!]
: [
this.connection.rawConnection.getRepository(Facet),
ctxOrFacetCode,
facetCodeOrLang as LanguageCode,
];
if (ctxOrFacetCode instanceof RequestContext) {
// New method using channel-aware query
return this.connection
.getRepository(ctxOrFacetCode, Facet)
.createQueryBuilder('facet')
.leftJoinAndSelect('facet.values', 'values')
.leftJoinAndSelect('values.facet', 'facetValue')
.where('facet.code = :code', { code: facetCodeOrLang })
.andWhere('facet.channels.id = :channelId', { channelId: ctxOrFacetCode.channelId })
.getOne()
.then(facet => {
if (facet) {
const channelLanguageCode = ctxOrFacetCode.languageCode;
return translateDeep(facet, lang || channelLanguageCode, [
'values',
['values', 'facet'],
]);
}
return undefined;
});
} else {
// Old method
const [repository, facetCode, languageCode] = [
this.connection.rawConnection.getRepository(Facet),
ctxOrFacetCode,
facetCodeOrLang as LanguageCode,
];

// TODO: Implement usage of channelLanguageCode
return repository
.findOne({
where: {
code: facetCode,
},
relations,
})
.then(
facet =>
(facet && translateDeep(facet, languageCode, ['values', ['values', 'facet']])) ??
undefined,
);
return repository
.findOne({
where: {
code: facetCode,
},
relations,
})
.then(facet => {
if (facet) {
return translateDeep(facet, languageCode, ['values', ['values', 'facet']]);
}
return undefined;
});
}
}

/**
Expand Down
9 changes: 5 additions & 4 deletions packages/payments-plugin/src/mollie/mollie.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,12 @@ export class MollieService {
`Unable to find order ${mollieOrder.orderNumber}, unable to process Mollie order ${mollieOrder.id}`,
);
}
if (mollieOrder.status === OrderStatus.expired) {
// Expired is fine, a customer can retry the payment later
return;
}
if (order.orderPlacedAt) {
// Verify if the Vendure order isn't already paid for, and log if so
const paymentWithSameTransactionId = order.payments.find(
p => p.transactionId === mollieOrder.id && p.state === 'Settled',
);
Expand Down Expand Up @@ -293,10 +298,6 @@ export class MollieService {
return;
}
const amount = amountToCents(mollieOrder.amount);
if (mollieOrder.status === OrderStatus.expired) {
// Expired is fine, a customer can retry the payment later
return;
}
if (mollieOrder.status === OrderStatus.paid) {
// Paid is only used by 1-step payments without Authorized state. This will settle immediately
await this.addPayment(ctx, order, amount, mollieOrder, paymentMethod.code, 'Settled');
Expand Down
Loading