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.
OmbyggtIt 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.
Klistra in det i Scripts-räddning och se vad som byggs
- Kopiera Ruby-koden med knappen bredvid vilket Script som helst på sidan.
- Öppna Stackable i Shopify-adminen, sedan Verktyg, sedan Scripts-räddning.
- 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)
OmbyggtRiskabelt 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.
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.cartIdentifierat 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.
| Inställning | Värde | Konfigurationsnyckel |
|---|---|---|
| Offer type | volume | type |
| Counting | per_product | counting |
| Recurrence | once | recurrence |
| Tier 1 | min qty 1 -> 10% off | tiers[0] |
| Target scope | all | target.scope |
| Target excludes | sale | target.excludeIds |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Your Script limited this to a tag, vendor, or product type. We carried that filter over, so confirm it selects the products you expect.
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.
| Artikel | Antal | Styckpris |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Delsumma | $14.00 | |
| Rabatt | -$1.40 | |
| Summa | $12.60 | |
Utloggad, eller inloggad som kund utan taggar.
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.
- swap the cart for a single Ceramic Travel Mug
| Artikel | Antal | Styckpris |
|---|---|---|
| Ceramic Travel Mug | 1 | $22.00 |
| Delsumma | $22.00 | |
| Summa | $22.00 | |
Utloggad, eller inloggad som kund utan taggar.
Exclude sale items compare at (D8)
Stöds inte änRiskabelt 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.
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.cartWe 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)
OmbyggtByggs om till ett volume-erbjudande.
Rabatt i sin egen varukorg: $1.40
next if line_item.variant.product.tags.include?("sale")Exclude sale items compare at (D8)
Stöds inte änByggs inte om. We have not built this yet
next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.priceVanliga 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
A discount limited to products carrying one tag, vendor or type.
Gift cards left out of a discount that would otherwise have hit them.
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.