Migrating a fixed amount off the order script
Its per-item twin has the same constructor, the same literal and the same message string. On a ten-item cart one gives away $5 and the other gives away $50, so the pair is shown together deliberately.
GenopbyggetIt reduced the cart total by one fixed sum, spread across the lines.
Handlende har skrevet det her på 2 forskellige måder, og de betyder ikke alle det samme. Hver variant står nedenfor med sin egen kurv og sine egne tal.
Indsæt det i Scripts-redning, og se hvad der bliver bygget
- Kopiér Ruby-koden med knappen ved siden af ethvert Script på siden.
- Åbn Stackable i Shopify-administrationen, derefter Værktøjer og så Scripts-redning.
- Indsæt det der, læs hvad værktøjet siger, det vil bygge, og hold det op mod indstillingerne på denne side.
Scripts-redning hører til Pro-abonnementet. Intet bliver udgivet, før du oplyser, hvad dit gamle Script gav i rabat, og de to beløb stemmer helt ned på øret.
Fixed total discount cart (D7)
GenopbyggetFarligt par D7. Denne fil og dens makker ser næsten ens ud og opfører sig forskelligt, så læs dem begge, før du afgør, hvilken du har.
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class FixedTotalDiscount
def initialize(amount, message, behaviour = :split)
@amount = Money.new(cents: 100) * amount
@message = message
@discount_applied = Money.zero
@behaviour = behaviour
end
def apply(line_item)
return unless @discount_applied < @amount
discount_to_apply = [(@amount - @discount_applied), line_item.line_price].min
line_item.change_line_price(line_item.line_price - discount_to_apply, message: @message)
@discount_applied += discount_to_apply
end
end
CAMPAIGNS = [
ConditionalDiscount.new(:all, nil, nil, nil, FixedTotalDiscount.new(5, "$5 off your order"), 0),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartGenkendt som Amount off the order og genopbygget som et tilbud af typen spend_goal. Det her er de rigtige konfigurationsnøgler, som tilbuddet gemmes med, så du kan tjekke din egen genopbygning felt for felt.
| Indstilling | Værdi | Konfigurationsnøgle |
|---|---|---|
| Offer type | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $0.00 -> $5.00 off each | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Bygget i vores offentlige demobutik, Meridian Goods, så hver pris her kan efterregnes i stedet for at blive taget på tro. Rabatten nedenfor er det, som den samme motor, der kører i kassen, beregner for præcis denne kurv.
| Vare | Antal | Stykpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Rabat | -$5.00 | |
| Total | $9.00 | |
Logget ud, eller logget ind som kunde uden tags.
Inden du udgiver, spørger værktøjet, hvad dit gamle Script gjorde ved en kurv, du allerede har. Sæt den til 1 af Braided USB-C Cable à $14.00, så ligger svaret fast.
Rabatten er $5.00. Det beløb, kunden betalte, er $9.00.
Sammenligningen er præcis, helt ned til den mindste enhed i din valuta. En øre ved siden af, og udgivelsen forbliver spærret, hvilket er hele pointen med trinnet.
This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.
Fixed total discount cart (D10)
GenopbyggetFarligt par D10. Denne fil og dens makker ser næsten ens ud og opfører sig forskelligt, så læs dem begge, før du afgør, hvilken du har.
MAX_DISCOUNT = Money.new(cents: 10000)
remaining = MAX_DISCOUNT
Input.cart.line_items.each do |line_item|
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "$100 off your order")
remaining = remaining - share
end
Output.cart = Input.cartGenkendt som Amount off the order og genopbygget som et tilbud af typen spend_goal. Det her er de rigtige konfigurationsnøgler, som tilbuddet gemmes med, så du kan tjekke din egen genopbygning felt for felt.
| Indstilling | Værdi | Konfigurationsnøgle |
|---|---|---|
| Offer type | spend_goal | type |
| Counting | per_cart | counting |
| Recurrence | once | recurrence |
| Tier 1 | min spend $0.00 -> $100.00 off each | tiers[0] |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
- A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Bygget i vores offentlige demobutik, Meridian Goods, så hver pris her kan efterregnes i stedet for at blive taget på tro. Rabatten nedenfor er det, som den samme motor, der kører i kassen, beregner for præcis denne kurv.
| Vare | Antal | Stykpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotal | $14.00 | |
| Rabat | -$14.00 | |
| Total | $0.00 | |
Logget ud, eller logget ind som kunde uden tags.
Inden du udgiver, spørger værktøjet, hvad dit gamle Script gjorde ved en kurv, du allerede har. Sæt den til 1 af Braided USB-C Cable à $14.00, så ligger svaret fast.
Rabatten er $14.00. Det beløb, kunden betalte, er $0.00.
Sammenligningen er præcis, helt ned til den mindste enhed i din valuta. En øre ved siden af, og udgivelsen forbliver spærret, hvilket er hele pointen med trinnet.
This rule carries no condition at all, so it fires on any cart holding anything and there is no quiet cart to build. The negative check is an empty cart, which the app runs for you. That is correct behaviour, not a failure.
To filer, der ligner hinanden
Hvert par herunder er den samme Script-form skrevet på to måder. De adskiller sig på en eller to linjer og gør noget forskelligt, så læs dem begge, før du afgør, hvilken du har.
Farligt par D7
Fixed total discount cart (D7)
GenopbyggetBygges om til et spend_goal-tilbud.
Rabat i dens egen kurv: $5.00
class FixedTotalDiscount
def initialize(amount, message, behaviour = :split)
@discount_applied = Money.zero
@behaviour = behaviour
return unless @discount_applied < @amount
discount_to_apply = [(@amount - @discount_applied), line_item.line_price].minOg 3 flere forskellige linjer, på dens egen side.
Amount off per unit (D7)
GenopbyggetBygges om til et volume-tilbud.
Rabat i dens egen kurv: $5.00
class FixedItemDiscount
def initialize(amount, message)
per_item_discount = @amount
discount_to_apply = [(per_item_discount * line_item.quantity), line_item.line_price].min
line_item.change_line_price([line_item.line_price - discount_to_apply, Money.zero].max, message: @message)
ConditionalDiscount.new(:all, nil, nil, nil, FixedItemDiscount.new(5, "$5 off each"), 0),Farligt par D10
Fixed total discount cart (D10)
GenopbyggetBygges om til et spend_goal-tilbud.
Rabat i dens egen kurv: $14.00
MAX_DISCOUNT = Money.new(cents: 10000)
remaining = MAX_DISCOUNT
break if remaining <= Money.zero
share = [line_item.line_price, remaining].min
line_item.change_line_price(line_item.line_price - share, message: "$100 off your order")
remaining = remaining - shareCapped percentage discount (D10)
GenopbyggetBygges om til et spend_goal-tilbud.
Rabat i dens egen kurv: $50.00
DISCOUNT_PERCENTAGE = 25
MAX_DISCOUNT = 50
cart_subtotal_float = Float((Input.cart.subtotal_price.cents / 100).to_s)
raw_discount = cart_subtotal_float * (DISCOUNT_PERCENTAGE / 100.0)
total_discount = [raw_discount, MAX_DISCOUNT].min
line_price_float = Float((line_item.line_price.cents / 100).to_s)Og 2 flere forskellige linjer, på dens egen side.
Ofte stillede spørgsmål
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a spend_goal offer, and the cart above is the one that proves it.
- What cart proves it works?
- 1 x Braided USB-C Cable at $14.00. The engine takes $5.00 off, and checkout charges $9.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script. A fixed amount off the order is spread across the items at checkout, so each line shows part of it rather than one line carrying the whole discount.
Beslægtede Script-typer
A flat sum taken off every unit, however many the shopper bought.
A percentage with a ceiling on it, so a large cart never gave away more than a set maximum.
Everything in the clearance line repriced to one round number per unit.
Indsæt dit Script og se det blive genopbygget
Genopbygningen holdes op mod det beløb, dit gamle Script opkrævede, før du kan udgive den.