CoCart v2.1.0-beta.2

A new beta of CoCart v2.1.0 is now available for testing with new and improved support for guest customers by saving the carts in session to a new database table for storage, performance and ease of cleanup.

Storing the carts

WooCommerce has a similar method of storing the cart data but it is only for logged in users and is stored under the usermeta table. While this is fine, it does not help those who are guest customers neither does the cart data expire unless the cart is emptied, an order has been made or all session data has been cleared via the tools section of the WooCommerce System Status.

In the first beta I simply saved the cart to the WordPress options table wp_options.

I realized that this was not the best solution should the cookie be removed on the users device, the cart would still be saved in the database which would eventually lead to increasing the size of the database due to human error.

The data not only needed to be stored but identified should the cart not have had it’s data updated or used for some time. This lead to creating a sessions table of my own wp_cocart_carts where the cart data per customer would be stored for a period of time.

When is the cart stored?

The data of the cart is stored the moment a customer adds the first item to the cart. The cart data is then updated when another item is added or an item is updated or removed. It’s also updated when a coupon is applied, coupon removed, fees and totals are calculated.

Cleaning the carts

With the large amounts of customers successful eCommerce stores get, maintaining the carts stored in the database needs to be kept in check and not overload the size of the database.

To achieve this, the carts have to expire after X amount of time. 48 hours should be enough but it can be overridden should the store owner choose to increase or decrease the time using a filter cocart_cart_expiration.

A cron-job is scheduled to run twice daily to clean any carts that have expired to keep the new table optimized.

For developers, I have added a new tool option to clear all carts saved in the new table via WooCommerce System Status. I recommend only using this for debugging purposes on a local environment as it does not clear the cookies stored on user devices.

WooCommerce System Status - Tool to clear cart sessions

Getting the carts

Once the customer has added at least one item to the cart, a cookie is created with a unique key for the cart. You then access that cookie to get the value of the cart key.

After getting the cart key you can then request to return the carts content for that cart like so.

There is no permission or authentication required to access the saved cart. As long as the cart key matches or the cart has not expired, you will be able to return the cart contents.

If you have already tried beta 1, it’s important to know that the cookie name has changed slightly to keep everything consistent throughout the code base.

In beta 1 the cookie name is called cocart_cart_id. In beta 2 the cookie name has changed to cocart_cart_key.

What else?

Wither you use CoCart for the REST-API or not, this new supported feature could be used to determine if a cart has been abandoned. This could be helpful to you with detailed information on what your customers are adding to their carts.

By default, storing the cart data was designed for guest customers only but it can also be used for registered customers too simply by filtering in the users ID as the unique key using cocart_customer_id.

Pretty sweat right!

Feedback is Required

For this new release I require you (specifically who are developing for Android) to test and provide me feedback. Getting the support right for you is important.

I’m not an Android developer nor do I have the time or tools to learn Android development so I urge you to tell me what works, what does not and what is missing so I can get it right for you.

No release date is set so there is plenty of time to test.

Thank you for reading and happy testing.

Just a Warning

A new database table will be created upon activation of the plugin for the carts to be stored. Please only install the beta on a local environment.

CoCart v2.1.0-beta.1

Android developers required

CoCart v2.1.0 beta 2 introduces improved support for storing cart data and is available for testing now.

This release introduces what I hope is support for guest customers. I have had a number of users telling me when developing an app that when a customer adds items to the cart and another user adds items to the cart on another device, all items are merged together.

To my knowledge these apps are developed for Android. I don’t know if this issue is the same in other apps developed for other devices.

Now I’m not an Android developer but that should not be happening and it became clear that it was not handling sessions correctly or at all.

So I have added my attempt at manipulating a session for guest customers in order to create an individual cart for them.

To do this, when a guest customer adds an item, for the first time a unique generated ID is created and stores that ID into a cookie called cocart_cart_id.

Once the item is added to the cart, the whole cart is then copied to the stores database under that unique ID. e.g. cocart_2e0eb609fe1a73a80405e7c4cf0ba8d7

That cookie is then used to get the unique ID so the developer can fetch the saved cart and return it’s content.

https://yourdomain.com/wp-json/cocart/v1/get-cart/saved?id=2e0eb609fe1a73a80405e7c4cf0ba8d7

The cart is updated every time an item is added, quantity is updated in the cart, item is restored to the cart, a coupon is applied, a coupon is removed, cart totals and fees are calculated.

The cookie and the copied cart are only cleared from the database if all items were removed or an order was created.

For the time being I have only added the option to get the cart contents, (until I get positive feedback that what I have done works) then if all is good I will apply support to the other endpoints if needed.

So download and test CoCart v2.1 Beta 1 today and provide me your feedback.

Thank you.

CoCart v2 now released

Today marks the first release of the new API that introduces it’s own namespace, major improvements including better responses and new ways to return a response to reduce API requests in your app.

If you have been following the development of version 2 then you already know that for developers it is now possible to filter in additional data.

To share some of the examples on what you can do with CoCart v2 I have created a side plugin that provides various tweaks that you can apply to further enhance CoCart to your needs.

Feel free to contribute other examples that you have applied yourself.

The API

The new API uses the same parameter properties and includes some new ones. The route for the API has also changed including some of the endpoints.

Below you will see a comparison of the route and endpoint changes.

