Giter VIP home page Giter VIP logo

craft-shopify-resource's Introduction

craft-shopify-resource plugin for Craft CMS 3.x

shopify-resource reference field via storefront api

store shopify storefront id in craft field with dropdown using shopify storefront api

use shopify products and collecitons in craft fields, highly inspired by nmaier95/craft-shopify-product-fetcher but using the shopify storefront api, therefore ids compatible with shopify buy sdk

  • send custom graphql queries to get resized images from shopify
  • async clientside queries in cp do not slow down cp rendering with mutliple product fields

Requirements

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

Installation

To install the plugin, follow these instructions.

  1. Open your terminal and go to your Craft project:

     cd /path/to/project
    
  2. Then tell Composer to load the plugin:

     composer require toyflish/craft-shopify-resource
    
  3. In the Control Panel, go to Settings → Plugins and click the “Install” button for craft-shopify-resource.

craft-shopify-resource Overview

adds a shopify resource select field to your control panel

Configuring craft-shopify-resource

expects storefront-api credentials and locale settings to enable queries to the new shopify mutlilanguage api

return [
    'accessToken' => getenv('SHOPIFY_ACCESS_TOKEN'),
    'hostname' => getenv('SHOPIFY_HOSTNAME'),
    'hostnameOverwrite' => getenv('SHOPIFY_HOSTNAME_PUBLIC'),
    'locale' => 'en'
];

Using craft-shopify-resource

you can use the plugin provided query (simular to shopify buy sdks product query) or submit a custom query setup in twig

<p>
    <h2>Entry resource field with handle myResource</h2>
    shopify storefront id: {{entry.myResource}}

    <p>use product query provided by plugin</p>
    {%  set myResourceProduct  = craft.storefront.productById(entry.myResource) %}

    {% if myResourceProduct %}
        title : {{ myResourceProduct.title }}
    {% else %}
        myResource product not found
    {% endif %}
</p>

<p>
    <h2>Custom Query: list of products</h2>
    {% set query %}
        query searchProducts($term: String) {
            products(first: 250, query: $term) {
                edges {
                    node {
                        id
                        title
                    }
                }
            }
        }
    {% endset %}
    {% set productsResult = craft.storefront.query(query)['products']['edges'] %}
    {% if productsResult|length %}
        <h3>Product list</h3>
        {% for product in  productsResult|map(product => product.node) %}
            <p>{{ product.title }}</p>
        {% endfor %}
    {% endif %}
</p>

Brought to you by devkai

craft-shopify-resource's People

Watchers

 avatar  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.