Giter VIP home page Giter VIP logo

craft-shopify-product-fetcher's Introduction

Shopify plugin for Craft CMS 3.x

Screenshot

Requirements

This plugin requires Craft CMS 3.0.0-beta.23 or later.

Installation

Composer

Install the plugin via composer into your craft 3 project:

composer require nmaier95/shopify-product-fetcher

In the Control Panel of Craft, go to Settings → Plugins and click the “Install” button for shopify.

Craft Plugin Store

We are listed inside the official Craft Plugin Store. You may directly install it here as well.

Manually

Please see the official docs of Craft:

https://docs.craftcms.com/v3/extend/plugin-guide.html#loading-your-plugin-into-a-craft-project

Configuring shopify

Once the plugin is installed successfully, a new icon with this' plugins logo on the settings-page appeared. Clicking it takes you to the settings of the plugin.

Screenshot

!! Please stick to the format of the "Hostname" field like in the example above !!

Using shopify

There will be an additional field of type "Shopify Product" in the list of all available field-types when creating a new field for a group. Then add this field/group to your section layout and you are ready to go. When editing the section it´ll now automatically fetch products from your store into the field to select them from. In the background only the product id gets saved into your database. Via the saved product-id you are then able to fetch specific products inside of your templates.

Samples

Usage of products selected inside of an entry

{% for productId in entry.products %}

    {% set shopifyProduct = craft.shopify.getProductById({ id: productId }) %}

    {{ dump(shopifyProduct) }}

{% endfor %}

Get all products of my shop

{% set products = craft.shopify.getProducts() %}

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

Both craft.shopify.getProductById() and craft.shopify.getProducts() support an optional 'options' parameter which takes shopify-api options for requests. For further documentation please use official shopify api docs. For example craft.shopify.getProducts({fields: 'variants'})

Brought to you by niklas maier
You may also find me inside of the official Craft Slack.

craft-shopify-product-fetcher's People

Contributors

nmaier95 avatar toyflish avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.