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.
Otra API de ShopifyIt split the excess units off a line and deleted them from the cart.
Pégalo en Rescate de scripts y mira qué reconstruye
- Copia el Ruby con el botón que hay junto a cualquier Script de esta página.
- En tu panel de Shopify, abre Stackable, luego Herramientas y luego Rescate de scripts.
- Pégalo ahí, lee lo que la herramienta dice que va a crear y compáralo con los ajustes de esta página.
Rescate de scripts está en el plan Pro. No se publica nada hasta que le digas cuánto descontaba tu Script antiguo y las dos cifras coincidan al céntimo.
El Script
Otra API de ShopifyPar peligroso D6. Este archivo y su pareja parecen casi idénticos y se comportan de forma distinta, así que lee los dos antes de decidir cuál tienes.
# 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 un Script no es un descuento. Shopify lo construye con otro tipo de función, indicado arriba, que Stackable no ofrece.
Lee la documentación de ShopifyClave del motivo: otherApi.cartCheckoutValidation
Aquí no hay carrito que probar, porque no se construye nada. Pegar esto produce el mensaje de arriba y ninguna campaña.
Dos archivos que parecen iguales
Cada pareja de abajo es una misma forma de Script escrita de dos maneras. Se diferencian en una o dos líneas y hacen cosas distintas, así que lee las dos antes de decidir cuál tienes.
Pareja peligrosa D6
Quantity limit purchase cap (D6)
Otra API de ShopifyNo se reconstruye. 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 = limitY 26 líneas distintas más, en su propia página.
Quantity limit first n discounted (D6)
ReconstruidoSe reconstruye como una oferta bxgy.
Descuento en su propio carrito: $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")Y 9 líneas distintas más, en su propia página.
Preguntas frecuentes
- 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.
Formas de Script relacionadas
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.
Pega tu Script y mira cómo se reconstruye
La reconstrucción se compara con el dinero que cobraba tu Script antiguo antes de que puedas publicarla.