Skip to content

Commit

Permalink
feat: apply line item discount policy (#1502)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Orlov authored Dec 20, 2024
1 parent 7f0ff08 commit c42f160
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ fragment fullLineItem on LineItemType {
imageUrl
selectedForCheckout
productType
showPlacedPrice
listTotal {
...money
}
product {
...fullLineItemProduct
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ fragment orderLineItemFields on OrderLineItemType {
name
productId
productType
showPlacedPrice
listTotal {
...money
}
product {
id
brandName
Expand Down
111 changes: 61 additions & 50 deletions client-app/core/api/graphql/types.ts

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions client-app/core/types/line-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export type AnyLineItemType = {
id: string;
name?: string;
}[];
showPlacedPrice?: boolean;
listTotal?: MoneyType;
};

export type VendorGroupType<T> = {
Expand Down Expand Up @@ -74,4 +76,6 @@ export type PreparedLineItemType = {
id: string;
name?: string;
}[];
showPlacedPrice?: boolean;
listTotal?: MoneyType;
};
6 changes: 5 additions & 1 deletion client-app/core/utilities/line-items/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,19 @@ function prepareItemPrices(item: AnyLineItemType) {
const salePrice = "salePrice" in item ? item.salePrice : undefined;
const placedPrice = "placedPrice" in item ? item.placedPrice : undefined;
const extendedPrice = "extendedPrice" in item ? item.extendedPrice : undefined;
const listTotal = "listTotal" in item ? item.listTotal : undefined;
return {
listPrice,
salePrice,
placedPrice,
extendedPrice,
actualPrice: placedPrice ?? salePrice ?? listPrice,
listTotal,
};
}

export function prepareLineItem(item: AnyLineItemType, countInCart?: number): PreparedLineItemType {
const { listPrice, extendedPrice, actualPrice } = prepareItemPrices(item);
const { listPrice, extendedPrice, actualPrice, listTotal } = prepareItemPrices(item);

const productType = "productType" in item ? item.productType : undefined;
const isVariation = !!item.product?.masterVariation;
Expand All @@ -70,6 +72,7 @@ export function prepareLineItem(item: AnyLineItemType, countInCart?: number): Pr
listPrice,
actualPrice,
extendedPrice,
listTotal,
quantity,
inStockQuantity,
route,
Expand All @@ -83,6 +86,7 @@ export function prepareLineItem(item: AnyLineItemType, countInCart?: number): Pr
hasVariations: item.product?.hasVariations,
variations: item.product?.variations,
configurationItems: "configurationItems" in item ? item.configurationItems : undefined,
showPlacedPrice: item.showPlacedPrice,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
v-if="withPrice"
class="vc-line-item__price"
:list-price="listPrice"
:actual-price="actualPrice"
:actual-price="showPlacedPrice ? actualPrice : listPrice"
:disabled="disabled"
align="end"
/>
Expand All @@ -100,7 +100,8 @@
<VcProductPrice
v-if="withTotal"
class="vc-line-item__total"
:list-price="total"
:list-price="showPlacedPrice ? total : listTotal"
:actual-price="total"
align="end"
:disabled="disabled"
truncate
Expand Down Expand Up @@ -145,6 +146,7 @@ interface IProps {
listPrice?: MoneyType;
actualPrice?: MoneyType;
total?: MoneyType;
listTotal?: MoneyType;
selectable?: boolean;
selected?: boolean;
removable?: boolean;
Expand All @@ -156,6 +158,7 @@ interface IProps {
withTotal?: boolean;
vendor?: CommonVendor;
browserTarget?: BrowserTargetType;
showPlacedPrice?: boolean;
}
defineEmits<IEmits>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
:list-price="item.listPrice"
:actual-price="item.actualPrice"
:total="item.extendedPrice"
:list-total="item.listTotal"
:with-image="showImage"
:with-properties="showProperties"
:with-price="showPrice"
Expand All @@ -67,6 +68,7 @@
:selectable="selectable"
:selected="selectable && selectedItemIds?.includes(item.id)"
:browser-target="browserTarget"
:show-placed-price="item.showPlacedPrice"
@select="($event) => selectSingleItem(item.id, $event)"
@remove="() => removeSingleItem(item.id)"
>
Expand Down

0 comments on commit c42f160

Please sign in to comment.