Migrating a purchase quantity limit script
Not a discount at all, and full of the exact syntax a BOGO uses, so a careless reader turns a purchase limit into a giveaway. The reliable tell is that it deletes cart lines and never changes a price.
Andet Shopify-APIIt split the excess units off a line and deleted them from the cart.
Indsæt det i Scripts-redning, og se hvad der bliver bygget
- Kopiér Ruby-koden med knappen ved siden af ethvert Script på siden.
- Åbn Stackable i Shopify-administrationen, derefter Værktøjer og så Scripts-redning.
- Indsæt det der, læs hvad værktøjet siger, det vil bygge, og hold det op mod indstillingerne på denne side.
Scripts-redning hører til Pro-abonnementet. Intet bliver udgivet, før du oplyser, hvad dit gamle Script gav i rabat, og de to beløb stemmer helt ned på øret.
Selve dette Script
Andet Shopify-APIFarligt par D6. Denne fil og dens makker ser næsten ens ud og opfører sig forskelligt, så læs dem begge, før du afgør, hvilken du har.
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class QuantityLimit < Campaign
def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
super(condition, customer_qualifier, cart_qualifier, line_item_selector)
@limit_by = limit_by
@limit = limit
end
def run(cart)
return unless qualifies?(cart)
to_delete = []
counts = {}
cart.line_items.each_with_index do |item, index|
next unless @line_item_selector.nil? || @line_item_selector.match?(item)
key = @limit_by == :product ? item.variant.product.id : item.variant.id
counts[key] = 0 unless counts[key]
max_amount = @limit - counts[key]
if max_amount <= 0
to_delete << index
elsif item.quantity > max_amount
item.split(take: max_amount)
counts[key] += max_amount
else
counts[key] += item.quantity
end
end
to_delete.reverse.each { |index| cart.line_items.delete_at(index) }
end
end
CAMPAIGNS = [
QuantityLimit.new(:all, nil, nil, ProductTagSelector.new(:does, :match, ["limited"]), :variant, 2),
].freeze
CAMPAIGNS.each do |campaign|
campaign.run(Input.cart)
end
Output.cart = Input.cartThis needs a different kind of Shopify app
Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.
Denne del af et Script er ikke en rabat. Shopify bygger den med en anden funktionstype, nævnt ovenfor, som Stackable ikke leverer.
Læs Shopifys dokumentationÅrsagsnøgle: otherApi.cartCheckoutValidation
Der er ingen kurv at teste her, fordi der ikke bliver bygget noget. At indsætte det her giver beskeden ovenfor og slet ingen kampagne.
To filer, der ligner hinanden
Hvert par herunder er den samme Script-form skrevet på to måder. De adskiller sig på en eller to linjer og gør noget forskelligt, så læs dem begge, før du afgør, hvilken du har.
Farligt par D6
Quantity limit purchase cap (D6)
Andet Shopify-APIBygges ikke om. This needs a different kind of Shopify app
# GENERATED BY THE SHOPIFY SCRIPT CREATOR APP
class QuantityLimit < Campaign
def initialize(condition, customer_qualifier, cart_qualifier, line_item_selector, limit_by, limit)
super(condition, customer_qualifier, cart_qualifier, line_item_selector)
@limit_by = limit_by
@limit = limitOg 26 flere forskellige linjer, på dens egen side.
Quantity limit first n discounted (D6)
GenopbyggetBygges om til et bxgy-tilbud.
Rabat i dens egen kurv: $23.70
DISCOUNT_PERCENTAGE = 30
MAX_UNITS = 2
num_to_discount = MAX_UNITS
Input.cart.line_items.each_with_index do |line_item, position|
break if num_to_discount <= 0
next unless line_item.variant.product.tags.include?("limited")Og 9 flere forskellige linjer, på dens egen side.
Ofte stillede spørgsmål
- Will Stackable rebuild this script?
- No, and the reason is stated rather than hidden: Your Script blocked or limited checkout, such as a purchase limit or an age check. Shopify builds that with the Cart and Checkout Validation API, which Stackable does not ship.
Beslægtede Script-typer
The discount applied to the first few units only, with the rest at full price.
Products that could not ship to the shopper’s country, quietly deleted.
A payment option taken off checkout under a condition.
Indsæt dit Script og se det blive genopbygget
Genopbygningen holdes op mod det beløb, dit gamle Script opkrævede, før du kan udgive den.