Migrating a buy one get one free script
Shopify shipped this as a starter template, so it is everywhere. The line that matters divides the quantity by the paid units PLUS the free one, which is what makes a nine-unit cart earn two free instead of three.
HerbouwdIt split the free units off each complete set and repriced them to zero.
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.
Het Script
HerbouwdRiskant paar D3. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.
BUY = 3
GET = 1
Input.cart.line_items.each do |line_item|
sets = line_item.quantity / (BUY + GET)
free_count = sets * GET
next if free_count == 0
discounted = line_item.split(take: free_count)
discounted.change_line_price(Money.zero, message: "Buy 3 get 1 free")
Input.cart.line_items << discounted
end
Output.cart = Input.cartHerkend als Buy X, get Y en herbouwd als aanbieding van het type bxgy. 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 | bxgy | type |
| Counting | per_group | counting |
| Recurrence | repeat | recurrence |
| Tier 1 | min qty 3 -> free item | tiers[0] |
| Buy quantity | 3 | bxgy.buyQty |
| Get quantity | 1 | bxgy.getQty |
| Get selection | same_item | bxgy.getSelection |
| Reward on the get units | 100% off | bxgy.getDiscountPct |
| Free units are additional | true | bxgy.freeUnitsAreAdditional |
| Target scope | all | target.scope |
| Method | automatic | discountMethod |
| Allocation | standard | stacking.allocation |
| Combines with other discounts | no | stacking |
- Confirm which products this applies to. We could not read product targeting from the script.
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.
| Artikel | Aantal | Stukprijs |
|---|---|---|
| Braided USB-C Cable | 4 | $14.00 |
| Subtotaal | $56.00 | |
| Korting | -$14.00 | |
| Totaal | $42.00 | |
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 4 van Braided USB-C Cable voor $14.00 en het antwoord ligt vast.
De korting is $14.00. Het totaal dat de klant betaalde is $42.00.
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.
- drop to 1 of the same product, under what the rule needs
| Artikel | Aantal | Stukprijs |
|---|---|---|
| Braided USB-C Cable | 1 | $14.00 |
| Subtotaal | $14.00 | |
| Totaal | $14.00 | |
Uitgelogd, of ingelogd als klant zonder tags.
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 D3
Bogo same item free (D3)
HerbouwdOpnieuw gebouwd als bxgy-aanbieding.
Korting in de eigen winkelwagen: $14.00
sets = line_item.quantity / (BUY + GET)Bogo inclusive basis (D3)
HerbouwdOpnieuw gebouwd als bxgy-aanbieding.
Korting in de eigen winkelwagen: $14.00
sets = line_item.quantity / BUYVeelgestelde vragen
- Will Stackable rebuild this script?
- Yes. Every spelling on this page is rebuilt today as a bxgy offer, and the cart above is the one that proves it.
- What cart proves it works?
- 4 x Braided USB-C Cable at $14.00. The engine takes $14.00 off, and checkout charges $42.00.
- What will I have to check before publishing?
- Confirm which products this applies to. We could not read product targeting from the script.
Verwante Script-vormen
The same buy-and-get offer, counted so the reward sits inside each set rather than beside it.
The discount applied to the first few units only, with the rest at full price.
The least expensive thing in the cart discounted, once.
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.