Categories
CoCart Core

CoCart Lite v3.1 Release Candidate 5

Yes you read the title correctly. Another release candidate. Last one was released September 16, 2021. Not how I planned on managing the release cycle for v3.1 but things happen.

Yes you read the title correctly. Another release candidate. Last one was released September 16, 2021. Not how I planned on managing the release cycle for v3.1 but things happen.

For now, I’m just excited to announce that CoCart Lite v3.1 Release Candidate 5 is now available for testing! You can either download it directly from GitHub or install the CoCart Beta Tester plugin.

This release is a much better improvement to the last one thanks to extensive testing and feedback from users. I’m pleased to have CoCart more compatible with PHP 8 even though there are only a small amount of stores using PHP 8 with WooCommerce at this time.

A number of important fixes have been applied as well as solving issues with new features added late. Normally I don’t add things new so late in the development process and if not complete I would remove it and continue it on the next cycle but these features got so intertwined with CoCart, removing them would have broken CoCart with the other additional improvements made.

So in future I will be focusing on more releases with shorter release cycles.

I have also bumped the minimum WordPress requirement to v5.6 and updated the branding of CoCart.

For a full recap on what’s new in v3.1 see the following previous posts before continuing:

What’s New since CoCart Lite v3.1 Release Candidate 4?

It’s a long list so here it goes.

What’s New

  • Prevent certain routes from initializing the session and cart.
  • Added notice for when item is restored.
  • Added cart update route to store controller.
  • Added product routes to store controller.
  • Added the ability to update the quantity of items in the cart in bulk using the new update callback API. See example of use below.
  • Exposed WordPress headers for product route support.
  • 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 Schema to the following cart routes: item and items.
  • Added Schema to the following other routes: login, sessions, session and store.
  • Added Schema to the Products API v2.
  • Added purchase quantity limits for each product except variable and external product types.
  • Added identification which product image is the featured image.
  • Added validation when requesting a variation of a variable product.
  • Added support for variable subscriptions for the add to cart REST URL.
  • Prepared links for product variations.

Plugin Suggestions

Bug Fixes

  • $item_key not passed in validate_item_quantity() function to validate the quantity allowed for the item.
  • get_cached_item() function from calling non-static incorrectly.
  • set_cached_item() function from calling non-static incorrectly.
  • Validating variable products with required parameters.
  • Clear cached cart when requested to clear the cart.
  • Requesting OPTIONS for any endpoint was not returning a proper response.
  • The timestamp for CoCart error logs.
  • Return error responses when updating an item fails.
  • Clearing the cart now 100% clears.
  • Validation of undefined index.
  • The use of WooCommerce API consumer key and consumer secret for authentication is now working again.
  • Trying to access array offset on value of type float.

Deprecated & Replacements

  • Function get_store_currency() is replaced with a global function cocart_get_store_currency()
  • Function prepare_money_response() is replaced with a global function cocart_prepare_money_response()
  • Function wc_deprecated_hook() is replaced with our version of that function cocart_deprecated_hook()
  • Function is_ajax() ìs replaced with wp_doing_ajax()
  • Timezone get_option( 'timezone_string' ) is replaced with wp_timezone_string() function to return proper timezone string on the store route.
  • Removed last raw WooCommerce cart data tax_data object from under cart items as the totals object provides better data for each item.

Enhancements

  • Re-worked session endpoint to get data from the session and not the cart.
  • Allow count items endpoint to return 0 if no items are in the cart.
  • Can now filter cart fields on a sub level except items. 👌
  • Variable products to return the basics of each variation to make it easier for developers to create the UI/UX. 👌

Tweaks

  • Returned available namespaces when requesting the cart update route without providing a namespace.
  • Returns correct error code if item is already restored.
  • Changed if statement to prevent undefined error should an item be restored that is already restored.
  • Clear cart cache before cart is emptied.
  • Injected plugin suggestion to prevent duplication on first page.
  • Plugin suggestion data structure and optimized performance.
  • Item controller extends cart controller for better performance.
  • Changed the use of the session function get_cart() with get_session() for compatibility with hard coded plugins when loading a cart in session.
  • Check cart fees exist before unserialize data.
  • Notice is added before the response is returned when removing an item.
  • Moved API’s into there own versioned directory.
  • Detection of WooCommerce Advanced Shipping Packages extension.
  • Removed shipping label added in RC 4. Not needed. Already have package_name. Only added it because I thought one was needed but it turned out the WooCommerce Advanced Shipping Packages extension was causing an issue with it’s return which is now fixed.
  • Item price in the cart now returns unformatted to be consistent with other monetary values such as taxes and totals.
  • Shipping cost now returns unformatted with set decimals to be consistent with other monetary values such as taxes and totals.
  • Shipping tax now returns as a string not object with just the tax cost unformatted with set decimals to be consistent with other monetary values such as taxes and totals.
  • Replaced wc_rest_prepare_date_response() function with cocart_prepare_date_response() function.
  • Using parent get_variation_product_data() function instead for Products API.
  • Fetched product instance instead of object for Products API.
  • Passed plugin slug used to identify error logs for.
  • Moved validating product up so it can be validated first and allows us to pass the product object when validate the quantity.
  • Cross sell item prices now sets the price decimals.
  • Cart tax total now sets the price decimals.

Improvements

  • Check if price is set for cart cache before updating price.
  • Calculate totals once cart has loaded from session.
  • Removed items now return even if the cart is empty.
  • Shipping rates only return properly if calculated not before.
  • Ensured the cart totals are calculated before an API response is returned.
  • To help support the ability to set a custom price for an item once added, the totals are recalculated before the cart response returns so it is up to date on the first callback.

For Developers

A few filters within the Products API have been changed so the prefix is consistent with others. – API v2 ONLY!

  • Renamed filter cocart_category_thumbnail to cocart_products_category_thumbnail.
  • Renamed filter cocart_category_thumbnail_size to cocart_products_category_thumbnail_size.
  • Renamed filter cocart_category_thumbnail_src to cocart_products_category_thumbnail_src.
  • Renamed filter cocart_variable_empty_price to cocart_products_variable_empty_price.
  • Renamed filter cocart_get_price_range to cocart_products_get_price_range.
  • Introduced new filter cocart_cart_item_subtotal_tax to allow developers to change the item subtotal tax.
  • Introduced new filter cocart_cart_item_total to allow developers to change the item total.
  • Introduced new filter cocart_cart_item_tax to allow developers to change the item tax.
  • Introduced new filter cocart_prepare_money_disable_decimals that allows you to disable the decimals used when returning the monetary value.
  • Introduced new filter cocart_quantity_maximum_allowed that allows control over the maximum quantity a customer is able to add said item to the cart.
  • Introduced new filter cocart_product_not_enough_stock_message that allows you to change the message about product not having enough stock.
  • Added $product object as a parameter for cocart_quantity_minimum_requirement filter so you have more control on which products we want to alter the minimum requirement if not all.

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. This was the final feature addition.

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
    }
  }'

Database changes

This release does not introduce any changes to the database.

Documentation

As I have been so busy working on v3.1 I haven’t had that much time to focus on updating the documentation. However, I have updated the schema for all routes for API v2 so you can see all the arguments, the data that is returned and it’s formats.

Once v3.1 is released the documentation will be updated soon after. If you have any questions about any broken changes, please feel free to make contact.

Testing

If you discover any bugs during the testing process, please let me know by logging a report on the GitHub repository. There I can manage it better and get on the issue asap.

Release Window

If there are no more issues to fix and this release goes smoothly I will release v3.1 on 28th February. So get testing. 🙏

%d bloggers like this: