Categories
CoCart Core

CoCart Lite v3.1 Release Notes

It’s finally here. CoCart v3.1

I’m happy with how CoCart has progressed over the last 8 months or so and that is thanks to your support and provided feedback as a community.

CoCart is constantly evolving and with that comes great features to help developers build an ecommerce store in their own image while providing a clean flow for the customers experience.

There is still more in the works and many plans to get more features developed faster. A roadmap will be posted soon to provide more details but for now, we have a core product that provides developers a more out of the box experience.

So thank you again and if you have any questions about this release, please post them in the comments below.

What’s New in CoCart v3.1

There are a lot of improvements, enhancements and tweaks to this release along with a few contributions. I will only list in brief the most exciting features added along with examples on how to use them.

You can view the full changelog here for the rest.

  • Setup wizard is now introduced to help identify if the store is new and prepare the environment for headless setup.
  • Products API is now part of the core with a new option to view single products by SKU and much more.
  • No cache control has been added to help prevent CoCart from being cached at all so results return quicker.
  • Added the ability to set the customers billing email address while adding item/s to cart. Great for capturing email addresses for cart abandonment.
  • Added the ability to return only requested fields for the cart response before fetching data. Similar to GraphQL. Powerful speed performance if you don’t want everything.
  • Added the ability to set a custom price of any item you add to the cart with new cart cache system. – Simple Products and Variations ONLY!
  • Added the ability to update the quantity of items in the cart in bulk using the new update callback API.
  • Prevented certain routes from initializing the session and cart as they are not needed. Small performance boost.
  • Timestamp of each REST API request is returned in the response headers. X-CoCart-API-Timestamp
  • Plugin version of CoCart is returned in the response headers. X-CoCart-API-Version
  • Added to the login response the users avatar URLS and email address.
  • …and finally schema has been added to the following routes: login, item, items, sessions, session and store.

Capture customers email

Pass the customers email address while you add an item to the cart and it will be set in session ready for when it comes to creating the order. Should the customer left the store with the cart unfinished. The email address is there ready for you to use for cart abandonment purposes.

curl -X POST https://example.com/wp-json/cocart/v2/cart/add-item \
  -H "Content-Type: application/json" \
  -d '{
    "id": "71",
    "quantity": "1",
    "email": "mindexploding@awesome.dev"
  }'

Get cart with limited fields

Here is an example of only getting the cart response for the following fields: cart_key, items and totals. Simply list them as a string followed by a , and the response will only return those fields.

curl -X GET https://example.com/wp-json/cocart/v2/cart \
  -H "Content-Type: application/json" \
  -d '{
    "fields": "cart_key,items,totals"
  }'

How to update items in cart in bulk

With the new update cart callback system in place you can now update the quantity of items in the cart in bulk.

Simply pass the item key and the quantity for each item you wish to change. Only need to make the request when you want to update the cart.

curl -X POST https://example.com/wp-json/cocart/v2/cart/update \
  -H "Content-Type: application/json" \
  -d '{
    "namespace": "update-cart",
    "quantity": {
      "fffcf8d139b229986b510f92c8fc4464": 4,
      "e511ee8c822a8419ee8d5f4b76ebff59": 6
    }
  }'

Set Price While Adding to Cart

This particular function is something that is normally programmed based on conditions that allows you to override the set price with the help of using WooCommerce’s action hook woocommerce_before_calculate_totals.

The only possible option that was available at the time was for the store to have a WooCommerce extension called “Name Your Price” installed and pass the price via item data.

curl -X POST https://example.com/wp-json/cocart/v2/cart/add-item \
  -H "Content-Type: application/json" \
  -d '{
    "id": "129",
    "quantity": "1",
    "item_data": {
      "nyp": 24
    }
  }'

However, that was more specific to validating the customers inputted price when adding any product to the cart that enabled the feature.

Now you can set the price how you like without any additional requirements using the new price parameter.

curl -X POST https://example.com/wp-json/cocart/v2/cart/add-item \
  -H "Content-Type: application/json" \
  -d '{
    "id": "129",
    "quantity": "1",
    "price": 24
  }'

To achieve this supported feature, a new cache system had to be created that would store a copy of the modified version of the item in session.

This is then used to set the new price before the totals are calculated.

That’s it. As long as that item is in the cart with the custom price, the sub-total will calculate based on that.

If the item is removed from the cart and is added again without the custom price, the original price will be used.

Stats

This release has made 483 commits and changed 169 files.

Requirements

Minimum requirement for WordPress is now v5.6

Database changes

This release does not introduce any changes to the database.

Final note

Enjoy! ☺

Leave a Reply

Your email address will not be published.