Naar de inhoud
Script-voorbeelden

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-API
Wat het Script deed

It split the excess units off a line and deleted them from the cart.

Probeer het in je eigen winkel

Plak het in Scripts-redding en kijk wat eruit komt

  1. Kopieer de Ruby met de knop naast elk Script op deze pagina.
  2. Open in je Shopify-beheer Stackable, dan Hulpmiddelen, dan Scripts-redding.
  3. 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

Andere Shopify-API

Riskant paar D6. Dit bestand en zijn tegenhanger zien er bijna hetzelfde uit en doen iets anders, dus lees ze allebei voordat je bepaalt welke jij hebt.

De oorspronkelijke Ruby

# 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.cart
Wat er met deze gebeurt

This 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.

Dit deel van een Script is geen korting. Shopify bouwt het met een ander functietype, hierboven genoemd, dat Stackable niet levert.

Lees de documentatie van Shopify

Redensleutel: otherApi.cartCheckoutValidation

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 D6

Quantity limit purchase cap (D6)

Andere Shopify-API

Niet opnieuw gebouwd. This needs a different kind of Shopify app

Regels die verschillen
# 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

En nog 26 afwijkende regels, op de eigen pagina.

Purchase quantity limit lezen

Quantity limit first n discounted (D6)

Herbouwd

Opnieuw gebouwd als bxgy-aanbieding.

Korting in de eigen winkelwagen: $23.70

Regels die verschillen
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")

En nog 9 afwijkende regels, op de eigen pagina.

Limit the discounted units lezen

Veelgestelde vragen

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.

Verwante Script-vormen

Limit the discounted units

The discount applied to the first few units only, with the rest at full price.

Remove products by country

Products that could not ship to the shopper’s country, quietly deleted.

Hide a payment method

A payment option taken off checkout under a condition.

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.

We gebruiken essentiële cookies om deze site te laten werken en, alleen met uw toestemming, analytische cookies om verkeer te begrijpen. Lees ons Cookiebeleid.