Giter Club home page Giter Club logo

cakephp-shopify-plugin's Introduction

CakePHP Shopify Plugin

This is a plugin that allows you to authenticate and make API calls with Shopify. It's perfect for building custom and public Shopify Apps. You can quickly and easily get a Shopify up and running and use CakePHP at the same time.

Requirements

-CakePHP (built and tested on 2.0.5 Stable)

Installation

After you have downloaded and installed CakePHP:

  • create a folder called "Shopify" in your app/Plugin folder.
  • extract (or clone) the contents of this repository to that "Shopify" folder.

you should now have these folder:

  • app/Plugin/Shopify/Config
  • app/Plugin/Shopify/Controller
  • app/Plugin/Shopify/View

now you need edit the config file with your Shopify App API info

  • open app/Plugin/Shopify/Config/shopify.php
  • fill in the api_key and shared_secret

load the plugin and configuration into your CakePHP App

  • open app/Config/bootstrap.php and add this at the bottom:
CakePlugin::load('Shopify');
Configure::load('Shopify.shopify');

Usage

Sample 1 - In your App Controller

Simply add this line to your AppController and it can be used in all Controllers

	public $components = array('Shopify.ShopifyAuth', 'Shopify.ShopifyAPI');

Sample 2 - In a specific Controller

<?php
App::uses('AppController', 'Controller');
class SimpleController extends AppController {

	public $name = 'Simple';
	public $components = array('RequestHandler', 'Shopify.ShopifyAuth', 'Shopify.ShopifyAPI');
	public function beforeRender() {
    		parent::beforeRender();
		// before rendering the views, check how many API calls we made
		$this->set('shopifyCallsMade', $this->ShopifyAPI->callsMade());
		$this->set('shopifyCallLimit', $this->ShopifyAPI->callLimit());
    	}

	public function index() {
		try {
			// I only want the id and title of the collections
			$fields = "fields=id,title";
			// get list of collections
			$custom_collections = $this->ShopifyAPI->call('GET', "/admin/custom_collections.json", $fields);
			$this->set('collections', $custom_collections);

		} catch (Exception $e) {
			
			// nothing fancy here
			echo "<pre>|";
			print_r($e);
			echo "</pre>";
		}
		
	}
}

Now, this plugin will automatically handle the shopify Authentication and redirect to an install form. Did you get that? You don't have to worry about authentication. It's all handled. All you have to do is start making API calls.

Coming Soon

Ability to skip Shopify Authentication on certain controllers and views. Currently it checks all including the front page.

	public $components = array(
				'Shopify.ShopifyAuth' => array('allow', array('controller/view1', 'controller2/view2')), 
				'Shopify.ShopifyAPI');

Special Thanks

Special thanks to Sandeep for his initial release of the lightweight Shopify API client (https://github.com/sandeepshetty/shopify.php) that is used and slightly modified in this repository.

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.