Naar de inhoud
Script-voorbeelden

Migrating a capped percentage discount script

Common on high-value carts and the one place where getting it wrong is wrong in both directions at once: read the cap as the discount and you give $50 flat, drop the cap and you give an uncapped quarter of the cart.

Herbouwd
Wat het Script deed

It worked out a percentage of the cart and then refused to take off more than a stated maximum.

Probeer het in je eigen winkel

Plak het in Scripts-redding en kijk wat eruit komt

  1. Kopieer de Ruby met de knop naast elk Script op deze pagina.
  2. Open in je Shopify-beheer Stackable, dan Hulpmiddelen, dan Scripts-redding.
  3. 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.

Het Script

Herbouwd

Riskant 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.

De oorspronkelijke Ruby

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

Input.cart.line_items.each do |line_item|
  line_price_float = Float((line_item.line_price.cents / 100).to_s)
  percentage = 1 - (((line_price_float / cart_subtotal_float) * total_discount) / line_price_float)
  line_item.change_line_price(line_item.line_price * percentage, message: "25% off, up to $50")
end

Output.cart = Input.cart
Wat het wordt

Herkend als Spend threshold discount 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.

Elke instelling, uitgeschreven
InstellingWaardeConfiguratiesleutel
Offer typespend_goaltype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> 25% offtiers[0]
Target scopealltarget.scope
Maximum discount$50.00maxDiscountAmount
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Er wordt om bevestiging gevraagd
  • Confirm which products this applies to. We could not read product targeting from the script.
Je krijgt te horen
  • The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.
De winkelwagen die het bewijst

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.

De winkelwagen die deze aanbieding activeert, en wat die kost
ArtikelAantalStukprijs
Canvas Belt Bag1$42.00
Aria Wireless Earbuds2$79.00
Subtotaal$200.00
Korting-$50.00
Totaal$150.00

Uitgelogd, of ingelogd als klant zonder tags.

Het bedrag waaraan de tool je toetst

Voor het publiceren vraagt de tool wat je oude Script deed met een winkelwagen die je al hebt. Zet die op 8 van Walnut Desk Organizer voor $26.00 en het antwoord ligt vast.

De korting is $50.00. Het totaal dat de klant betaalde is $158.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.

De winkelwagen die niets mag opleveren

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 D10

Capped percentage discount (D10)

Herbouwd

Opnieuw gebouwd als spend_goal-aanbieding.

Korting in de eigen winkelwagen: $50.00

Regels die verschillen
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.

Capped percentage discount lezen

Fixed total discount cart (D10)

Herbouwd

Opnieuw gebouwd als spend_goal-aanbieding.

Korting in de eigen winkelwagen: $14.00

Regels die verschillen
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 - share
Amount off the order lezen

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 Canvas Belt Bag at $42.00 plus 2 x Aria Wireless Earbuds at $79.00. The engine takes $50.00 off, and checkout charges $150.00.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script. The maximum applies to the whole order and is shared across the discounted items. If your Script capped each line on its own, that gave more away than this does.

Verwante Script-vormen

Amount off the order

One lump sum off the whole cart, spread across the lines.

Fixed price per item

Everything in the clearance line repriced to one round number per unit.

Amount off each item

A flat sum taken off every unit, however many the shopper bought.

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.

We gebruiken essentiële cookies om deze site te laten werken en, alleen met uw toestemming, analytische cookies om verkeer te begrijpen. Lees ons Cookiebeleid.