Skip to content

Commit

Permalink
dummy test
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhang12 committed Mar 13, 2024
1 parent 5a859ad commit 2d5fbe0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -498,31 +498,10 @@ public void initialize(Compiler compiler) throws CodeException {

@Override
public void apply(Context ctx, Arguments args, Variables variables) throws CodeExecuteException {
// Variable var = variables.first();
// String subscriptionId = args.first();
// JsonNode node = var.node();
// StringBuilder buf = new StringBuilder();
// System.out.println("WKAHJDAKSLDJAS D");
// ObjectNode obj = JsonUtils.createObjectNode();

// JsonNode pricingOptions = CommerceUtils.getPricingOptionsAmongLowestVariant(node);
//
// if (CommerceUtils.hasVariants(node)) {
// JsonNode subscriptionPricingNode = CommerceUtils.getSubscriptionPricing(pricingOptions, subscriptionId);
//
// obj.put("fromText", StringUtils.defaultIfEmpty(
// ctx.resolve(Constants.PRODUCT_PRICE_FROM_TEXT_KEY).asText(), "from {fromPrice}"));
// obj.put("formattedFromPrice", getMoneyString(subscriptionPricingNode, ctx));
// }
//
// JsonNode firstSubscriptionPricingNode = CommerceUtils.getSubscriptionPricing(pricingOptions, null);
//
// obj.put("formattedPriceText", "{price}");
// obj.put("formattedPrice", getMoneyString(firstSubscriptionPricingNode, ctx));

Variable var = variables.first();
StringBuilder buf = new StringBuilder();
executeTemplate(ctx, template, variables.first().node(), true);
// buf.append(subscriptionPriceInfo.asText());
// var.set(buf);
var.set(buf);
}

private static String getMoneyString(JsonNode moneyNode, Context ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,76 +140,6 @@ public static JsonNode getLowestPriceAmongVariants(JsonNode item) {
}
}

public static JsonNode getPricingOptionsAmongLowestVariant(JsonNode item) {
ProductType type = getProductType(item);
JsonNode structuredContent = item.path("structuredContent");

switch (type) {
case PHYSICAL:
case SERVICE:
JsonNode variants = structuredContent.path("variants");
if (variants.size() == 0) {
return null;
}

JsonNode first = variants.get(0);
JsonNode moneyNode = isTruthy(first.path("onSale"))
? first.path("salePriceMoney")
: first.path("priceMoney");

JsonNode pricingOptions = first.path("pricingOptions");

Decimal price = getAmountFromMoneyNode(moneyNode);

for (int i = 1; i < variants.size(); i++) {
JsonNode var = variants.get(i);
JsonNode currentMoneyNode = isTruthy(var.path("onSale"))
? var.path("salePriceMoney")
: var.path("priceMoney");

Decimal current = getAmountFromMoneyNode(currentMoneyNode);
if (current.compare(price) < 0) {
pricingOptions = var.path("pricingOptions");
}
}

return pricingOptions;

default:
return null;
}
}

public static JsonNode getSubscriptionPricing(JsonNode pricingOptions, String subscriptionId) {
JsonNode chosenSubscription = null;

if (pricingOptions == null || pricingOptions.size() == 0) {
return DEFAULT_MONEY_NODE;
}

if (subscriptionId == null) {
chosenSubscription = pricingOptions.get(0);
} else {
for (int i = 0; i < pricingOptions.size(); i++) {
if (subscriptionId.equals(pricingOptions.get(i).path("productSubscriptionOptionId").asText())) {
chosenSubscription = pricingOptions.get(i);
}
}
}

return getMoneyAmountFromPricing(chosenSubscription);
}

public static JsonNode getMoneyAmountFromPricing(JsonNode pricing) {
if (pricing == null) {
return DEFAULT_MONEY_NODE;
}

return isTruthy(pricing.path("onSale"))
? pricing.path("salePriceMoney")
: pricing.path("priceMoney");
}

public static JsonNode getHighestPriceAmongVariants(JsonNode item) {
ProductType type = getProductType(item);
JsonNode structuredContent = item.path("structuredContent");
Expand Down Expand Up @@ -511,7 +441,4 @@ public static boolean isMultipleQuantityAllowedForServices(JsonNode websiteSetti
return storeSettings.get(fieldName).asBoolean(defaultValue);
}

public static JsonNode getDefaultMoneyNode() {
return DEFAULT_MONEY_NODE;
}
}

0 comments on commit 2d5fbe0

Please sign in to comment.