/sunrise-spa

SUNRISE shop template as a single-page application

Primary LanguageJavaScriptApache License 2.0Apache-2.0

SUNRISE as a Single-Page Application

CircleCI Netlify Status

Demo

https://sunrise.netlify.com/

Deploy it on Netlify

Netlify allows you to clone the repository, configure the project with your own data and deploy it, all in one click.

Deploy to Netlify

In order to deploy SUNRISE SPA with a different commercetools project than the default, follow the instructions described in the section How to use your project data to obtain your credentials and use them to configure your site in Netlify.

Run it locally

Steps with Yarn with NPM
Install yarn install npm install
Run yarn serve npm run serve

How to use your own project data

SUNRISE SPA comes with some read-only data set by default that you can use. But if you need to use a different set of data or to manage the project via Merchant Center, then you'll need to connect SUNRISE SPA to your own commercetools project.

Once you have created your commercetools project and populated it with data, follow the next steps to connect to it.

1. Create an API client for a SPA

In the Merchant Center, select your project and go to the New API Client section (Settings > Developer Settings > API Clients > Create New API Client). Enter a descriptive name for your new API client and select the template Mobile & single-page application client. Once you have filled the form, submit it by clicking on Create API Client, you should now be able to see your project credentials. Don't close the window yet!

⚠️ Always use an API client suited for single-page applications (SPA), as your credentials will be publicly accessible through the browser.

2. Configure SUNRISE with your API client

Below the credentials, you should see a dropdown with different technologies: select Sunrise SPA and click on the download button. This will download a file named .env.local with your credentials, which you should place in the root folder of your SUNRISE SPA project.

⚠️ Make sure the downloaded file is called exactly .env.local, as browsers may remove the initial dot and apply further modifications to the filename.

This will set up the necessary environment variables required to run SUNRISE SPA.

Development tips

Add any queried fields to the mutation

When executing a mutation (e.g. to update the active cart), we receive as a response the updated resource, which Apollo then uses to update the cached data in Apollo store. It is thanks to this cache that all components are able to display the same information, even after mutations.

But when we under-fetch in the mutation and fail to update some cached fields we are displaying in a component, this component will not be updated at all with any new data. To avoid that, make sure to add any field you are querying in the mutation. The update mutations are found in the methods updateMyCart and updateMyCustomer.

Related issue: apollographql/apollo-client#3267

Run tests

The project has unit and end-to-end tests covering each functionality. Unit tests will run out of the box, but end-to-end tests require some further configuration, explained in the section below.

Test with Yarn with NPM
Unit yarn test:unit npm run test:unit
End-to-end yarn test:e2e npm run test:e2e

Configure end-to-end tests

In order to continue, it is necessary that you have full control over the commercetools project associated with SUNRISE.

Follow the same steps explained in the section How to use your own project data to create a second API client, but this time create it with the Admin client template instead. Then add your new client ID and secret as the following environment variables (e.g. in .env.local file):

CYPRESS_CT_CLIENT_ID=<your client ID>
CYPRESS_CT_CLIENT_SECRET=<your client secret>