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.
HerbouwdIt reduced the cart total by one fixed sum, spread across the lines.
Merchants hebben dit op 2 verschillende manieren geschreven, en die betekenen niet allemaal hetzelfde. Elke schrijfwijze staat hieronder met een eigen winkelwagen en eigen cijfers.
Plak het in Scripts-redding en kijk wat eruit komt
- Kopieer de Ruby met de knop naast elk Script op deze pagina.
- Open in je Shopify-beheer Stackable, dan Hulpmiddelen, dan Scripts-redding.
- Plak het daar, lees wat het hulpmiddel zegt te gaan bouwen en vergelijk dat met de instellingen op deze pagina.
Scripts-redding zit in het Pro-abonnement. Er wordt niets gepubliceerd totdat je vertelt wat je oude Script gaf en beide bedragen tot op de cent kloppen.
Fixed total discount cart (D7)
HerbouwdRiskant paar D7. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
# 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.cartHerkend als Amount off the order en herbouwd als aanbieding van het type spend_goal. Dit zijn de echte configuratiesleutels waarmee de aanbieding wordt opgeslagen, zodat je je eigen herbouw veld voor veld kunt nalopen.
| Instelling | Waarde | Configuratiesleutel |
|---|---|---|
| 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.
Gebouwd in onze openbare demowinkel, Meridian Goods, zodat elke prijs hier na te rekenen is in plaats van op vertrouwen aangenomen. De korting hieronder is wat dezelfde engine die bij het afrekenen draait, voor precies deze winkelwagen berekent.
| Artikel | Aantal | Stukprijs |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotaal | $14.00 | |
| Korting | -$5.00 | |
| Totaal | $9.00 | |
Uitgelogd, of ingelogd als klant zonder tags.
Voor het publiceren vraagt de tool wat je oude Script deed met een winkelwagen die je al hebt. Zet die op 1 van Braided USB-C Cable voor $14.00 en het antwoord ligt vast.
De korting is $5.00. Het totaal dat de klant betaalde is $9.00.
De vergelijking is exact, tot op de kleinste eenheid van je valuta. Eén cent ernaast en publiceren blijft dicht, en daar gaat deze stap juist om.
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)
HerbouwdRiskant paar D10. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
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.cartHerkend als Amount off the order en herbouwd als aanbieding van het type spend_goal. Dit zijn de echte configuratiesleutels waarmee de aanbieding wordt opgeslagen, zodat je je eigen herbouw veld voor veld kunt nalopen.
| Instelling | Waarde | Configuratiesleutel |
|---|---|---|
| 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.
Gebouwd in onze openbare demowinkel, Meridian Goods, zodat elke prijs hier na te rekenen is in plaats van op vertrouwen aangenomen. De korting hieronder is wat dezelfde engine die bij het afrekenen draait, voor precies deze winkelwagen berekent.
| Artikel | Aantal | Stukprijs |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotaal | $14.00 | |
| Korting | -$14.00 | |
| Totaal | $0.00 | |
Uitgelogd, of ingelogd als klant zonder tags.
Voor het publiceren vraagt de tool wat je oude Script deed met een winkelwagen die je al hebt. Zet die op 1 van Braided USB-C Cable voor $14.00 en het antwoord ligt vast.
De korting is $14.00. Het totaal dat de klant betaalde is $0.00.
De vergelijking is exact, tot op de kleinste eenheid van je valuta. Eén cent ernaast en publiceren blijft dicht, en daar gaat deze stap juist om.
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.
Twee bestanden die op elkaar lijken
Elk paar hieronder is dezelfde Script-vorm, op twee manieren geschreven. Ze schelen een of twee regels en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
Gevaarlijk paar D7
Fixed total discount cart (D7)
HerbouwdOpnieuw gebouwd als spend_goal-aanbieding.
Korting in de eigen winkelwagen: $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].minEn nog 3 afwijkende regels, op de eigen pagina.
Amount off per unit (D7)
HerbouwdOpnieuw gebouwd als volume-aanbieding.
Korting in de eigen winkelwagen: $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),Gevaarlijk paar D10
Fixed total discount cart (D10)
HerbouwdOpnieuw gebouwd als spend_goal-aanbieding.
Korting in de eigen winkelwagen: $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)
HerbouwdOpnieuw gebouwd als spend_goal-aanbieding.
Korting in de eigen winkelwagen: $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)En nog 2 afwijkende regels, op de eigen pagina.
Veelgestelde vragen
- 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.
Verwante Script-vormen
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.
Plak je Script en zie het herbouwd worden
De herbouw wordt getoetst aan het bedrag dat je oude Script rekende voordat je hem kunt publiceren.