Naar de inhoud
Script-voorbeelden

Migrating a percentage off shipping script

The shipping half of Shopify’s own dialect uses the same class name as the line-item half and stores the opposite fraction in it. One keeps what the shopper pays, the other keeps what comes off.

Herbouwd
Wat het Script deed

It reduced every delivery rate at checkout by a percentage.

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

# ================================ Customizable Settings ================================
DISCOUNT_TYPE = :percent
DISCOUNT_AMOUNT = 10
DISCOUNT_MESSAGE = '10% off shipping'

# ================================ Script Code (do not edit) ================================
class DiscountApplicator
  def initialize(discount_type, discount_amount, discount_message)
    @discount_type = discount_type
    @discount_message = discount_message

    @discount_amount = if discount_type == :percent
      discount_amount * 0.01
    else
      Money.new(cents: 100) * discount_amount
    end
  end

  def apply(shipping_rate)
    discount_amount = if @discount_type == :percent
      shipping_rate.price * @discount_amount
    else
      @discount_amount > shipping_rate.price ? shipping_rate.price : @discount_amount
    end

    shipping_rate.apply_discount(discount_amount, message: @discount_message)
  end
end

class DiscountRatesCampaign
  def initialize(discount_applicator)
    @discount_applicator = discount_applicator
  end

  def run(cart, shipping_rates)
    shipping_rates.each do |shipping_rate|
      @discount_applicator.apply(shipping_rate)
    end
  end
end

CAMPAIGNS = [
  DiscountRatesCampaign.new(
    DiscountApplicator.new(DISCOUNT_TYPE, DISCOUNT_AMOUNT, DISCOUNT_MESSAGE),
  ),
]

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

Output.shipping_rates = Input.shipping_rates
Wat het wordt

Herkend als Shipping discount en herbouwd als aanbieding van het type free_shipping. 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 typefree_shippingtype
Countingper_cartcounting
Recurrenceoncerecurrence
Tier 1min spend $0.00 -> 10% offtiers[0]
Target scopealltarget.scope
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
  • This discounts every shipping rate at checkout, not one named rate.
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
Braided USB-C Cable1$14.00
Subtotaal$14.00
Bezorging, normaal $6.90$6.21
Totaal$14.00

Uitgelogd, of ingelogd als klant zonder tags.

Het bedrag waaraan de tool je toetst

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.

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 D16

Official dialect, shipping applicator (D16)

Herbouwd

Opnieuw gebouwd als free_shipping-aanbieding.

Verzendvoordeel in de eigen winkelwagen: $0.69

Regels die verschillen
DISCOUNT_MESSAGE = '10% off shipping'
      discount_amount * 0.01
  def apply(shipping_rate)
    discount_amount = if @discount_type == :percent
      shipping_rate.price * @discount_amount
      @discount_amount > shipping_rate.price ? shipping_rate.price : @discount_amount

En nog 8 afwijkende regels, op de eigen pagina.

Percentage off shipping lezen

Official dialect, lineitem applicator (D16)

Herbouwd

Opnieuw gebouwd als volume-aanbieding.

Korting in de eigen winkelwagen: $1.40

Regels die verschillen
DISCOUNT_MESSAGE = '10% off everything'
      1 - (discount_amount * 0.01)
  def apply(line_item)
    new_line_price = if @discount_type == :percent
      line_item.line_price * @discount_amount
      [line_item.line_price - (@discount_amount * line_item.quantity), Money.zero].max

En nog 8 afwijkende regels, op de eigen pagina.

Help Center script template lezen

Veelgestelde vragen

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 $0.69 off, and checkout charges $14.00 plus $6.21 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.

Verwante Script-vormen

Help Center script template

The dialect Shopify’s own documentation taught, with its settings block above a do-not-edit banner.

Amount off shipping

A flat sum off the delivery charge, floored at free.

Flat rate shipping

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

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.