Create discount applied to compare_at_price

Create discount applied to compare_at_price

urkoG
Shopify Partner
4 0 0

We are working to migrate our Shopify Scripts to Shopify Functions.

I am following the examples to create an automatic discount for specific user tag . I would like to know if I can apply the discount to the compare_at_price instead of the "final" price.  

 This is how we select the target to apply the discount:

 

 

 const targets = input.cart.lines
      .filter(line =>  costumerIsPro &&
        line.merchandise.__typename == "ProductVariant")
      .map(line => {


        const variant = /** @type {ProductVariant} */ (line.merchandise);
        return /** @type {Target} */ ({
          productVariant: {
            id: variant.id
          }
        });
      });

 

 

 

And this the discount properties :

 

return {
      discounts: [
        
        {        
          "message": "50% pro users",
          targets,
          value: {
            percentage: {
              value: "50.0"
            }
          }
        }
      ],
      discountApplicationStrategy: DiscountApplicationStrategy.First
    };

 

The script that I am trying to migrate do the following:

 if item.variant.compare_at_price
            compare_price = item.variant.compare_at_price
          else
            compare_price = item.variant.price
          end
          new_line_price = compare_price * (100 - proDiscountNumber) * 0.01 *  item.quantity
Replies 0 (0)