Get line item property in Script Editor

SriLakshmiG
Tourist
5 0 1
Hello,
 
I've installed the Script Editor App in my development store.
Followed the instruction from the below reference link and customized the script code
 
I've created a line item property(customer_Discount_Rate) on the cart page.
I'm able to get the key of that line item property in script code as true. But I'm unable to get that value of that line item property.
 
How do I get the value of the line item property in the script code?
 
Following is part of the script code that I've added in the store:
 

cust_disc = 0
cust_dist_msg = "test"

Input.cart.line_items.each do |line_item|

    item_val = line_item.properties
    if item_val.has_key?("customer_Discount_Rate")
       cust_dist_msg = item_val.has_key?("customer_Discount_Rate") - TRUE (working)
      cust_disc = item_val["customer_Discount_Rate"] - Not working
    end
  end

 

DISCOUNTS_FOR_CUSTOMER_TAG = [
{
customer_tag_match_type: :include,
customer_tags: ["wholesale"],
discount_type: :percent,
discount_amount: cust_disc,
discount_message: cust_dist_msg,
},
]

remaining code is same as in the reference link..

 

Any help pointing in the right direction would be appreciated.

0 Likes
SBD_
Shopify Staff
Shopify Staff
1043 141 183

How are you logging the value? I just tested with an "example" line item property, to create a custom message:

 

 

Input.cart.line_items.each do |line_item|
  if line_item.properties.has_key?("example")
    line_item.change_line_price(line_item.line_price * 0.90, message: line_item.properties["example"])
  end
end

Output.cart = Input.cart

Added to cart like so:

 

jQuery.post('/cart/add.js', {
  items: [
    {
      quantity: 1,
      id: ...,
      properties: {
        'example': 'hello'
      }
    }
  ]
});

 

I've created a line item property(customer_Discount_Rate) on the cart page.

Could you be creating cart attributes, instead of line item properties?