@ikas/bp-storefront 1.4.0-beta.131 → 1.4.0-beta.133
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -724,14 +724,25 @@ export declare function getProductVariantCampaignOffersDiscountPercentage(varian
|
|
|
724
724
|
* A tiered discount defines multiple quantity tiers (`campaign.tieredDiscount.rules`), each with its own
|
|
725
725
|
* amount and quantity range. This resolves every tier against the variant's price and returns the
|
|
726
726
|
* per-tier sell/final prices (both raw numbers and formatted strings), matching the storefront runtime.
|
|
727
|
+
* The raw rules are `IkasProductTieredDiscountRule` (ranges may be null); this function returns the
|
|
728
|
+
* resolved `IkasTieredDiscountProduct` with normalized `{ min, max }` — use the resolved shape, not the raw rule.
|
|
729
|
+
*
|
|
730
|
+
* `sellPrice`/`finalPrice` (and their `formatted*` variants) are PER UNIT; the `*WithQuantity` fields are the
|
|
731
|
+
* tier total for buying the minimum quantity. A `"FIXED_AMOUNT"` discount is applied only to that total, so
|
|
732
|
+
* per-unit `finalPrice` equals `sellPrice` and the saving shows only in `finalPriceWithQuantity`.
|
|
727
733
|
*
|
|
728
734
|
* The discount `amount` is interpreted by `campaign.type`: `"RATIO"` treats it as a percentage,
|
|
729
|
-
* `"FIXED_AMOUNT"` as an absolute money amount subtracted from the tier total.
|
|
735
|
+
* `"FIXED_AMOUNT"` as an absolute money amount subtracted from the tier total. `amount`/`type` are
|
|
736
|
+
* informational — the discount is already applied in the resolved `*Price` fields, so prefer those over
|
|
737
|
+
* recomputing it yourself.
|
|
730
738
|
*
|
|
731
739
|
* `lineItemQuantityRange.min`/`max` are normalized numbers where `0` means "unbounded". In particular
|
|
732
740
|
* `max === 0` marks an open-ended top tier (e.g. "6+" with no upper limit) — render it as "min+" rather
|
|
733
741
|
* than "min–max", and never treat `max` as a real quantity when it is `0`.
|
|
734
742
|
*
|
|
743
|
+
* Each tier's `salesChannelIds` lists the channels it targets (empty/null = all channels). Filter tiers
|
|
744
|
+
* against `IkasStorefrontConfig.salesChannelId` so only those valid for the current storefront are shown.
|
|
745
|
+
*
|
|
735
746
|
* Returns an empty array when the variant has no tiered-discount campaign, when a
|
|
736
747
|
* `PRODUCT_AND_VARIANT` filter excludes this variant, or when no tier defines a quantity range.
|
|
737
748
|
*
|
|
@@ -743,23 +754,36 @@ export declare function getProductVariantCampaignOffersDiscountPercentage(varian
|
|
|
743
754
|
*
|
|
744
755
|
* @example
|
|
745
756
|
* ```typescript
|
|
746
|
-
* import {
|
|
757
|
+
* import {
|
|
758
|
+
* getProductVariantTieredDiscountProducts,
|
|
759
|
+
* getSelectedProductVariant,
|
|
760
|
+
* IkasStorefrontConfig,
|
|
761
|
+
* } from "@ikas/bp-storefront";
|
|
747
762
|
* import { IkasProduct } from "@ikas/bp-storefront";
|
|
748
763
|
*
|
|
749
764
|
* function TieredDiscountTable({ product }: { product: IkasProduct }) {
|
|
750
765
|
* const variant = getSelectedProductVariant(product);
|
|
751
766
|
* const tiers = getProductVariantTieredDiscountProducts(variant);
|
|
767
|
+
* const salesChannelId = IkasStorefrontConfig.salesChannelId;
|
|
752
768
|
*
|
|
753
769
|
* if (!tiers.length) return null;
|
|
754
770
|
*
|
|
755
771
|
* return (
|
|
756
772
|
* <ul>
|
|
757
|
-
* {tiers.map((tier, i) =>
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
773
|
+
* {tiers.map((tier, i) => {
|
|
774
|
+
* // A tier applies when it targets no channels or includes the current one
|
|
775
|
+
* const scoped =
|
|
776
|
+
* !tier.salesChannelIds?.length ||
|
|
777
|
+
* (!!salesChannelId && tier.salesChannelIds.includes(salesChannelId));
|
|
778
|
+
* if (!scoped) return null;
|
|
779
|
+
*
|
|
780
|
+
* return (
|
|
781
|
+
* <li key={i}>
|
|
782
|
+
* Buy {tier.lineItemQuantityRange.min}+ → {tier.formattedFinalPriceWithQuantity}{" "}
|
|
783
|
+
* <s>{tier.formattedSellPriceWithQuantity}</s>
|
|
784
|
+
* </li>
|
|
785
|
+
* );
|
|
786
|
+
* })}
|
|
763
787
|
* </ul>
|
|
764
788
|
* );
|
|
765
789
|
* }
|