All Projects → bigcommerce → hello-world-app-php-silex

bigcommerce / hello-world-app-php-silex

Licence: MIT license
Hello World sample app in PHP and Silex

Programming Languages

PHP
23972 projects - #3 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to hello-world-app-php-silex

hello-world-app-python-flask
Hello World sample app in Python and Flask
Stars: ✭ 31 (+34.78%)
Mutual labels:  oauth-application, bigcommerce
silex-ddd-skeleton
A simple skeleton of silex application using ddd arquitecture
Stars: ✭ 19 (-17.39%)
Mutual labels:  silex
Cache Service Provider
A Cache Service Provider for Silex, using the doctrine/cache package
Stars: ✭ 23 (+0%)
Mutual labels:  silex
Silex Webprofiler
Stars: ✭ 207 (+800%)
Mutual labels:  silex
Silex
Silex is a static website builder in the cloud.
Stars: ✭ 958 (+4065.22%)
Mutual labels:  silex
Pimple
A small PHP dependency injection container
Stars: ✭ 2,491 (+10730.43%)
Mutual labels:  silex
Silex Kitchen Edition
This project is a sample or a bootstrap silex application
Stars: ✭ 645 (+2704.35%)
Mutual labels:  silex
PHP-Frameworks-Bench
Popular PHP Frameworks Benchmark.
Stars: ✭ 28 (+21.74%)
Mutual labels:  silex
Php Getting Started
Getting Started with PHP on Heroku
Stars: ✭ 170 (+639.13%)
Mutual labels:  silex
Payumserver
Payment processing microservice. Written in Symfony4
Stars: ✭ 103 (+347.83%)
Mutual labels:  silex
Silex
something to help you spark
Stars: ✭ 61 (+165.22%)
Mutual labels:  silex
Crudlex
CRUDlex is an easy to use CRUD generator for Symfony 4 and Silex 2 which is great for auto generated admin pages
Stars: ✭ 102 (+343.48%)
Mutual labels:  silex
Slugify
Converts a string to a slug. Includes integrations for Symfony, Silex, Laravel, Zend Framework 2, Twig, Nette and Latte.
Stars: ✭ 2,697 (+11626.09%)
Mutual labels:  silex
Silexstarter
Starter app based on Silex framework with mvc and modular arch, scaffold generator, and admin panel
Stars: ✭ 11 (-52.17%)
Mutual labels:  silex
big-design
Design system that powers the BigCommerce ecosystem.
Stars: ✭ 35 (+52.17%)
Mutual labels:  bigcommerce
Silex Skeleton
A skeleton to get started with Silex
Stars: ✭ 805 (+3400%)
Mutual labels:  silex
Transport
Swiss public transport API
Stars: ✭ 215 (+834.78%)
Mutual labels:  silex
silex-starter-pack
A starter pack for beginning development with the Silex PHP framework. Includes a basic admin control panel, and user login system.
Stars: ✭ 12 (-47.83%)
Mutual labels:  silex
sm-groupcheck-web
GroupCheck web API.
Stars: ✭ 14 (-39.13%)
Mutual labels:  silex
add-to-org
A simple Oauth App to automatically add users to an organization
Stars: ✭ 24 (+4.35%)
Mutual labels:  oauth-application

BigCommerce Sample App: PHP

This is a small Silex application that implements the OAuth callback flow for BigCommerce Single Click Apps and uses the BigCommerce API to pull a list of products on a BigCommerce store. For information on how to develop apps for BigCommerce stores, see our Developer Portal.

We hope this sample gives you a good starting point for building your next killer app! What follows are steps specific to running and installing this sample application.

Prerequisites

  • A web server such as MAMP or Apache. A localhost address will work fine for the hello world app.
  • PHP
  • Composer

