Skip to content

Commit

Permalink
Merge branch 'master' into minor
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelbromley committed Sep 27, 2023
2 parents 9e06df0 + 6e826bf commit efbf335
Show file tree
Hide file tree
Showing 13 changed files with 204 additions and 78 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## <small>2.0.8 (2023-09-27)</small>


#### Fixes

* **admin-ui** Fix creating nullable string fields ([7e2c17a](https://github.com/vendure-ecommerce/vendure/commit/7e2c17a)), closes [#2343](https://github.com/vendure-ecommerce/vendure/issues/2343)
* **admin-ui** Fix link to Asset detail from asset picker ([4539de3](https://github.com/vendure-ecommerce/vendure/commit/4539de3)), closes [#2411](https://github.com/vendure-ecommerce/vendure/issues/2411)
* **core** Implement Refund lines fields resolver ([6b4da6c](https://github.com/vendure-ecommerce/vendure/commit/6b4da6c)), closes [#2406](https://github.com/vendure-ecommerce/vendure/issues/2406)
* **core** Prevent negative total from compounded promotions ([0740c87](https://github.com/vendure-ecommerce/vendure/commit/0740c87)), closes [#2385](https://github.com/vendure-ecommerce/vendure/issues/2385)
* **payments-plugin** Fix stripe payment transaction handling (#2402) ([fd8a777](https://github.com/vendure-ecommerce/vendure/commit/fd8a777)), closes [#2402](https://github.com/vendure-ecommerce/vendure/issues/2402)
* **admin-ui** Add image carousel to asset preview dialog (#2370) ([bd834d0](https://github.com/vendure-ecommerce/vendure/commit/bd834d0)), closes [#2370](https://github.com/vendure-ecommerce/vendure/issues/2370) [#2129](https://github.com/vendure-ecommerce/vendure/issues/2129)

## <small>2.0.7 (2023-09-08)</small>


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
>
</ng-container>
<div *ngIf="selectionManager.selection.length === 1">
<a [routerLink]="['./', lastSelected().id]" class="button-ghost">
<a [routerLink]="['/catalog/assets/', lastSelected().id]" (click)="editAssetClick.emit()" class="button-ghost">
<clr-icon shape="pencil"></clr-icon> {{ 'common.edit' | translate }}
<clr-icon shape="arrow right"></clr-icon>
</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import {
ChangeDetectionStrategy,
Component,
EventEmitter,
Input,
OnChanges,
Output,
SimpleChanges,
} from '@angular/core';

import { SelectionManager } from '../../../common/utilities/selection-manager';
import { ModalService } from '../../../providers/modal/modal.service';
Expand All @@ -21,6 +29,7 @@ export class AssetGalleryComponent implements OnChanges {
@Input() canDelete = false;
@Output() selectionChange = new EventEmitter<AssetLike[]>();
@Output() deleteAssets = new EventEmitter<AssetLike[]>();
@Output() editAssetClick = new EventEmitter<void>();

selectionManager = new SelectionManager<AssetLike>({
multiSelect: this.multiSelect,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[assets]="(assets$ | async)! | paginate: paginationConfig"
[multiSelect]="multiSelect"
(selectionChange)="selection = $event"
(editAssetClick)="cancel()"
#assetGalleryComponent
></vdr-asset-gallery>

Expand Down
75 changes: 75 additions & 0 deletions packages/core/e2e/order-promotion.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1942,6 +1942,81 @@ describe('Promotions applied to Orders', () => {
expect(applyCouponCode.totalWithTax).toBe(96);
});

// https://github.com/vendure-ecommerce/vendure/issues/2385
it('prevents negative line price', async () => {
await shopClient.asAnonymousUser();
const item1000 = getVariantBySlug('item-1000')!;
const couponCode1 = '100%_off';
const couponCode2 = '100%_off';
await createPromotion({
enabled: true,
name: '100% discount ',
couponCode: couponCode1,
conditions: [],
actions: [
{
code: productsPercentageDiscount.code,
arguments: [
{ name: 'discount', value: '100' },
{
name: 'productVariantIds',
value: `["${item1000.id}"]`,
},
],
},
],
});
await createPromotion({
enabled: true,
name: '20% discount ',
couponCode: couponCode2,
conditions: [],
actions: [
{
code: productsPercentageDiscount.code,
arguments: [
{ name: 'discount', value: '20' },
{
name: 'productVariantIds',
value: `["${item1000.id}"]`,
},
],
},
],
});

await shopClient.query<
CodegenShop.ApplyCouponCodeMutation,
CodegenShop.ApplyCouponCodeMutationVariables
>(APPLY_COUPON_CODE, { couponCode: couponCode1 });

await shopClient.query<
CodegenShop.AddItemToOrderMutation,
CodegenShop.AddItemToOrderMutationVariables
>(ADD_ITEM_TO_ORDER, {
productVariantId: item1000.id,
quantity: 1,
});

const { activeOrder: check1 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
GET_ACTIVE_ORDER,
);

expect(check1!.lines[0].discountedUnitPriceWithTax).toBe(0);
expect(check1!.totalWithTax).toBe(0);

await shopClient.query<
CodegenShop.ApplyCouponCodeMutation,
CodegenShop.ApplyCouponCodeMutationVariables
>(APPLY_COUPON_CODE, { couponCode: couponCode2 });

const { activeOrder: check2 } = await shopClient.query<CodegenShop.GetActiveOrderQuery>(
GET_ACTIVE_ORDER,
);
expect(check2!.lines[0].discountedUnitPriceWithTax).toBe(0);
expect(check2!.totalWithTax).toBe(0);
});

async function getProducts() {
const result = await adminClient.query<Codegen.GetProductsWithVariantPricesQuery>(
GET_PRODUCTS_WITH_VARIANT_PRICES,
Expand Down
18 changes: 15 additions & 3 deletions packages/core/src/api/resolvers/entity/refund-entity.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
import { Resolver } from '@nestjs/graphql';
import { Parent, ResolveField, Resolver } from '@nestjs/graphql';

import { idsAreEqual } from '../../../common/index';
import { Refund } from '../../../entity/refund/refund.entity';
import { OrderService } from '../../../service/services/order.service';
import { PaymentService } from '../../../service/index';
import { RequestContext } from '../../common/request-context';
import { Ctx } from '../../decorators/request-context.decorator';

@Resolver('Refund')
export class RefundEntityResolver {
constructor(private orderService: OrderService) {}
constructor(private paymentService: PaymentService) {}

@ResolveField()
async lines(@Ctx() ctx: RequestContext, @Parent() refund: Refund) {
if (refund.lines) {
return refund.lines;
}
const payment = await this.paymentService.findOneOrThrow(ctx, refund.paymentId, ['refunds.lines']);
return payment.refunds.find(r => idsAreEqual(r.id, refund.id))?.lines ?? [];
}
}
11 changes: 10 additions & 1 deletion packages/core/src/entity/order-line/order-line.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,16 @@ export class OrderLine extends VendureEntity implements HasCustomFields {
}

addAdjustment(adjustment: Adjustment) {
this.adjustments = this.adjustments.concat(adjustment);
// We should not allow adding adjustments which would
// result in a negative unit price
const maxDiscount = this.proratedLinePrice * -1;
const limitedAdjustment: Adjustment = {
...adjustment,
amount: Math.max(maxDiscount, adjustment.amount),
};
if (limitedAdjustment.amount !== 0) {
this.adjustments = this.adjustments.concat(limitedAdjustment);
}
}

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/payments-plugin/src/stripe/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './stripe.plugin';
export * from './';
export { StripePlugin } from './stripe.plugin';
2 changes: 1 addition & 1 deletion packages/payments-plugin/src/stripe/stripe-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Stripe from 'stripe';
export class VendureStripeClient extends Stripe {
constructor(private apiKey: string, public webhookSecret: string) {
super(apiKey, {
apiVersion: null as any, // Use accounts default version
apiVersion: null as unknown as Stripe.LatestApiVersion, // Use accounts default version
});
}
}
12 changes: 4 additions & 8 deletions packages/payments-plugin/src/stripe/stripe-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ import { CurrencyCode, Order } from '@vendure/core';
* stores money amounts multiplied by 100). See https://github.com/vendure-ecommerce/vendure/issues/1630
*/
export function getAmountInStripeMinorUnits(order: Order): number {
const amountInStripeMinorUnits = currencyHasFractionPart(order.currencyCode)
return currencyHasFractionPart(order.currencyCode)
? order.totalWithTax
: Math.round(order.totalWithTax / 100);
return amountInStripeMinorUnits;
}

/**
Expand All @@ -24,10 +23,7 @@ export function getAmountInStripeMinorUnits(order: Order): number {
* used by Vendure.
*/
export function getAmountFromStripeMinorUnits(order: Order, stripeAmount: number): number {
const amountInVendureMinorUnits = currencyHasFractionPart(order.currencyCode)
? stripeAmount
: stripeAmount * 100;
return amountInVendureMinorUnits;
return currencyHasFractionPart(order.currencyCode) ? stripeAmount : stripeAmount * 100;
}

function currencyHasFractionPart(currencyCode: CurrencyCode): boolean {
Expand All @@ -36,6 +32,6 @@ function currencyHasFractionPart(currencyCode: CurrencyCode): boolean {
currency: currencyCode,
currencyDisplay: 'symbol',
}).formatToParts(123.45);
const hasFractionPart = !!parts.find(p => p.type === 'fraction');
return hasFractionPart;

return !!parts.find(p => p.type === 'fraction');
}
Loading

0 comments on commit efbf335

Please sign in to comment.