Legacy API

  • wc/v2/cart
  • wc/v2/cart/add
  • wc/v2/cart/calculate
  • wc/v2/cart/cart-item
  • wc/v2/cart/clear
  • wc/v2/cart/count-items
  • wc/v2/cart/totals

New API

  • cocart/v1/get-cart
  • cocart/v1/add-item
  • cocart/v1/calculate
  • cocart/v1/clear
  • cocart/v1/count-items
  • cocart/v1/item
  • cocart/v1/totals

You can still use the legacy API if you are already using it and not yet ready to use the new API but you will miss out on all the new enhanced features.

Upgrading is easy. As I said, the new API uses the same parameter properties so switching over is a breeze. The documentation provides all the details on the new parameter properties.

Minimum Requirements

While it is still possible to use CoCart with WooCommerce v3.X.X it is better to be updated to at least v3.6.X for better performance and security. With the upcoming release of WooCommerce 3.7, I will be updating the minimum required version of WooCommerce to 3.6 in the future.

I have to do this to keep up with the code changes within the WooCommerce ecosystem and to be able to deliver the best experience for my users.

If you have any questions or feedback around the decision for this change, please feel free to leave them in the comments.

Changelog

Here is the full changelog on what’s new in CoCart.

  • NEW: REST API namespace. CoCart is now an individual API and is no longer nested with WooCommerce’s core REST API.
  • NEW: Check to see if the cart is set before falling back to the cart in session if one exists.
  • NEW: Get a specific customers cart via their customer ID number.
  • NEW: Product title also returns besides just the product name when getting the cart.
  • NEW: Product price also returns when getting the cart.
  • Changed: Filter and Action Hook names in new API.
  • Improved: Complexity of functions for better performance and usage.
  • Tweaked: Added checking for items already in the cart.
  • Tweaked: Check if cart is empty before removing an item.
  • Tweaked: Responses for adding, updating, removing and restoring items to return whole cart if requested.
  • Tweaked: Responses for updating items to return the quantity of item along with message.
  • Tweaked: Totals can now return once calculated if requested.
  • Tweaked: Totals now return from session and can be returned pre-formatted if requested.
  • Tweaked: New option to refresh cart totals once item has been added or updated.
  • Dev: Added action hooks for getting cart, cart is cleared, item added, item removed and item restored.
  • Dev: Added filter to allow additional checks before the item is added to the cart.
  • Dev: Added filter to apply additional data to return when cart is returned.
  • Dev: Added filter to change the size of the thumbnail returned.
  • Dev: Added new option to return cart raw if requested.

Progress on CoCart Pro

Now that CoCart v2 is released you can expect to see CoCart Pro very soon.

If you look at the features page, you will already see some of the features that are coming to CoCart Pro. Development on the remaining core features that I have planned are near completion.

With plans for supporting popular official WooCommerce extensions in future updates, support for WooCommerce Subscriptions (which is by far the most popular) is the first supported.

Prices for CoCart Pro has already been released and if you have signed up to the newsletter you will be given a discount for the first year once launched so don’t miss out.

Showcase your store

I’m looking to showcase stores built using CoCart whether it’s a web app, desktop app or a smartphone app for Android and iOS. If you are interested in being featured, please contact me to discuss.

That’s it.

Enjoy CoCart v2 πŸ™‚

CoCart v2 Release Candidate 2

Another release candidate for CoCart v2. I’m not going to specify a release date but if there are no further major issues I will release it sometime this week with more details about CoCart Pro.

All details of the changes made to CoCart for v2 can be found here and links to the specific feature improvements made can be found here.

Before v2 is made available to the public I require your feedback for suggestions, issues or bugs that need to be squashed. View the new documentation available for details on the new API.

Please only test on a local environment or staging site. If you come across an issue, please report it via the GitHub repository where I can manage it more appropriately.

Thank you.

Changelog

  • Added refresh totals parameter to adding item.

CoCart v2 Release Candidate 1

Two days ago was suppose to be the release of CoCart v2 but a major issue occurred that was found last minute so I had to delay and I’m glad I did as this issue actually exposed a few invalid responses and sections that could be improved further.

Now the major issue is resolved and further improvements have been made, CoCart v2 is ready for real this time but before it is made public I would like you to test it out for me and report any bugs or issues you come across.

The documentation will be updated over the weekend but is 99% ready for CoCart v2.

Updated: 1st July 2019

Release Candidate 2 was released. See post for more details.

Thank you for your patience. πŸ™‚

Changelog

  • WP_Error is no longer in CAPS
  • Added notes for translators and tweaked strings.
  • Corrected feature mentioned for CoCart Pro.
  • New totals override totals instead of another REST Response.
  • Added original price of product when getting cart.
  • Added more argument descriptions.
  • Optional argument corrections.
  • Return a response should specified cart item key not exist in cart.
  • Tweaked CSS for admin notices.
  • Ensure we don’t add a variation to the cart directly by variation ID.
  • Generate a ID based on product ID, variation ID, variation data, and other cart item data.
  • Added new option to refresh cart totals once item has been added.
  • Use self get_cart instead of cart class get_cart.
  • Added new option to return cart raw if requested.
  • Quantity of item increases if item already in cart. Responses improved.
  • Removed the need to format quantity value again when checking available stock.
  • No need to check if WC endpoint is requested.
  • Removed validate_callback for pre-formatted totals.
  • Made sure the cart item key parameter name is consistent.
  • Return cart parameter is no longer ignored.
  • Return cart item contents rather than boolean status.
  • Changed hook for loading controllers.