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.
localhost
for your hostname, but ultimately you'll need to host your
app on the public Internet.
https://<app hostname>/bigcommerce/callback
https://<app hostname>/bigcommerce/load
https://<app hostname>/bigcommerce/uninstall
https://<app hostname>/bigcommerce/remove-user
(if enabling your app for multiple users)Save & Close
on the top right of the dialog.Clone the repo.
git clone https://github.com/bigcommerce/hello-world-app-php-silex
Use Composer to install the dependencies.
php composer.phar install
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>
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.
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.
heroku create <appname>
git push heroku master -u
APP_URL
in .env to https://<appname>.herokuapp.com
heroku-config
plugin: heroku plugins:install heroku-config
heroku config:push
In the BigCommerce Developer Portal, you'll need to update the app's callback URLs:
https://<appname>.herokuapp.com/auth/callback
https://<appname>.herokuapp.com/load
https://<appname>.herokuapp.com/uninstall
This example repo contains the ability to securely show recently purchased products. This is how it looks:
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>
<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%%
.<div id="recent_purchases_block"></div>
. You should see the Recently Purchased Products block appear.