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.
HerbouwdIt skipped any line whose product was already marked down.
Merchants hebben dit op 2 verschillende manieren geschreven, en die betekenen niet allemaal hetzelfde. Elke schrijfwijze staat hieronder met een eigen winkelwagen en eigen cijfers.
Plak het in Scripts-redding en kijk wat eruit komt
- Kopieer de Ruby met de knop naast elk Script op deze pagina.
- Open in je Shopify-beheer Stackable, dan Hulpmiddelen, dan Scripts-redding.
- 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.
Exclude sale items tag proxy (D8)
HerbouwdRiskant paar D8. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
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.cartHerkend als Percentage off en herbouwd als aanbieding van het type volume. Dit zijn de echte configuratiesleutels waarmee de aanbieding wordt opgeslagen, zodat je je eigen herbouw veld voor veld kunt nalopen.
| Instelling | Waarde | Configuratiesleutel |
|---|---|---|
| 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.
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.
- 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 | Aantal | Stukprijs |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotaal | $14.00 | |
| Korting | -$1.40 | |
| Totaal | $12.60 | |
Uitgelogd, of ingelogd als klant zonder tags.
Voor het publiceren vraagt de tool wat je oude Script deed met een winkelwagen die je al hebt. Zet die op 1 van Braided USB-C Cable voor $14.00 en het antwoord ligt vast.
De korting is $1.40. Het totaal dat de klant betaalde is $12.60.
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.
- swap the cart for a single Ceramic Travel Mug
| Artikel | Aantal | Stukprijs |
|---|---|---|
| Ceramic Travel Mug | 1 | $22.00 |
| Subtotaal | $22.00 | |
| Totaal | $22.00 | |
Uitgelogd, of ingelogd als klant zonder tags.
Exclude sale items compare at (D8)
Nog niet mogelijkRiskant paar D8. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
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.
Dit is ons gat, niet dat van Shopify. Shopify staat het toe en wij hebben het niet gebouwd, dus er valt hier niets te linken en niets op het platform af te schuiven.
Redensleutel: unsupported.compareAtExclusion
Er is hier geen winkelwagen om te testen, want er wordt niets gebouwd. Dit plakken levert de melding hierboven op en verder geen campagne.
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 D8
Exclude sale items tag proxy (D8)
HerbouwdOpnieuw gebouwd als volume-aanbieding.
Korting in de eigen winkelwagen: $1.40
next if line_item.variant.product.tags.include?("sale")Exclude sale items compare at (D8)
Nog niet mogelijkNiet opnieuw gebouwd. We have not built this yet
next if line_item.variant.compare_at_price && line_item.variant.compare_at_price > line_item.variant.priceVeelgestelde vragen
- 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.
Verwante Script-vormen
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.
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.