diff --git a/__tests__/plugins/resources/f-add-to-cart-btn-10.html b/__tests__/plugins/resources/f-add-to-cart-btn-10.html new file mode 100644 index 0000000..2f58c5f --- /dev/null +++ b/__tests__/plugins/resources/f-add-to-cart-btn-10.html @@ -0,0 +1,26 @@ +:JSON +{ + "item": { + "id": "560c37c1a7c8465c4a71d99a", + "collectionId": "560c37c1a7c8465c4a71d99b", + "structuredContent": { + "productType": "2", + "useCustomAddButtonText": false, + "isSubscribable": true, + "productSubscriptionOptions" : [] + } + }, + "localizedStrings": { + "productSubscribeText": "SUBSCRIBE" + } +} + +:TEMPLATE +{item|add-to-cart-btn} + +:OUTPUT +
+
+
SUBSCRIBE
+
+
\ No newline at end of file diff --git a/__tests__/plugins/resources/f-add-to-cart-btn-8.html b/__tests__/plugins/resources/f-add-to-cart-btn-8.html new file mode 100644 index 0000000..29ed707 --- /dev/null +++ b/__tests__/plugins/resources/f-add-to-cart-btn-8.html @@ -0,0 +1,37 @@ +:JSON +{ + "item": { + "id": "560c37c1a7c8465c4a71d99a", + "collectionId": "560c37c1a7c8465c4a71d99b", + "structuredContent": { + "productType": "2", + "useCustomAddButtonText": false, + "isSubscribable": true, + "productSubscriptionOptions" : [{ + "id" : "2e0c2fbe-bc48-4a5e-9e0f-bb939576a0aa", + "percentageDiscount" : 0, + "subscriptionPlan" : { + "billingPeriod" : { + "value" : 1, + "unit" : "WEEK" + }, + "planVersionId" : "d6803d89-82b8-49a3-ab6d-d9a16c93b5a8", + "numBillingCycles" : 0 + } + }] + } + }, + "localizedStrings": { + "productSubscribeText": "SUBSCRIBE" + } +} + +:TEMPLATE +{item|add-to-cart-btn} + +:OUTPUT +
+
+
SUBSCRIBE
+
+
diff --git a/__tests__/plugins/resources/f-add-to-cart-btn-9.html b/__tests__/plugins/resources/f-add-to-cart-btn-9.html new file mode 100644 index 0000000..5a05760 --- /dev/null +++ b/__tests__/plugins/resources/f-add-to-cart-btn-9.html @@ -0,0 +1,34 @@ +:JSON +{ + "item": { + "id": "560c37c1a7c8465c4a71d99a", + "collectionId": "560c37c1a7c8465c4a71d99b", + "structuredContent": { + "productType": "2", + "useCustomAddButtonText": false, + "isSubscribable": false, + "productSubscriptionOptions" : [{ + "id" : "2e0c2fbe-bc48-4a5e-9e0f-bb939576a0aa", + "percentageDiscount" : 0, + "subscriptionPlan" : { + "billingPeriod" : { + "value" : 1, + "unit" : "WEEK" + }, + "planVersionId" : "d6803d89-82b8-49a3-ab6d-d9a16c93b5a8", + "numBillingCycles" : 0 + } + }] + } + } +} + +:TEMPLATE +{item|add-to-cart-btn} + +:OUTPUT +
+
+
Add To Cart
+
+
\ No newline at end of file diff --git a/__tests__/plugins/resources/f-product-checkout-1.html b/__tests__/plugins/resources/f-product-checkout-1.html index 2b3663a..939c3a5 100644 --- a/__tests__/plugins/resources/f-product-checkout-1.html +++ b/__tests__/plugins/resources/f-product-checkout-1.html @@ -58,6 +58,9 @@ + + +
Add To Cart
diff --git a/src/plugins/templates/add-to-cart-btn.html b/src/plugins/templates/add-to-cart-btn.html index 0577127..de01fb7 100644 --- a/src/plugins/templates/add-to-cart-btn.html +++ b/src/plugins/templates/add-to-cart-btn.html @@ -7,9 +7,12 @@ {.var @addToCartText localizedStrings.productAddToCartText} {.var @subscribeText localizedStrings.productSubscribeText} {.var @isSubscribable @content.isSubscribable} +{.var @productSubscriptionOptions structuredContent.productSubscriptionOptions} +{.var @subsOTPOptionsCount structuredContent.productSubscriptionOptions|count} +{.eval @hasProductSubsOptionAndIsSubscribable = @subsOTPOptionsCount && @isSubscribable}
-
+
{.if @useCustom && @customButton}{@customButton|htmltag}{.or}{.if @isSubscribable}{.if @subscribeText}{@subscribeText|htmltag}{.or}Subscribe{.end}{.or}{.if @addToCartText}{@addToCartText|htmltag}{.or}Add To Cart{.end}{.end}{.end}
diff --git a/src/plugins/templates/add-to-cart-btn.json b/src/plugins/templates/add-to-cart-btn.json index 438dbeb..acda852 100644 --- a/src/plugins/templates/add-to-cart-btn.json +++ b/src/plugins/templates/add-to-cart-btn.json @@ -16,6 +16,12 @@ [6, "@subscribeText", [["localizedStrings", "productSubscribeText"]], 0], [0, "\n"], [6, "@isSubscribable", [["@content", "isSubscribable"]], 0], + [0, "\n"], + [6, "@productSubscriptionOptions", [["structuredContent", "productSubscriptionOptions"]], 0], + [0, "\n"], + [6, "@subsOTPOptionsCount", [["structuredContent", "productSubscriptionOptions"]], [["count"]]], + [0, "\n"], + [23, "@hasProductSubsOptionAndIsSubscribable = @subsOTPOptionsCount && @isSubscribable"], [0, "\n\n
\n
\n
"], [8, [1], [["@useCustom"], ["@customButton"]], [ [1, [["@customButton"]], [["htmltag"]]]