CoCart JavaScript Library v1.0.0 Release Notes

Excited to share finally a JavaScript library to help with your headless store development. Much like the WooCommerce JavaScript Library, this one is designed so authentication is optional.

Where to get it?

You can install the JavaScript Library simply running this command in your terminal.

npm install --save @cocart/cocart-rest-api

If you wish to contribute to the project you can access the GitHub repository.

Example of Use

// import CoCartAPI from "@cocart/cocart-rest-api"; // Supports ESM
const CoCartAPI = require("@cocart/cocart-rest-api").default;
 
const CoCart = new CoCartAPI({
  url: "http://example.com"
});

You can decide to use CommonJS (CJS) or ECMAScript Modules (ESM).

Since there is only one API version at this time there is no need to define the version when setting up your API constant. All that is required is the URL of your site.

FYI

This library will NOT support the LEGACY API of CoCart.

If you are authenticating a customer then you need to set the consumerKey (a.k.a Username) and consumerSecret (a.k.a Password).

// import CoCartAPI from "@cocart/cocart-rest-api"; // Supports ESM
const CoCartAPI = require("@cocart/cocart-rest-api").default;
 
const CoCart = new CoCartAPI({
  url: "http://example.com",
  consumerKey: "sebtest123",
  consumerSecret: "happycoding24"
});

You can then proceed to use the library to make requests like so.

Get Cart

// Get Cart
CoCart.get("get-cart", {
  thumb: true, // Returns product thumbnail
})
.then((response) => {
  // Successful request
  console.log("Response Status:", response.status);
  console.log("Response Headers:", response.headers);
  console.log("Response Data:", response.data);
})
.catch((error) => {
  // Invalid request, for 4xx and 5xx statuses
  console.log("Response Status:", error.response.status);
  console.log("Response Headers:", error.response.headers);
  console.log("Response Data:", error.response.data);
})
.finally(() => {
  // Always executed.
});

Add item to cart

// Add item to cart
CoCart.post("add-item", {
  product_id: "32",
  quantity: 1
})
.then((response) => {
  // Successful request
  console.log("Response Status:", response.status);
  console.log("Response Headers:", response.headers);
  console.log("Response Data:", response.data);
})
.catch((error) => {
  // Invalid request, for 4xx and 5xx statuses
  console.log("Response Status:", error.response.status);
  console.log("Response Headers:", error.response.headers);
  console.log("Response Data:", error.response.data);
})
.finally(() => {
  // Always executed.
});

CoCart Lite v2.8.3 Release Notes

Excited to announce that CoCart Lite 2.8.3 is now publicly available! This is a minor release so everything is backwards compatible with the previous version.

As always, it is recommend to create a backup of your site before updating.

What’s new in CoCart v2.8.3?

This is the last minor update for CoCart v2 or at least for this year I think.

What’s new is that multi-site networks now properly engage with the site admin once the plugin is activated on the network.

A few tweaks have been made so we don’t add the version of the plugin per site. All admin notices now show via the network admin and if you are new to CoCart, you are redirected to the getting started page in the network admin upon first activation.

Before network sites would only see “Plugin activated” which makes the site admin feel left out.

A couple of fixes were also made.

Headers were already sent when filtering rest_pre_serve_request. This appeared to only cause issues when you have WP_DEBUG enabled when using CoCart locally.

And finally, a few errors were not returning the status error in the correct format.

That is it. I hope you are doing well and have a good x-mas. ?

Database changes

This release does not introduce any changes to the database.

Documentation

This release does not introduce any changes to the documenation.

CoCart Lite v2.8.2 Release Notes

Excited to announce that CoCart Lite 2.8.2 is now publicly available! This is a minor release so everything is backwards compatible with the previous version.

As always, it is recommend to create a backup of your site before updating.

What’s new in CoCart v2.8.2?

Two things have been done to improve the loading of a cart from session via the web. Load the chosen shipping method and cart fees.

In addition to this minor release, a request was made to be able to filter the parameter name cocart-load-cart, used for loading the cart from session via the web to provide more white labelling for their client.

You can find an example for this filter under “White Labelling”.

Database changes

This release does not introduce any changes to the database.

Documentation

All examples provided for setting a cart key have been corrected. Due to an over look on my part, I mistakenly documented the cart_key parameter as a standard data parameter and not a global parameter that requires to be queried.

Not many developers who had issues with this, saw the error and corrected this in their development but not reported the error to me.

Others had tried to report the error but did not make it clear to me as to what was wrong and moved on. Now after several releases and finally getting someone to report clearly what was wrong, I was able to correct it.

I apologise for the mistake and hope you try again with the new examples provided. I have also added a warning notice in the documentation to remind you that it is not to be passed as a data parameter.

CoCart Lite v2.8.1 Release Notes

Excited to announce that Pantheon, a high performance hosting platform is now supported in CoCart Lite 2.8.1 which is now publicly available! This is a tiny release so everything is backwards compatible with the previous version.

As always, it is recommend to create a backup of your site before updating.

What does it do?

Well because Pantheon is a platform built for speed, it’s cache system caused a problem for guest customers on the frontend making it look like the cart was empty no matter how many items were added to the cart.

Luckily, this was a quick easy fix after talking to their customer service.

All that was required was to change the cookie name using the available filter in CoCart to a new formatting that Pantheon reorganizes to prevent the session cookie from caching.

And after trying them out, I can say that I recommend using Pantheon for speedy performance to run your store no matter how large.

Database changes

This release does not introduce any changes to the database.

Documentation

This release does not introduce any changes to the documentation.

CoCart Get Cart Enhanced v2.0 Release Notes

This is the first release note post for CoCart Get Cart Enhanced. It introduces a couple of things. First checking the cart contents and applied coupons.

Validity of the items and stock is checked before returning the cart. The same for the coupons. This gives a more realistic cart in real time before the order is made and allows you to inform the customer should any item or coupon no longer be available or valid.

Second, is to give developers a preview of the new default cart response coming in CoCart v3.0 API v2.

What’s different and how do I preview?

Over time this add-on has been updated to improve the response based on the feedback by it’s users. One thing in particular that developers wanted was not to have the product prices and totals pre-formatted.

This suggestion allows more control, which means adding more information like the currency used for the store.

Default cart response with a single item added to the cart.

To preview the new cart response for CoCart v3.0 API v2, you need to use the filter cocart_preview_api_v2. You can copy the and paste the code below.

add_filter( 'cocart_preview_api_v2', function() { return true; });

Compatibility

This release also makes it compatible with v2.8 of CoCart Lite and small minor fix for those who are already using PHP 8. It’s also been tested with WooCommerce 4.8

Warning

Previewing the new cart response is still a working progress and is by no means complete. Use only for experimenting and to provide feedback.

Hope you enjoy and have a good X-mas. ?