Kristen Jordan Koenig Living the Midwestern developer/writer dream

A guide to SAP Spartacus

3 min read 1036

SAP Spartacus Logo

What is SAP Spartacus?

SAP Spartacus, referred to simply as Spartacus, is an open-source platform for online storefront applications. More specifically, Spartacus is an open-source JavaScript application for B2C and B2B e-commerce platforms that sit on the SAP Commerce Cloud. The Spartacus libraries provide storefront applications with a core framework that includes:

  • Homepage
  • Product details
  • Product categories
  • Search functionality
  • Adding items to cart
  • Cart page
  • Checkout
  • Order history

Spartacus’s flexibility allows customers to shop through both traditional computer and mobile environments. Spartacus is free, open-source, and updated every few weeks through the GitHub repository.

In this article, we’ll cover some of the features of Spartacus, how to use it, and some tips and tricks you should consider.

Prerequisites

Leveraging Spartacus requires a working knowledge of JavaScript and Angular, as well as the SAP Commerce Cloud and Commerce APIs.

Notable features of Spartacus

Decoupled architecture

Spartacus is a purely frontend technology and is separate from backend commerce platforms, thus decoupling the website’s architecture. SAP Commerce Cloud remains constant and operates through REST APIs.

By taking advantage of decoupled architecture, frontend developers using Spartacus don’t need to sync their release schedule with backend platform releases. Instead, each team can work independently on its own development cycles and allow Spartacus to handle communications via REST services.

JS Storefront
The Spartacus storefront sits independently on the commerce platform. | Source: CX Works

Extendable and upgradable

Because Spartacus libraries are imported into existing websites, Spartacus is inherently upgradable and extendable. Minor releases and patches should not affect compatibility. Releases of Spartacus follow standard versioning conventions.

Users can add their own customized features. However, Spartacus is designed to be extendable, so users can continue to upgrade existing sites to leverage the latest sets of components.

Open source

Spartacus is an open-source platform and was originally written by SAP developers. With an open-source platform, Spartacus provides broader access to both the SAP Commerce Cloud and unofficial SAP partners. Because of the open-source architecture, developers can quickly access code to explore new components, test out new functionalities, and modify storefronts.

Spartacus is developed with the agile model, which provides an avenue for quick changes and rapid releases approximately every two weeks. You can choose, however, if you want your setup to automatically incorporate new releases or if you would prefer to maintain a specific version of Spartacus.

We made a custom demo for .
No really. Click here to check it out.

Progressive and responsive

Spartacus code developers strive to fully comply with the Progressive Web Application (PWA) checklist of capable, reliable, and installable when it comes to web applications. One important factor of this goal is incorporating responsive design and supporting a multitude of breakpoints — users can configure breakpoints as well. Supported breakpoints include:

  • Mobile
  • Tablet
  • Desktop
  • Wide-desktop

Spartacus can also allow your e-commerce site to operate more like a traditional iOS/Android mobile app. It includes mobile-ready features along with solid performance and reliability.

Content management system focused

Spartacus is flexible enough to work with various content management systems (CMS). In cases where the content manager works with the SAP Commerce CMS, storefront content is edited through SAP Commerce Cloud CMS tools. However, Spartacus can access content through third-party CMS applications too.

How to use Spartacus

Leveraging Spartacus

A typical implementation involves setting up a JavaScript or Angular web application and then importing Spartacus libraries. Even without modifications, a Spartacus storefront works out of the box. However, Spartacus is flexible so developers can customize, upgrade, and extend functionality and branding as needed.

Requirements

  • Frontend: Spartacus was written on an Angular platform and also uses node.js and yarn. Each version of Spartacus (1.x, 2.x, or 3.x) requires different versions of Angular, node.js, and yarn.
  • Backend: To use Spartacus, the SAP Commerce Cloud used must be on at least version 1905, but version 2005 is preferred and recommended.

Spartacus walk-through guide

Creating a store

In this walk-through, we’ll create a new Angular application with the name mynewstore.

First, open a command prompt or terminal window. Then, create a new Angular application using the Angular CLI with the following command:

ng new mynewstore --style=scss

You’ll be asked about Angular routing — enter n for “no.” The mynewstore folder app and associated folder are created.

Now, access the newly created mynewstore folder with the following command:

cd mynewstore

Spartacus project setup

Using Angular Schematics is the easiest way to set up your application quickly.

First, let’s set up the project using schematics. This schematics command installs the latest release of Spartacus:

ng add @spartacus/schematics

If you want to install the most recent “Next” or Release Candidate, the above command can include @next or @rc at the end.

To verify the installed Spartacus library versions, open package.json, and search for @spartacus.

Now, install dependencies needed by your Spartacus app with the following command:

yarn install

Afterward, we’ll check app.module.ts for base URL and other settings. Open src\app\app.module.ts and see if you want to make any setup changes.
A few features to check:

  • baseUrl: sets your SAP Commerce Cloud server
  • prefix: sets OCC prefix in calls; change /rest/v2/ to /occ/v2/ (if on release 2005)
  • features.level: sets compatibility level
  • context: sets site constants like language, currency, and base site

To start your application, enter the command:

yarn start

At this point, your application is compiled and started. To view the mynewstore storefront — if everything is installed locally — browse to http://localhost:4200.

Spartacus tips and tricks

Don’t copy Spartacus source code

Although it may be tempting to copy Spartacus source code and tweak it for your site, this breaks upgradability. Instead, reference Spartacus libraries and change site behavior in other ways.

Check on Spartacus features

Before developing your own storefront feature, check to see if it’s something already included in Spartacus or if it’s on the design horizon.

Choose your features

Developers can pick which Spartacus features to leverage according to e-commerce needs. For example, you may want to allow Express Checkout but not take advantage of Guest Checkout.

Conclusion

Spartacus provides lightweight, frontend capabilities to online storefronts. We covered some of the basic functionalities and pros of leveraging Spartacus, learned how to create a new Angular application and add Spartacus, and covered some tips and tricks.

LogRocket: See the technical and UX reasons for why users don’t complete a step in your ecommerce flow.

LogRocket is like a DVR for web apps and websites, recording literally everything that happens on your ecommerce app. Instead of guessing why users don’t convert, LogRocket proactively surfaces the root cause of issues that are preventing conversion in your funnel, such as JavaScript errors or dead clicks. LogRocket also monitors your app’s performance, reporting metrics like client CPU load, client memory usage, and more.

Start proactively monitoring your ecommerce apps — .

Kristen Jordan Koenig Living the Midwestern developer/writer dream

Leave a Reply