In light of the recent COVID-19 pandemic - OPTASY would like to offer DRUPAL website support for any Health Care, Government, Education and Non-Profit Organization(s) with critical crisis communication websites or organizations directly providing relief. Stay Safe and Stay Well.

How to Decouple Drupal Commerce to Deliver Richer Shopping Cart Experiences: Useful Modules

How to Decouple Drupal Commerce to Deliver Richer Shopping Cart Experiences: Useful Modules

by RADU SIMILEANU on Feb 01 2019

Just imagine it: Drupal 8's robust features as a CMS, the flexible e-commerce functionality of the Drupal Commerce ecosystem and a JavaScript framework for the front-end! All in the same native mobile app! You can easily achieve this “combo” — a reliable content repository & a JS-based front-end providing a fantastic shopping cart experience — if you just... decouple Drupal Commerce.

For why should you trade Drupal's battle-tested content authoring and administration tools for a more interactive user experience? 

And why should you give up on your goal to deliver richer cart experiences just because Drupal 8 can't rival the JavaScript in terms of advanced native mobile app functionality?

 

  • push notifications
  • complex shopping options
  • enabling users to manage their own delivery times and places
  • ... to configure various aspects of their orders and so on

     

Just leverage a decoupled Drupal Commerce strategy in your shopping app project and you can have both:

 

  • Drupal as your secure content service 
  • the front-end framework of your choice “in charge” with the user experience 

     

In this respect, these are the most useful Drupal tools at hand for implementing an API-based headless architecture:

 

1. Headless Commerce Comes Down to...

… separating your commerce stack (back-end content handling area, data store etc.) from the user interface.

Or the “head”, if you wish.

The presentation layer would “retrieve” content from the back-end content storage area and is the one fully “responsible” with delivering fantastic user experience.

This way, you're free to choose your own front-end tools.

Now, why would you consider choosing a decoupled architecture for your e-commerce solution? The benefits are quite obvious and not at all negligible:

 

  • higher flexibility and scalability (that JS frameworks are “famous” for)
  • freedom to customize your app to your liking (for every platform or/and device)
  • richer, more interactive shopping experiences 

     

2. Decoupled Drupal Commerce... Out of the Box? The Commerce Demo 

Narrowing our focus down to... Drupal, to Drupal Commerce, more specifically, the question's still there:

“How do I decouple Drupal Commerce?”

Considering that:

 

  • there are specific challenges that such a decoupled front-end architecture poses
  • Drupal solutions like Forms API and Views won't fit your specific (probably quite complex) design implementation requirements

     

Luckily, the Commerce Guys team has already faced and solved these challenges.

First of all, they've put together the Commerce Demo project, a store providing default content to be “injected” into Drupal.

Secondly, their attempt at integrating a design meant to support advanced functionality, for richer shopping cart experiences, resulted in 2 new modules:

 

  • Commerce Cart API
  • Commerce Cart Flyout

     

More about them, here below...

 

3. Useful Modules to Decouple Drupal Commerce 

Here's a collection of the most... relevant modules that you could use in your headless Drupal Commerce project:

 

3.1. The Commerce Cart API Module

It's no less than a handy Drupal tool that enables you to custom build your shopping cart widget. 

 

3.2. The Cart Flayout Module

The go-to module when you need to ajaxify the “Add to cart” form in your shopping app.

Basically, what it does is:

Provide a sidebar that “flies out” once the user clicks the “Add to cart” button or the cart block.

If I were to dive into details a bit, I'd add that the flyout enables users to:

 

  • view the products in their shopping carts
  • remove all the items there
  • update the quantity of a specific item

     

Should I add also that Cart Layout comes with no less than 9 different Twig templates, for various parts of the module? By leveraging Drupal's library management feature you can easily override these JS segments of the module.

And not only that you get to customize it to suit your needs entirely, but:

 

  • it comes with a well structured JS logic
  • it's built on top of Backbone

     

… which translates into an efficient models-views separation.

 

3.3. Commerce 2

Use Drupal Commerce 2 as the core structure of your e-commerce project.

Being an ecosystem of Drupal 8 modules and “spoiling” you with unmatched extensibility via its APIs, Drupal Commerce empowers you to implement all kinds of headless commerce scenarios.

It enables you to use Drupal as your content/data (user and order-related info) repository and to easily serve this content to your mobile app. To your end-users.

 

3.4. The Commerce Recurring Framework Module

Some of its handy charging & billing features include:

 

  • configurable billing cycles
  • configurable retries in case of payment declines
  • both prepaid and postpaid billing systems

     