Registering the app with BigCommerce

  1. Create a trial store on BigCommerce
  2. Go to the Developer Portal and log in by going to "My Apps"
  3. Click the button "Create an app", enter a name for the new app, and then click "Create"
  4. You don't have to fill out all the details for your app right away, but you do need to provide some core details in section 4 (Technical). Note that if you are just getting started, you can use localhost for your hostname, but ultimately you'll need to host your app on the public Internet.
  • Auth Callback URL: https://<app hostname>/bigcommerce/callback
  • Load Callback URL: https://<app hostname>/bigcommerce/load
  • Uninstall Callback URL: https://<app hostname>/bigcommerce/uninstall
  • Remove User Callback URL: https://<app hostname>/bigcommerce/remove-user (if enabling your app for multiple users)
  1. Enable the Products - Read Only scope under OAuth scopes, which is what this sample app needs. Note: If you are managing customer information through the API (such as with the Recently Purchased Products Block example below) then you will need to also enable the Customers scope to at least read data. below) then you will need to also enable the Customers scope to at least read.
  2. Click Save & Close on the top right of the dialog.
  3. You'll now see your app in a list in the My Apps section of Developer Portal. Hover over it and click View Client ID. You'll need these values in the next step.

Getting Started

  1. Fork the repo (optional).

  2. Clone the repo.

     git clone https://github.com/bigcommerce/hello-world-app-php-silex
    
  3. Use Composer to install the dependencies.

     php composer.phar install
    
  4. Copy .env-example to .env and set the following environment variables in it.

     BC_AUTH_SERVICE=https://login.bigcommerce.com
     BC_CLIENT_ID=<contents of Client ID field>
     BC_CLIENT_SECRET=<contents of Client Secret field>
     BC_CALLBACK_URL=<URL TO YOUR AUTH CALLBACK ENDPOINT>
    
  5. Restart the software or the entire host as needed to set the environment variables.

Hosting the app

In order to install this app in a BigCommerce store, it must be hosted on the public Internet. You can get started in development and use localhost in your URLs, but ultimately you will need to host it somewhere to use the app anywhere other than your development system. One easy option is to put it on Heroku.

Heroku

Note: It is assumed that you already have a Heroku account, have the Heroku toolbelt installed, and have authenticated with the toolbelt. See Heroku for details.

  • Create a new Heroku app: heroku create <appname>
  • Push the project to Heroku: git push heroku master -u
  • Set APP_URL in .env to https://<appname>.herokuapp.com
  • Add the heroku-config plugin: heroku plugins:install heroku-config
  • Push the local environment variables to heroku: heroku config:push

In the BigCommerce Developer Portal, you'll need to update the app's callback URLs:

  • Auth Callback URL: https://<appname>.herokuapp.com/auth/callback
  • Load Callback URL: https://<appname>.herokuapp.com/load
  • Uninstall Callback URL: https://<appname>.herokuapp.com/uninstall

Installing the app in your trial store

  • Login to your trial store
  • Go to the Marketplace and click My Drafts. Find the app you just created and click it.
  • A details dialog will open. Click Install and the draft app will be installed in your store.

Showing the Recently Purchased Products Block with JWT

This example repo contains the ability to securely show recently purchased products. This is how it looks:

Adding the block to your theme

  1. Edit your Footer.html file in blueprint or Footer Scripts if you're using Stencil and add:
    <script>
    var appClientId = "**BC_CLIENT_ID**"; // TODO: Fill this in with your app's client ID.
    var storeHash = "**TEST_STORE_HASH**"; // TODO: Fill this in wit the test store's store hash (found in base url before the `store-` part)
    var appUrl = "**APP_URL**"; // TODO: Replace this with the URL to your app.
    
    // Get the JWT token from the BC server signed first.
    $.get('/customer/current.jwt?app_client_id='+appClientId, function(jwtToken) {
      // Now that we have the JWT token, use it to get the recent purchases block.
      $.get(appUrl+'/storefront/'+storeHash+'/customers/'+jwtToken+'/recently_purchased.html', function(htmlContent) {
        $('#recent_purchases_block').html(htmlContent, true);
      });
    });
    </script>
  2. Put <div id="recent_purchases_block"></div> wherever you want the block to appear. If you're using blueprint it is recommended that you put it in default.html right before %%Panel.SideTopSellers%%.
  3. Log in as a customer in your store's frontend (or create a customer account if one doesn't exist yet), place an order then go to the section where you added the <div id="recent_purchases_block"></div>. You should see the Recently Purchased Products block appear.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].