craftcms / shopify

Synchronize and extend product data from your Shopify storefront.
MIT License
45 stars 25 forks source link

Interesting plugin #1

Closed patryk-smc closed 6 years ago

patryk-smc commented 6 years ago

I'm really happy to see first Shopify plugin for Craft. Can you elaborate on how it can be used exactly or show some in-action examples? What kind of product properties can be fetched and used and how to do this?

Thanks

nmaier95 commented 6 years ago

Hi there,

simply install it into your craft 3 project as any other plugin. You will then see an additional main-menu item making it possible to configure your shopify credentials (api-key, tokens, etc.). There will also be an additional field of type "Shopify Product". Add this to your section layout and you are ready to go. It´ll now automatically fetch products from your store into the field to select from. In the background only the product id gets saved into your database.

You may then fetch (inside of any of your twig templates) the product/s via their id/s or all at once. Have a look at the shopify api docs and how a response of a products request looks like. The same objects are returned by the methods of this plugin:

{% set shopify = craft.shopify.getProductById({ id: entry.productId, fields: 'variants' }) %}
{# Or all products: #}
{% set shopify = craft.shopify.getProducts({ fields: 'variants' }) %}

<form action="//{{craft.shopify.getSettings().hostname}}/cart/add" method="post">
    <select name="id">
        {% for variant in shopify.variants %}
            <option value="{{ variant.id }}">{{ variant.title }} - ${{ variant.price }}</option>
        {% endfor %}
    </select>
    <input type="hidden" name="return_to" value="back">
    <button type="submit">Add to Cart</button>
</form>

<form action="//{{craft.shopify.getSettings().hostname}}/cart" method="post" novalidate="" class="cart">
    <button type="submit">Checkout</button>
</form>

Further you may fetch the products prevously added to your shopify cart via any e.g. JavaScript script to dispaly them on your sites shopping card with the following HTTP GET request to "//craftintegration.myshopify.com/cart.json".

Hope I was able to help you with that.

Cheers.