mattstein / snipcart-craft-plugin

A Craft plugin for browsing Snipcart API information from the Craft control panel.
MIT License
29 stars 5 forks source link

Max Quantity #3

Closed kaspar-allenbach closed 8 years ago

kaspar-allenbach commented 9 years ago

Hi.

I'm just fiddling around with snipcart on craft. I just stumbled over your plugin. Is it somehow possible to define a max quantity in craft and then pass it along to snipcart?

mattstein commented 9 years ago

Hey @Seppentoni! Sure, the Snipcart product definition links support data-item-max-quantity, so you could add a Number field in Craft and use it to generate the markup for the add to cart button.

If your Craft field is called maxQuantity, then, your template's buy button for an entry might look something like this...

<a href="#"
    class="btn snipcart-add-item" 
    data-item-id="{{ entry.id }}" 
    data-item-name="{{ entry.title }}" 
    data-item-price="{{ entry.price }}" 
    data-item-weight="{{ entry.weight }}" 
    data-item-url="{{ entry.url }}" 
    data-item-quantity="1"
    {% if entry.maxQuantity %}data-item-max-quantity="{{ entry.maxQuantity }}" {% endif %}
>

...note that second to last line where we're checking for maxQuantity and passing it on to Snipcart. Super easy!

kaspar-allenbach commented 9 years ago

Yeah, but does snipcart take this number into account automatically? So when I enter '30'. After 30 selling snipcart closes this item down?

mattstein commented 9 years ago

The Snipcart folks wrote a post on this topic, and this Craft plugin could easily be tailored for automated inventory deduction in your setup. This is exactly what Anna Brown did on her project for Sackwear.