CoCart Needs You

CoCart now needs your help more than ever for the next major update v3. Your feedback has been great but for the next API I want to take it a step further and request your participation in it’s development.

CoCart is designed for developers and for v2 of the API, it needs to be developed by those developers who use CoCart.

Originally, my plan for CoCart v3 was to introduce a major re-write of the cart system that the current API relies on. However, that was because at the time I was figuring out on how to support guest customers with the default WooCommerce session handler.

Now that problem has been solved without the need of a major re-write, we can move on to the actual responses developers require.

The most requested to improve CoCart was additional information returned for the cart and for certain fields to be formatted a certain way. Well now is your chance to actually add those details yourself so the cart returns what you need out of the box without the need to use filters.

That doesn’t mean that filters are being removed. There will always be something unique that a developer will require that is not for all.

So what can I add?

The new API is not to focus on adding new core features but to add support where needed and to format data the right way that is compatible for all frameworks without the need to re-format the data again after you get the response.

How do I get involved?

It’s actually fairly easy. All that you require is a GitHub account, fork the CoCart repository and contribute to the v3.0.0 branch with your pull request.

An enhanced issue must be made before hand explaining in detail what it does and why it should be added.

There are also issues already created that may need a PR so if I have not started on those your are welcome to go ahead and try working on one yourself.

I will then review and possible respond with a comment before deciding to merge it. If your PR gets approved, send me your WordPress.org username and I will add you as a contributor when v3 is released.

That’s it. That simple.

So test out what the new API has so far and get coding.

FYI, the changelog will provide some documentation as to what is new.

If you have any questions. Leave it in the comments section and I will get back to you asap.

Support your extension for the new CoCart API

With CoCart v3 near a code freeze, I’m excited to share that the new API is more connected to the front-end of WooCommerce than before.

New matching filters are included for the cart response so you can connect any of the filters you may have already used in your WooCommerce extension to filter the cart template to do the same for CoCart.

For example, your extension may have changed how the subtotal displays in the cart using woocommerce_cart_item_subtotal.

The same can be done for CoCart using cocart_cart_item_subtotal returning the same results and using the same arguments the filter uses.

This enables your extension to be compatible no matter what the store owner decides to use. Its that simple and only one additional line of code is required.

Take WooCommerce Free Gift Coupons extension for example. All that is required for the subtotal to match via the REST API is to apply the matching filter like so.

add_filter( 'cocart_cart_item_price', array( 'WC_Free_Gift_Coupons', 'cart_item_price' ), 10, 2 );

Matching filters

WooCommerce FilterCoCart Filter
woocommerce_cart_item_namecocart_cart_item_name
woocommerce_cart_item_pricecocart_cart_item_price
woocommerce_cart_item_quantitycocart_cart_item_quantity
woocommerce_cart_item_subtotalcocart_cart_item_subtotal
All filters use the same arguments and are in the same order.

If you need any assistance, you can join me and other developers in the CoCart Community via Slack.

I look forward to seeing more WooCommerce extensions supporting CoCart.

P.S. Not all matching filters can just be placed, some results may have to return formatted a little differently depending on how you have developed your extension for that particular area.

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 CoCart from "@cocart/cocart-rest-api";
const CoCart = require("@cocart/cocart-rest-api").default;
 
const api = new CoCart({
  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 CoCart from "@cocart/cocart-rest-api";
const CoCart = require("@cocart/cocart-rest-api").default;
 
const api = new CoCart({
  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
api.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
api.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.