3.5 The JSON API & JSON API Extras Modules   

Need to decouple Drupal Commerce, to enable a full REST API in JSON format? 

It's as easy as... enabling a module (or 2 at most): the JSON API module.

What it does is:

 

Expose the API so you can vizualize the data in JSON format.

 

And Drupal's built and perfectly adapted to support JSON API, which turns it into the go-to option when you need a back-end content repository for your headless shopping app.

In addition to this module, feel free to enable JSON API Extras, as well. It comes particularly handy if you need to customize the generated API. 

It allows you to:

 

  • override the name of your resources
  • change their path...

     

You'll then have a specific place in your app's user interface where you can visualize your content paths.

Once you have your data in JSON format, safely stored in your back-end content creation & moderation Drupal area, you're free to... serve it to your mobile shopping app!

 

The END!

And these are some of the already tested tools and techniques to decouple Drupal Commerce so that you can deliver richer, more interactive cart experiences.

Have you tried other modules/methods? Writing custom JavaScript code... maybe?

Development

We do Web development

Go to our Web development page!

Visit page!

Recommended Stories

10 Best Tools for Conducting a Drupal 8 Site Audit (to evaluate its performance, security, and stability)
You want to audit your Drupal website's infrastructure, SEO, best practices, security, stress, overall performance... And you ask yourself: Are there tools that help you run a Drupal 8 site audit? ... and generate the reports you need? There are quite a few, actually. To narrow down your too many options, we've made a list of 10 tools and Drupal modules that you can use to test your website's performance, security, and stability. 1. 3 Best Tools to Run a Website Security Audit 1.1. Coder     What does it do? it checks your code to see whether it meets the industry standards it checks your text, so you'll know whether i's properly sanitized or not quite In short, a Drupal 8 audit module you'll want to have in your toolbox when conducting a website security audit. 1.2. Qualys SSL Server Test Another tool that you'll want to use during your Drupal 8 security audit process. Why? Because it performs a thorough analysis of a public SSL certificate and generates a grade for you. 1.3. Security Kit How does it work?  It provides you with a set of security-hardening options, that strengthen the shield around your site against CSRF, XSS, and clickjacking attacks. 2.3 Best Tools to Run a Drupal 8 Site Audit Focused on Its Performance 2.1. PageSpeed Insight, YSlow, GTMetrix  Take these 3 website performance audit tools as your the "swiss army knife" in your toolbox.  They run multiple tests on your website and generate a whole set of practical recommendations on how you can boost its front-end performance. Here are just some examples of recommendations: cut down on the number of elements the browser's forced to parse by simplifying the DOM cut down on the number of requests  by aggregating your JS files or using image sprites 2.2. New Relic An all-into-one Drupal site audit module that helps you monitor different sections on your website: from infrastructure to server, to browser and application. Now, here's precisely why you'll want to keep it close at hand while assessing your website's performance: it allows you to set up multiple customized dashboards that show graphs and charts of your website's performance data it enables you to keep an eye on your website's traffic and performance in real-time it allows you to isolate bottlenecks and set up alerts for key events 2.3. Performance Monitor   Let's say you've just moved your Drupal website to another hosting and you now feel that it has slowed down. And that the new server needs to be optimized for Drupal. This is precisely where this module comes in handy: It gives you a clear picture of how your website's performing now, while comparing different servers/hostings. Here are some of the features you'll love: it checks the Mysql status and variables (and provides recommendations) it tests the overall system performance (it runs database, CPU, and file operations performance tests) it evaluates the "Performance score"  3. 4 Best Tools to Evaluate Your Website's Stability 3. 1. Behat, PHPUnit, Nightwatch Or you can put together your own "combo" of unit and functional testing tools. Automated testing will improve your website's stability... in the long-term (and nothing can beat the peace of mind that you'll get). 3.2. Code Sniffer Whenever you need to assess your code's quality, just reach out for this Drupal 8 audit tool. It will... "sniff on" your code and signal you if it doesn't meet the coding standards.  Also, while testing your code's stability, you'll want to have a look at: the quality of your links the cycles of peer review for codes the factors that influence the SEO the access and breadth of documentation the modules you have on your website: are there any outdated ones? 3.3. Tugboat You save time and money using Tugboat (or an alternative continuous integration tool). Here's how: it runs the automated and linting tests that you will have set up and generates a report to your developer before even merging or reviewing the code it builds a completely working website that incorporates that new feature you've added or has that specific bug fixed before it gets merged A true time-saver that you'll definitely want to have in your toolkit when testing newly added code for stability.  3.4. Linting Tools How do they help you increase the stability of your Drupal website? they get all the developers in your team on the same page when it comes to the code format to be used they (i.e. Drupal Code Sniffer) enforce the Drupal coding standards once integrated to your developers' text editors Tip! Make sure you incorporate your linting tools into your automated testing routine, the one that gets performed on each pull request. The END! These are your best options when it comes to the Drupal 8 site audit tools to include in your toolkit. But what if you dread the idea of digging deep into your code, checking every single one of your Drupal modules, evaluating the CPU performance... What if you could still get a clear picture of how you're website's performing without the dread of going through all these tedious, time-consuming tasks? Just shift the burden to us! Drop us a line and let's get your Drupal website checked for all the issues and bottlenecks affecting its performance, security level, and stability! Image by Free-Photos from Pixabay   ... Read more
Adriana Cacoveanu / Aug 06'2020
7 Ways that You Can Reduce Image Size on a Large-Scale Drupal Site, With a Lot of Images
Images can make or... break the user experience. Especially if we're talking about large amounts of images. So, what are your best options to reduce image size on a large-scale Drupal 8 site? And, most importantly: How do you strike a balance between the smallest file size and the best possible image quality? Well, just keep on reading... Here are 7 ways that you can manage image compression on your image-heavy Drupal site without affecting their quality: 1. Use a PNG Optimizer to Reduce Image File Size Let's say that you have a lot of PNG images on your Drupal website. How do you reduce the image file size? Simple: you use TinyPNG to... squeeze them. Expect to reduce them somewhere around 60% (while keeping the lossless image quality). 2. Use a JPEG Compressor to... Compress Your Images Server-Side  "How to make images load faster on my website?" Just use a compressor to reduce image size for your JPG and JPEG files: TinyJPG CompressJPEG Compress Now JPEGOptim It will take... a while, especially since we're talking about an image-heavy Drupal site. Different JPG files mean different settings for you to... play with till you've balanced out size and quality. 3. How to Improve Image Load Times: Use Drupal 8 Image Styles It's a tool that you get... out of the box. And what you gain is more control over the size of the images on your website: Set several image styles, of different sizes, that will go on various areas of a page. Good to know! Configure your image styles just once: from then on, they'll resize all your new images by default. Here's how you do it: Go to "Manage display", in the content type setup section Click the gear wheel icon next to the image field to open the settings tab and choose an image style There, you can either choose one of the previously configured image styles or... create a new one, by selecting the "Configure Image Style" option from the dropdown menu Source: Drupal.org          Good to know! Once you've set your image style, the module updates all the created images... automatically. 4. Use Drupal 8 Image Toolkit to Adjust Their Quality (And Their Size) It's the best way to resize images in Drupal 8. And the easiest way, as well: Go to Admin > Configuration > Media > Image Toolkit Choose the setting that allows you to compress your images (the JPEG quality field) Play with it till your strike the perfect size-quality balance Save the new settings Note! The new setting will apply to all your images; there's no way for you to adjust the quality for each image, one by one. Tip! Stick to somewhere between 60% and 80% when setting the image quality. 5. Use the Responsive Images Module to Resize Your Images  "Which module is used for image optimization?" Which is the best Drupal 8 module to reduce image size on pages that contain lots of images... Responsive Images is (but) one of them. Here's how it works: Its image formatter maps the breakpoint of the original image and renders a responsive image instead. All that by using an HTML5 picture tag (that has sizes and srcset attributes). It basically enables browsers to select the image to display according to the image style selections. And here's how you set up responsive images on your Drupal 8 website: Enable the module (for, even if it's a core module, it's not enabled by default) in Admin > Configuration Select "Responsive Image" Hit "Install" What about breakpoints? How do you set them up? Go to your editor (if it's a custom theme that you're using) Create a file named "yourthemename.breakpoints.yml" in your theme directory ("/themes/custom/yourthemename") Now, its time to configure the image styles for your responsive images: Different breakpoints call for... different image sizes.  Go ahead and pair each breakpoint that you set up at your_theme_name.breakpoints.yml with an image style and create your responsive image styles. 6. Use the ImageMagick Module to Reduce Image Size   "How do I manage compression on my image-heavy Drupal site?" You use ImageMagick. It's another one of your best options for Drupal 8 image resize. Here's why: Drupal might provide the GD2 image manipulation toolkit out of the box and enable you to set multiple alternatives, of different sizes, for the same image. Yet, it lacks some key features, such as... TIFF format support or GIF support with an image style. And this is where the ImageMagick module comes in handy. To install it, just run this command: Composer require 'drupal/imagemagick' And here's how you use it to reduce image size: enable it via ‘yoursite/ path set the quality for your image to 100% in the ImageMagick image toolkit The results? you've just enabled the GIT format support with image style you've reduced your image size by 20-40% Mission accomplished... 7. If It's Still Not Enough, Lazy Load Your Images  "How to load images faster?" Use the Lazy Loader, the ultimate Drupal 8 image optimization solution. Have you tried them all — all the dedicated modules and Drupal core features available — and you're still not satisfied with how fast your image-heavy pages load? Then go even further and incorporate a lazy loading functionality into your website. The END! But maybe you have better things to do — a business strategy to improve, urgent projects to work on — than finding and implementing the best solution to reduce image size on your Drupal website. Yet, you still want to make your pages load faster... So, just pass on the "burden" to us! We'll identify the best solution for speeding things up on your image-heavy web pages and... implement it for you sitewide. Image by Alexandra_Koch from Pixabay   ... Read more
Silviu Serdaru / Jul 23'2020
Drupal Performance Optimization: 17 Drupal Caching Best Practices To Speed Up Your Page Load Time- Part 2
"How can I make my Drupal 8 website faster?" Are you still struggling with this? Still striving to figure out which are the best (and most straightforward) Drupal performance optimization techniques for your website? Well, here I am today with a handful of 9 more ways that you can speed up your Drupal site. In addition to the 8 ones that I covered in the first part of this post. And yes: it's another round of Drupal caching best practices that'll help you boost your page load time. So, let's dive right into it: Tip #9: Use the Dynamic Page Cache Module  ... to cache for both authenticated and anonymous users. Unlike the Internal Page Cache module, that I mentioned in Part 1, which only caches pages for anonymous users. Tip #10: Use Distributed Cache, A Highly Effective Drupal Performance Optimization Technique But how does it work, more precisely? Once you've installed a distributed cache, it'll store your database's cache tables (Drupal's "cache_" tables) either in: file or memory Tip #11: Enable Drupal Cache for Anonymous Users Another one of those quick, yet powerful Drupal performance tuning steps that you can take. Tip #12: Use Squid to Cache Images and Static Content on Your Website "How to optimize Drupal for better performance?" You could go for Squid, an open-source caching proxy server. Now, since Drupal's already famed for its particularly dynamic content, the only cases where Squid does make a great performance booster are those where you need to cache static content. Tip #13: Add a Front-End Cache (i.e.Varnish Cache) Here's another handy Drupal performance optimization method for you: Use Varnish Cache to reduce the load on your server. How does it do it? It stores the HTML response, so that next time that the same page is requested, it serves it from memory. The result? Bypassed PHP and web server and... improved page load time. Tip #14: Use the Advanced CSS/JS Aggregation Module to Improve the Front-End Performance of Your Website  Combining your assets together is one of the most straightforward and effective ways to address those Drupal performance issues on your website. From: file grouping to caching to compressing ... the AdvAgg module handles all the steps that you need to take to aggregate your CSS and JS files. Tip #15: Install Memcache to Reduce Your Database Load You know how you're often struggling with keeping your database load to a minimum by caching database objects in RAM? In this respect, Memcache makes a great Drupal 8 performance optimization technique. It helps you reduce that load on the database and boost your page loading time. How? By taking standard caches out of the database. And by caching the results of resource-intensive database operations... Tip #16: Use the Entity Cache Module to Cache... Entities   Another caching best practice to boost Drupal 8 with is installing the Entity Cache module.  And its name says it all: it helps you cache entities. Tip #17: Cache Views  Here's the situation: Page requests made by registered users on your website lead to loads of queries to your database. Which impact the page load time. Now, to query the database, views are being used. And this is where this views caching module comes in handy to... boost things in there.   The END! These are our 17 recommendations for you on the best Drupal performance optimization methods for boosting your page load time. Not thrilled about the idea of having to go through the... Memcache installation process or to configure Varnish for Drupal? Or to put your current projects on hold so that your team can set up a... distributed cache? Maybe you don't have a professional Drupal maintenance team that could handle all these caching settings? We're here to help! Just drop us a line and let's figure out which of these 17 techniques are best suited for your website and the specific performance issues that it's struggling with. Let's speed things up in there! Image by Izwar Muis from Pixabay   ... Read more
Silviu Serdaru / Jun 23'2020