The Script Editor app lets you create scripts that are run each time a customer adds items to their cart. Scripts can have many uses, from discounting products with specific tags to running promotions such as "buy 2, get 1 free". Scripts are written with a Ruby API that allows a great deal of control and flexibility.
discount_code will be present if a discount has been applied to the cart. This does not necessarily mean that the price of the cart will change. For example, if a discount applies to carts above $50, and a script reduces the cart price below $50, discount_code will be present but the price of the cart will not change.
Splits a line item into two line items. take specifies what quantity to remove from the original line item to create the new line item.
This example script splits a line item called original_line_item into two line items. The new line item will have a quantity of 1 (specified by take: 1). The script then applies a discounted price to the new line item with the message "Third hat for 5 dollars".
Returns a list of strings representing the tags that are set for this product.
A categorization that a product can be tagged with, commonly used for filtering and searching.
Returns the vendor of this product.
Kernel is a Ruby module that is included in every class. As a result, its methods are available to every object. These methods act in the same way as global functions act in other languages.
Ends execution of the current script without error. If this is run before anything is assigned to Output.cart, the script has no effect. This is a useful way to exit scripts, for example, if the customer is ineligible to run the script.
customer=Input.cart.customerifcustomer&&customer.email.end_with?("@mycompany.com")# Employees are not eligible for this promotion.exitend