Spring til indhold
Script-eksempler

Migrating an amount off shipping script

Two classes in the generator library are one word apart and inverted. On a $30 rate, one leaves the shopper paying $25 and the other leaves them paying $5, and the bodies are almost the same ternary.

Genopbygget
Hvad dette Script gjorde

It subtracted a fixed sum from every delivery rate, never taking it below free.

Prøv det i din egen butik

Indsæt det i Scripts-redning, og se hvad der bliver bygget

  1. Kopiér Ruby-koden med knappen ved siden af ethvert Script på siden.
  2. Åbn Stackable i Shopify-administrationen, derefter Værktøjer og så Scripts-redning.
  3. 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.

Selve dette Script

Genopbygget

Farligt par D4. 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.

Den oprindelige Ruby-kode

# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP

class FixedDiscount
  def initialize(amount, message)
    @amount = Money.new(cents: 100) * amount
    @message = message
  end

  def apply(rate)
    rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
    rate.apply_discount(rate_discount, { message: @message })
  end
end

CAMPAIGNS = [
  ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
].freeze

CAMPAIGNS.each do |campaign|
  campaign.run(Input.shipping_rates, Input.cart)
end

Output.shipping_rates = Input.shipping_rates
Hvad det bliver til

Genkendt som Shipping discount og genopbygget som et tilbud af typen free_shipping. Det her er de rigtige konfigurationsnøgler, som tilbuddet gemmes med, så du kan tjekke din egen genopbygning felt for felt.

Hver indstilling, skrevet ud
IndstillingVærdiKonfigurationsnøgle
Offer typefree_shippingtype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> $5.00 off eachtiers[0]
Target scopealltarget.scope
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Du bliver bedt om at bekræfte
  • Confirm which products this applies to. We could not read product targeting from the script.
Du får det at vide
  • This discounts every shipping rate at checkout, not one named rate.
Kurven, der beviser det

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.

Kurven, der udløser dette tilbud, og hvad det koster
VareAntalStykpris
Braided USB-C Cable1$14.00
Subtotal$14.00
Levering, normalt $6.90$1.90
Total$14.00

Logget ud, eller logget ind som kunde uden tags.

Beløbet, som værktøjet holder dig op mod

This rebuild only changes shipping. We price shipping against a sample rate rather than the rate your shopper saw, so there is no figure here we could honestly compare. Publishing records that the amount was not checked.

Kurven, der ikke må give noget

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 D4

Shipping fixed amount off (D4)

Genopbygget

Bygges om til et free_shipping-tilbud.

Fragtbesparelse i dens egen kurv: $5.00

Linjer der er forskellige
class FixedDiscount
    rate_discount = rate.price - @amount < Money.zero ? rate.price : @amount
  ShippingDiscount.new(:all, nil, nil, FixedDiscount.new(5, "$5 off shipping")),
Læs Amount off shipping

Shipping fixed price (D4)

Ikke understøttet endnu

Bygges ikke om. We have not built this yet

Linjer der er forskellige
class FixedPriceDiscount
    rate_discount = @amount > rate.price ? rate.price : rate.price - @amount
  ShippingDiscount.new(:all, nil, nil, FixedPriceDiscount.new(5, "Flat rate shipping $5")),
Læs Flat rate shipping

Ofte stillede spørgsmål

Will Stackable rebuild this script?
Yes. Every spelling on this page is rebuilt today as a free_shipping 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 $14.00 plus $1.90 delivery.
What will I have to check before publishing?
Confirm which products this applies to. We could not read product targeting from the script. This discounts every shipping rate at checkout, not one named rate.

Beslægtede Script-typer

Flat rate shipping

Every delivery rate rewritten to one price rather than reduced by an amount.

Percentage off shipping

A share taken off every delivery rate at checkout.

Free shipping over a threshold

Delivery drops to free once the cart is worth enough.

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.

Vi bruger essentielle cookies til at drive dette site, og kun med din tilladelse, analysecookies til at forstå trafik. Læs vores Cookiepolitik.