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

BackPort Update from Main #60

Open
wants to merge 79 commits into
base: releases/250
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 40 commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
a3f1701
test commit
alakhmani Feb 13, 2024
4a8ba7a
update sample shipping calculator for Delivery Estimation
alakhmani Feb 13, 2024
04b36ce
update sample shipping calculator
alakhmani Feb 13, 2024
2af7c33
updated test for delivery estimation fields
alakhmani Feb 14, 2024
77dc051
updated comment
alakhmani Feb 15, 2024
1f8ff40
Merge pull request #50 from forcedotcom/t/commerce/obsidian/updateSam…
alakhmani Feb 15, 2024
1bcc64a
adding test for PromotionCalculatorSample class
patricia-bagzai-sf Feb 16, 2024
49827a9
Merge pull request #51 from forcedotcom/W-14847074/PromotionCalculato…
patricia-bagzai-sf Feb 16, 2024
8b1d07a
Update variable name
patricia-bagzai-sf Feb 19, 2024
a364315
Merge pull request #52 from forcedotcom/@W-14847074/UpdatePromotionCa…
patricia-bagzai-sf Feb 19, 2024
8e06355
[Tax calculator] replaced for loops with iterators
bsrilok Mar 18, 2024
ae773dc
Addressed comments
bsrilok Mar 18, 2024
9b25b3a
code changes
smahbubani99 Mar 18, 2024
0f4f9f5
update unit test
smahbubani99 Mar 18, 2024
114305e
revert comment changes
smahbubani99 Mar 18, 2024
5b7b3a9
update unit test
smahbubani99 Mar 19, 2024
baea2c2
code changes
smahbubani99 Mar 20, 2024
5f354b1
modify utests
smahbubani99 Mar 20, 2024
cc8ed61
Addressed comments
bsrilok Mar 21, 2024
244f3a0
Addressed comments
bsrilok Mar 21, 2024
9cf6c10
change method name
smahbubani99 Mar 21, 2024
6143194
update orchestrator check
smahbubani99 Mar 21, 2024
dda947b
formatting
smahbubani99 Mar 21, 2024
a7923d9
change method name again
smahbubani99 Mar 22, 2024
f036aff
Update CartCalculateSampleUnitTest.cls
smahbubani99 Mar 22, 2024
d8b7615
Merge pull request #54 from forcedotcom/addCouponsToSampleOrchestrator
smahbubani99 Mar 22, 2024
a622066
updating PromotionCalculatorSample example to evalaute BOGO promotion…
patricia-bagzai-sf Mar 26, 2024
aaf5ae4
addressing PR comments
patricia-bagzai-sf Mar 27, 2024
fc67e34
addressed comments
bsrilok Mar 28, 2024
6708c2b
Merge pull request #53 from bsrilok/t/commerce/TaxCalculator
ParameshOddepally Mar 28, 2024
46773ee
updating logic to leverage buyerActionDetails; updating tests
patricia-bagzai-sf Mar 28, 2024
2a12dbb
adding evaluate promotion logic when optionalBuyerActionDetails not p…
patricia-bagzai-sf Apr 2, 2024
6d6a57a
Merge pull request #55 from forcedotcom/W-15061789/optimizePromotoinC…
patricia-bagzai-sf Apr 2, 2024
f3fde2a
@W-15346861-refactored-cart-calculator-apex
bsrilok Apr 24, 2024
0973ccc
@W-15346861-added-test-cases
bsrilok Apr 25, 2024
2f78248
Use proper CartValidationOutputTypeEnum for PricingCalculator
pplat23 Apr 25, 2024
8d929f2
Merge pull request #56 from forcedotcom/fix-cvotype-for-pricingcalcul…
pplat23 Apr 26, 2024
cb5fe17
Fix errors in PricingServiceSample
adarshjain-sf Apr 29, 2024
2550e02
Update comments
adarshjain-sf Apr 30, 2024
95ca63f
Review comments
adarshjain-sf Apr 30, 2024
0f241eb
Update PricingServiceSample.cls
adarshjain-sf Apr 30, 2024
4ac3500
Merge pull request #58 from adarshjain-sf/patch-1
ParameshOddepally May 2, 2024
fe5d211
@W-15346861-addressed-comments
bsrilok May 12, 2024
337c8ef
@W-15346861-addressed-comments
bsrilok May 12, 2024
a84a342
@W-15346861-addressed-comments
bsrilok May 16, 2024
7edf37f
@W-15346861-addressed-comments
bsrilok May 16, 2024
fe5f02a
@W-15346861-adddressed-comments
bsrilok May 21, 2024
4c33c6f
Merge pull request #1 from bsrilok/t/commerce/W-15346861-tax-cart-cal…
bsrilok May 21, 2024
b1f924e
Merge pull request #59 from bsrilok/main
ParameshOddepally May 29, 2024
1a238d7
adding cart endpoint extension samples
balaji0034 May 30, 2024
78beff6
adding cart endpoint samples
balaji0034 May 30, 2024
b97fd25
review comments fix
balaji0034 May 31, 2024
4faa153
adding if else for currency handling
balaji0034 Jun 3, 2024
162d2d2
Update debug logs
ParameshOddepally Jun 4, 2024
4235e58
empty commit to check CLA
balaji0034 Jun 6, 2024
d0a9dab
Merge pull request #62 from balaji0034/W-15359680/cartEndpointExtensi…
balaji0034 Jun 6, 2024
56334d0
Format the file
ParameshOddepally Jun 8, 2024
da354ca
Merge pull request #63 from forcedotcom/origin/addDebugLogs
ParameshOddepally Jun 12, 2024
0ef89c5
Adding debug logs
skumar2-sfdc Jun 20, 2024
507b55c
Adding caught exception to the CartCalculateRuntimeException
skumar2-sfdc Jun 21, 2024
1a1683f
Merge pull request #65 from skumar2-sfdc/pricingCalculatorLogging
skumar2-sfdc Jun 21, 2024
61acced
Added null check for order item unit price to support bundles.
ssomanchi-salesforce Jul 12, 2024
c8a2b55
Updated the sample apex code to process the new recalculationRequeste…
cboscenco-salesforce Jul 12, 2024
5974d82
Merge pull request #66 from ssomanchi-salesforce/create-order-sample-…
gurpreetsainisalesforce Jul 13, 2024
990d4f5
Merge remote-tracking branch 'origin/main' into t/1c-cart-platform/W-…
cboscenco-salesforce Jul 16, 2024
c6d2c7a
Fixes after review.
cboscenco-salesforce Jul 16, 2024
ab490de
Merge pull request #67 from forcedotcom/t/1c-cart-platform/W-16205916…
cboscenco-salesforce Jul 16, 2024
4fdb511
Add sample and tests
l-wei791 Jul 24, 2024
5c05e87
add sample code for commerce inventory dommain, including a test to d…
sf-afoliaco Sep 26, 2024
a6fccc9
make method so can be overriable from the mock
sf-afoliaco Sep 26, 2024
83e4f91
remove fix vaules and add exception for better data validation
sf-afoliaco Sep 27, 2024
cb0fa18
add new test for calculator and comply to folder structure
sf-afoliaco Oct 2, 2024
1488d73
Fix comments
sf-afoliaco Oct 2, 2024
79dda81
address issue since warning are not supported we change the approach
sf-afoliaco Oct 3, 2024
4354939
change from warning to Error
sf-afoliaco Oct 3, 2024
a00dcbe
change method to make more sense
sf-afoliaco Oct 3, 2024
bdf15a0
Merge pull request #70 from sf-afoliaco/t/som/cc-om-not-hotdog/W-1604…
pplat23 Oct 3, 2024
53cbf10
Update test to use new constructor
l-wei791 Jan 23, 2025
73573db
Merge pull request #72 from forcedotcom/t/cc-om-not-hotdog/W-17643044
sf-afoliaco Jan 24, 2025
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
11 changes: 8 additions & 3 deletions commerce/domain/orchestrators/classes/CartCalculateSample.cls
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ global class CartCalculateSample extends CartExtension.CartCalculate {

// Use BuyerActions to decide which calculators to invoke
CartExtension.BuyerActions buyerActions = request.getBuyerActions();
boolean isCouponAppliedInCheckout = isCouponAppliedInCheckout(buyerActions, cart);
boolean runPricing = buyerActions.isCheckoutStarted() || buyerActions.isCartItemChanged();
boolean runPromotions = buyerActions.isCheckoutStarted() || buyerActions.isCouponChanged() || buyerActions.isCartItemChanged();
boolean runInventory = buyerActions.isCheckoutStarted();
boolean runShipping = buyerActions.isDeliveryGroupChanged();
boolean runPostShipping = buyerActions.isDeliveryGroupChanged() || buyerActions.isDeliveryMethodSelected();
boolean runTaxes = buyerActions.isDeliveryGroupChanged() || buyerActions.isDeliveryMethodSelected();
boolean runShipping = buyerActions.isDeliveryGroupChanged() || isCouponAppliedInCheckout;
boolean runPostShipping = buyerActions.isDeliveryGroupChanged() || buyerActions.isDeliveryMethodSelected() || isCouponAppliedInCheckout;
boolean runTaxes = buyerActions.isDeliveryGroupChanged() || buyerActions.isDeliveryMethodSelected() || isCouponAppliedInCheckout;

// OptionalBuyerActionDetails can be used to optimize the various calculators that are invoked
CartExtension.CartCalculateCalculatorRequest calculatorRequest = new CartExtension.CartCalculateCalculatorRequest(cart, request.getOptionalBuyerActionDetails());
Expand Down Expand Up @@ -103,4 +104,8 @@ global class CartCalculateSample extends CartExtension.CartCalculate {

return false;
}

private Boolean isCouponAppliedInCheckout(CartExtension.BuyerActions buyerActions, CartExtension.Cart cart) {
return cart.getStatus() == CartExtension.CartStatusEnum.CHECKOUT && buyerActions.isCouponChanged();
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2023 salesforce.com, inc.
* All Rights Reserved
* Company Confidential
*/

/**
* @description A Sample unit test for CartCalculateSample.
*/
Expand Down Expand Up @@ -109,12 +115,33 @@ global class CartCalculateSampleUnitTest {
assertUnexpectedCalculations(cart, new List<String>{CART_REPRICED, INVENTORY_CHECKED, SHIPPING_RECALCULATED, POST_SHIPPING_COMPLETED, TAXES_RECALCULATED});
}

@IsTest
public static void shouldRunPromotionsAndShippingAndPostShippingAndTaxesWhenBuyerAddsCouponDuringCheckout() {
// Arrange Cart
CartExtension.Cart cart = arrangeCart('Checkout');

// Arrange BuyerActions and BuyerActionDetails as if the Buyer added a coupon at checkout
CartExtension.BuyerActionsMock buyerActions = getBuyerActionsForApplyCouponAtCheckout(cart);
CartExtension.BuyerActionDetails buyerActionDetails = getBuyerActionDetailsForApplyCoupon(cart.getCartAdjustmentBases().get(0));
CartExtension.OptionalBuyerActionDetails optionalBuyerActionDetails = CartExtension.OptionalBuyerActionDetails.of(buyerActionDetails);

// Act
act(new CartExtension.CartCalculateOrchestratorRequest(cart, buyerActions, optionalBuyerActionDetails));

// Assert
assertNoCartValidationOutputs(cart);
assertExpectedCalculations(cart, new List<String>{PROMOTIONS_RECALCULATED, SHIPPING_RECALCULATED, POST_SHIPPING_COMPLETED, TAXES_RECALCULATED});
assertUnexpectedCalculations(cart, new List<String>{CART_REPRICED, INVENTORY_CHECKED});


}

@IsTest
public static void shouldRunPromotionsWhenBuyerRemovesCoupon() {
// Arrange Cart
CartExtension.Cart cart = arrangeCart();

// Arrange BuyerActions and BuyerActionDetails as if the Buyer added a coupon
// Arrange BuyerActions and BuyerActionDetails as if the Buyer deleted a coupon
CartExtension.BuyerActionsMock buyerActions = getBuyerActionsForDeleteCoupon(cart);
CartExtension.BuyerActionDetails buyerActionDetails = getBuyerActionDetailsForDeleteCoupon();
CartExtension.OptionalBuyerActionDetails optionalBuyerActionDetails = CartExtension.OptionalBuyerActionDetails.of(buyerActionDetails);
Expand Down Expand Up @@ -225,6 +252,28 @@ global class CartCalculateSampleUnitTest {
return CartExtension.CartTestUtil.getCart(testCart.Id);
}

private static CartExtension.Cart arrangeCart(String cartStatus) {
Account testAccount = new Account(Name='My Account');
insert testAccount;

WebStore testWebStore = new WebStore(Name='My WebStore');
insert testWebStore;

WebCart testCart = new WebCart(Name='My Cart', WebStoreId=testWebStore.Id, AccountId=testAccount.Id, Status=cartStatus);
insert testCart;

CartDeliveryGroup testDeliveryGroup = new CartDeliveryGroup(Name='My Delivery Group', CartId=testCart.Id);
insert testDeliveryGroup;

CartItem testCartItem = new CartItem(Name='My Cart Item', CartId=testCart.Id, CartDeliveryGroupId=testDeliveryGroup.Id);
insert testCartItem;

WebCartAdjustmentBasis testCartAdjustmentBasis = new WebCartAdjustmentBasis(Name='My Coupon', WebCartId=testCart.Id);
insert testCartAdjustmentBasis;

return CartExtension.CartTestUtil.getCart(testCart.Id);
}

private static void act(CartExtension.CartCalculateOrchestratorRequest request) {
Test.startTest();
cartCalculateSample.calculate(request);
Expand Down Expand Up @@ -357,6 +406,10 @@ global class CartCalculateSampleUnitTest {
return getCouponChangedBuyerActions(cart);
}

private static CartExtension.BuyerActionsMock getBuyerActionsForApplyCouponAtCheckout(CartExtension.Cart cart) {
return getCouponChangedAtCheckoutBuyerActions(cart);
}

private static CartExtension.BuyerActionDetails getBuyerActionDetailsForApplyCoupon(CartExtension.CartAdjustmentBasis cartAdjustmentBasis) {
CartExtension.CouponChange couponChange = new CartExtension.CouponChange.Builder()
.withChangedAdjustmentBasis(CartExtension.OptionalCartAdjustmentBasis.of(cartAdjustmentBasis))
Expand Down Expand Up @@ -462,4 +515,10 @@ global class CartCalculateSampleUnitTest {
buyerActions.setCouponChanged(True);
return buyerActions;
}
}

private static CartExtension.BuyerActionsMock getCouponChangedAtCheckoutBuyerActions(CartExtension.Cart cart) {
CartExtension.BuyerActionsMock buyerActions = new CartExtension.BuyerActionsMock(cart);
buyerActions.setCouponChanged(True);
return buyerActions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class EstimatedActualPricingCalculator extends CartExtension.PricingCartC
if (pricingDataMap == Null) {
// No data returned means there is an issue with underlying 3rd party service. Populate generic error message for the Buyer.
CartExtension.CartValidationOutput cvo = new CartExtension.CartValidationOutput(
CartExtension.CartValidationOutputTypeEnum.SHIPPING,
CartExtension.CartValidationOutputTypeEnum.PRICING,
CartExtension.CartValidationOutputLevelEnum.ERROR);
String errorMessage = getGenericErrorMessage();
cvo.setMessage(errorMessage);
Expand Down
23 changes: 15 additions & 8 deletions commerce/domain/pricing/service/classes/PricingServiceSample.cls
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class PricingServiceSample extends commercestorepricing.PricingService {
// amount, total adjustment amount and total amount. Item level - line id, product id, unit price,
// list price, unit pricebook entry id, unit adjustment amount, total line amount, total adjustment
// amount, total price, and total list price.
//
// Caution: If you're overriding fields containing Salesforce IDs, ensure that they are valid IDs. Otherwise,
// subsequent operations may fail unexpectedly.
public override commercestorepricing.TransactionalPricingResponse processTransactionalPrice(
commercestorepricing.TransactionalPricingRequest request2
) {
Expand All @@ -123,7 +126,6 @@ public class PricingServiceSample extends commercestorepricing.PricingService {
commercestorepricing.TxnPricingResponseItemCollection txnItemCollection = txnResponse.getTxnPricingResponseItems();
for (Integer j = 0; j < txnItemCollection.size(); j++) {
commercestorepricing.TransactionalPricingResponseItem txnItem = txnItemCollection.get(j);
txnItem.setLineId(appendField(prefix, txnItem.getLineId()));
txnItem.setProductId(appendField(prefix, txnItem.getProductId()));
txnItem.setUnitPricePriceBookEntryId(
appendField(prefix, txnItem.getUnitPricePriceBookEntryId())
Expand All @@ -139,13 +141,18 @@ public class PricingServiceSample extends commercestorepricing.PricingService {
txnResponse.getTotalProductAmount() + txnResponse.getTotalAdjustmentAmount()
);

if (!txnItemCollection.isEmpty()) {
// Override success/failure of a product easily by adding an error message to the product. Here
// we are failing the first product in the response.
String customErrorMessage = 'We no longer sell this particular product.';
String localizedErrorMessage = 'Wir verkaufen dieses spezielle Produkt nicht mehr.';
txnItemCollection.get(0).setError(customErrorMessage, localizedErrorMessage);
}
/**
* Override success/failure of a product easily by adding an error message to the product.
* Here is a sample code demonstrating how to set error messages for products.
* We are failing the first product in the response.
* Warning: Uncommenting the code below will cause cart operations to fail.
*/
// if (!txnItemCollection.isEmpty()) {
// String customErrorMessage = 'We no longer sell this particular product.';
// String localizedErrorMessage = 'Wir verkaufen dieses spezielle Produkt nicht mehr.';
// txnItemCollection.get(0).setError(customErrorMessage, localizedErrorMessage);
// }

return txnResponse;
}

Expand Down
Loading