Hoppa till innehåll
Script-exempel

Migrating an exclude sale items script

The same intent, often the same comment in the merchant’s own file, and two completely different answers depending on how the markdown was detected. Getting the pair backwards either refuses something we support or leaks margin on every clearance line.

Ombyggt
Vad detta Script gjorde

It skipped any line whose product was already marked down.

Handlare har skrivit det här på 2 olika sätt, och de betyder inte alla samma sak. Varje variant finns nedan med en egen varukorg och egna siffror.

Testa det i din egen butik

Klistra in det i Scripts-räddning och se vad som byggs

  1. Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
  2. Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
  3. Klistra in det där, läs vad verktyget säger att det ska bygga och jämför med inställningarna på den här sidan.

Scripts-räddning ingår i Pro-planen. Ingenting publiceras förrän du anger vad ditt gamla Script gav i rabatt och båda beloppen stämmer på öret.

Exclude sale items tag proxy (D8)

Ombyggt

Riskabelt par D8. Den här filen och dess motpart ser nästan likadana ut och beter sig olika, så läs båda innan du avgör vilken du har.

Den ursprungliga Ruby-koden

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.product.tags.include?("sale")
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

Output.cart = Input.cart
Vad det blir

Identifierat som Percentage off och ombyggt till ett erbjudande av typen volume. Det här är de verkliga konfigurationsnycklarna som erbjudandet sparas med, så du kan stämma av din egen ombyggnad fält för fält.

Varje inställning, utskriven
InställningVärdeKonfigurationsnyckel
Offer typevolumetype
Countingper_productcounting
Recurrenceoncerecurrence
Tier 1min qty 1 -> 10% offtiers[0]
Target scopealltarget.scope
Target excludessaletarget.excludeIds
MethodautomaticdiscountMethod
Allocationstandardstacking.allocation
Combines with other discountsnostacking
Du kommer att få bekräfta
  • Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
Varukorgen som bevisar det

Byggd i vår publika demobutik, Meridian Goods, så att varje pris här går att räkna efter i stället för att tas på förtroende. Rabatten nedan är vad samma motor som kör i kassan räknar fram för exakt den här varukorgen.

  • Targeting excludes sale. No Meridian Goods product carries those, so every product stays eligible and the exclusion is proved by the campaign settings, not by the cart.
Varukorgen som utlöser erbjudandet, och vad det kostar
ArtikelAntalStyckpris
Braided USB-C Cable1$14.00
Delsumma$14.00
Rabatt-$1.40
Summa$12.60

Utloggad, eller inloggad som kund utan taggar.

Beloppet som verktyget stämmer av dig mot

Före publicering frågar verktyget vad ditt gamla Script gjorde med en varukorg du redan har. Sätt den till 1 av Braided USB-C Cable à $14.00, så är svaret givet.

Rabatten är $1.40. Summan som kunden betalade är $12.60.

Jämförelsen är exakt, ned till minsta enhet i din valuta. Ett öre fel och publiceringen förblir stängd, vilket är hela poängen med steget.

Varukorgen som inte får ge något alls
  • swap the cart for a single Ceramic Travel Mug
Varukorgen som inte får utlösa erbjudandet
ArtikelAntalStyckpris
Ceramic Travel Mug1$22.00
Delsumma$22.00
Summa$22.00

Utloggad, eller inloggad som kund utan taggar.

Exclude sale items compare at (D8)

Stöds inte än

Riskabelt par D8. Den här filen och dess motpart ser nästan likadana ut och beter sig olika, så läs båda innan du avgör vilken du har.

Den ursprungliga Ruby-koden

DISCOUNT_PERCENTAGE = 10

Input.cart.line_items.each do |line_item|
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
  new_price = line_item.original_line_price * (1.0 - (DISCOUNT_PERCENTAGE / 100.0))
  line_item.change_line_price(new_price, message: "10% off full-price items")
end

Output.cart = Input.cart
Vad som händer med den här

We have not built this yet

Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

Det här är vår lucka, inte Shopifys. Shopify tillåter det och vi har inte byggt det, så det finns inget att länka till här och inget att skylla på plattformen.

Orsaksnyckel: unsupported.compareAtExclusion

Det finns ingen varukorg att testa här, eftersom ingenting byggs. Att klistra in det här ger meddelandet ovan och ingen kampanj alls.

Två filer som ser likadana ut

Varje par nedan är samma Script-form skriven på två sätt. De skiljer sig åt på en eller två rader och gör olika saker, så läs båda innan du avgör vilken du har.

Farligt par D8

Exclude sale items tag proxy (D8)

Ombyggt

Byggs om till ett volume-erbjudande.

Rabatt i sin egen varukorg: $1.40

Rader som skiljer sig
  next if line_item.variant.product.tags.include?("sale")
Läs Exclude sale items

Exclude sale items compare at (D8)

Stöds inte än

Byggs inte om. We have not built this yet

Rader som skiljer sig
  next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.price
Läs Exclude sale items

Vanliga frågor

Will Stackable rebuild this script?
It depends on how yours is written. 1 of the 2 spellings on this page are rebuilt today; the rest are refused with a reason. Compare your file against the Ruby above.
What cart proves it works?
1 x Braided USB-C Cable at $14.00. The engine takes $1.40 off, and checkout charges $12.60.
What will I have to check before publishing?
Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
What happens to the part you cannot rebuild?
We have not built this yet. Your Script skipped items that were already marked down. Shopify does give us the sale price, but our checkout query is already at Shopify's cost limit, so we cannot ask for it today. Exclude those products by hand and we can rebuild the rest.

Besläktade Script-former

Scoped to a tag or vendor

A discount limited to products carrying one tag, vendor or type.

Exclude gift cards

Gift cards left out of a discount that would otherwise have hit them.

Line item property

A discount keyed on a property attached to one cart line.

Klistra in ditt Script och se det byggas om

Ombyggnaden stäms av mot beloppet som ditt gamla Script tog ut innan du kan publicera den.

Vi använder nödvändiga cookies för att driva den här webbplatsen, och, bara med ditt tillstånd, analyscookies för att förstå trafiken. Läs vår Cookiepolicy.