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.
Outra API da ShopifyIt split the excess units off a line and deleted them from the cart.
Cole no Resgate de Scripts e veja o que ele reconstrói
- Copie o Ruby no botão ao lado de qualquer Script desta página.
- No admin da Shopify, abra o Stackable, depois Ferramentas e depois Resgate de Scripts.
- Cole lá, leia o que a ferramenta diz que vai criar e compare com as configurações desta página.
O Resgate de Scripts está no plano Pro. Nada é publicado até você informar quanto o Script antigo descontava e os dois valores baterem no centavo.
O Script
Outra API da ShopifyPar perigoso D6. Este arquivo e o parceiro dele são quase idênticos e se comportam de formas diferentes, então leia os dois antes de decidir qual é o seu.
# 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.
Esta parte de um Script não é um desconto. A Shopify constrói isso com outro tipo de função, citado acima, que o Stackable não oferece.
Leia a documentação da ShopifyChave do motivo: otherApi.cartCheckoutValidation
Não há carrinho para testar aqui, porque nada é criado. Colar isso produz a mensagem acima e nenhuma campanha.
Dois arquivos que parecem iguais
Cada dupla abaixo é a mesma forma de Script escrita de dois jeitos. Elas mudam em uma ou duas linhas e fazem coisas diferentes, então leia as duas antes de decidir qual é a sua.
Dupla perigosa D6
Quantity limit purchase cap (D6)
Outra API da ShopifyNão reconstruído. 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 = limitE mais 26 linhas diferentes, na página dela.
Quantity limit first n discounted (D6)
ReconstruídoReconstruído como oferta bxgy.
Desconto no carrinho dele: $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")E mais 9 linhas diferentes, na página dela.
Perguntas frequentes
- 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.
Formatos de Script relacionados
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.
Cole o seu Script e veja a reconstrução
A reconstrução é comparada com o valor que o seu Script antigo cobrava antes de você poder publicá-la.