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.
Andere Shopify-APIIt split the excess units off a line and deleted them from the cart.
Fügen Sie es in die Scripts-Rettung ein und sehen Sie, was daraus wird
- Kopieren Sie das Ruby mit der Schaltfläche neben jedem Script auf dieser Seite.
- Öffnen Sie im Shopify-Adminbereich Stackable, dann Tools, dann Scripts-Rettung.
- Fügen Sie es dort ein, lesen Sie, was das Tool bauen will, und vergleichen Sie das mit den Einstellungen auf dieser Seite.
Die Scripts-Rettung gehört zum Pro-Tarif. Nichts wird veröffentlicht, bevor Sie angeben, was Ihr altes Script berechnet hat, und beide Zahlen auf den Cent genau übereinstimmen.
Das Script
Andere Shopify-APIGefährliches Paar D6. Diese Datei und ihr Gegenstück sehen fast gleich aus und verhalten sich unterschiedlich, lesen Sie also beide, bevor Sie entscheiden, welche Sie haben.
# 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.
Dieser Teil eines Scripts ist kein Rabatt. Shopify baut ihn mit einem anderen Funktionstyp, der oben genannt ist und den Stackable nicht anbietet.
Shopifys Dokumentation lesenGrundschlüssel: otherApi.cartCheckoutValidation
Hier gibt es keinen Warenkorb zum Testen, weil nichts gebaut wird. Das Einfügen erzeugt die obige Meldung und überhaupt keine Kampagne.
Zwei Dateien, die gleich aussehen
Jedes Paar unten ist dieselbe Script-Form in zwei Schreibweisen. Sie unterscheiden sich in ein, zwei Zeilen und tun Unterschiedliches. Lesen Sie beide, bevor Sie entscheiden, welche Sie haben.
Gefährliches Paar D6
Quantity limit purchase cap (D6)
Andere Shopify-APIKein Nachbau. 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 = limitUnd 26 weitere abweichende Zeilen, auf der eigenen Seite.
Quantity limit first n discounted (D6)
NachgebautWird als bxgy-Angebot nachgebaut.
Rabatt im eigenen Warenkorb: $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")Und 9 weitere abweichende Zeilen, auf der eigenen Seite.
Häufige Fragen
- 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.
Verwandte Script-Formen
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.
Fügen Sie Ihr Script ein und sehen Sie den Nachbau
Der Nachbau wird mit dem Betrag abgeglichen, den Ihr altes Script berechnet hat, bevor Sie ihn veröffentlichen können.