edf79c699a
* Add new exceptions for out of stock scenarios These are needed to differentiate between the different stock validation errors, and so we can create the correct error message. * Catch new out of stock exceptions when checking the cart for errors This is so we can get the cart sent back to the client, if we don't catch these, then the route will just return a 500 error and crash. * Add ArrayUtils class This will contain methods used to operate on arrays that don't fit anywhere else. * Handle the case in Checkout where the error is already a WP_Error This will happen when the cart fails validation. * Handle StockAvailabilityException in AbstractRoute This will happen when an item or number of items in the cart are out of stock/insufficient stock. * Throw exceptions for each type of invalid stock in validate_cart_items This will allow us to create an error message for each type of violation to display to the user. * Display additional error notices returned by the API * Fix wording when throwing exceptions relating to stock * Handle TooManyInCartException in CartController * Abstract the merging of cart, status, and additional data into new fn This allows us to simplify the way errors are returned from the API. The reason we have to add all of the data at once is because of how WP_Error works with the additional data, if there is already existing data in a WP_Error object, it gets moved into additional_data. By adding all of the data in one place, we stop this from happening. Also since we're only adding status and/or cart explicitly, it makes sense to just do it in one place. * Add get_route_error_response_from_object method This is so we can differentiate between a string and WP_Error object. * Remove unnecessary slashes from WP_Error instantiation * Add option to enclose each item in quotes in natural_language_join * Abstract adding error messages to error object into single function A lot of code was repeated, so doing this cuts down on that and ensures any changes only need to be made in one place. * Create new parent exception for each type of out of stock exception This is so we don't have to repeat code inside each different exception and we can simply inherit StockAvailabilityException. * Catch the generic StockAvailabilityException in get_cart_item_errors * No longer recalculate totals in validate function It is not needed, the totals are recalculated elsewhere. This call was superfluous. * Reduce nesting, and only throw exception if error object has errors * Improve comment on get_route_error_response_from_object method * Fix nesting when throwing the InvalidStockLevelsInCartException * Catch errors during cart validation * Add get_error_message_for_stock_exception_type function This will be used to get an error message depending on the type of extension, and whether the plural form, or singular form is needed. This abstraction is better because the code is used in more than one place in the API. * Use error message generation function instead of creating errors individually * Use specific error codes for each type of error & fix PHPDoc Now the stock_exceptions_to_wp_errors function will return an array of WP_Errors this is better as the client needs a distinct error code to display and replace notices. * No longer remove items from cart or modify quantity if there is an error * Return the WP_Error from RouteException or all Stock WP_Errors * Fix error in PHPDoc * No longer necessary to add get_cart_item_errors into an array This is because the method always returns an array now. * Rename variables in get_cart_item_errors to be more descriptive * Improve PHPDoc on get_cart_item_errors * Replace underscores with hyphens in error code * Only return WP_Errors that have an actual error in them * Add unit test for ensure the cart errors relating to stock are handled * Fix typo in comment * Use optional chaining to add errors to cart |
||
---|---|---|
.. | ||
.github | ||
.sources | ||
.wordpress-org | ||
assets | ||
bin | ||
docs | ||
packages | ||
src | ||
storybook | ||
templates/emails | ||
tests | ||
.distignore | ||
.editorconfig | ||
.env | ||
.eslintignore | ||
.eslintrc.js | ||
.gitattributes | ||
.gitignore | ||
.nvmrc | ||
.prettierrc.js | ||
.stylelintrc.json | ||
.wp-env.json | ||
README.md | ||
babel.config.js | ||
composer.json | ||
composer.lock | ||
docker-compose.yml | ||
globals.d.ts | ||
package-lock.json | ||
package.json | ||
phpcs.xml | ||
phpunit.xml.dist | ||
postcss.config.js | ||
readme.txt | ||
renovate.json | ||
tsconfig.json | ||
webpack.config.js | ||
woocommerce-gutenberg-products-block.php |
README.md
WooCommerce Blocks
This is the feature plugin for WooCommerce + Gutenberg. This plugin serves as a space to iterate and explore new Blocks and updates to existing blocks for WooCommerce, and how WooCommerce might work with the block editor.
Use this plugin if you want access to the bleeding edge of available blocks for WooCommerce. However, stable blocks are bundled into WooCommerce, and can be added from the "WooCommerce" section in the block inserter.
Table of Contents
- Documentation
- Installing the plugin version
- Installing the development version
- Getting started with block development
- Vision for the Feature
Documentation
To find out more about the blocks and how to use them, check out the documentation on WooCommerce.com.
If you want to see what we're working on for future versions, or want to help out, read on.
Code Documentation
Installing the plugin version
We release a new version of WooCommerce Blocks onto WordPress.org every few weeks, which can be used as an easier way to preview the features.
Note: The plugin follows a policy of supporting the "L2" strategy for version support. What this means is that the plugin will support the most recent two minor versions of WordPress, and the most recent two minor versions of WooCommerce core at the time of a release.
That means if the latest version of WooCommerce is 4.3 at the time of a release, then our minimum version requirements for WooCommerce core would be 4.1+.
We recommend you always keep WordPress and WooCommerce core up to date in order to ensure your store is running with the most recent fixes and enhancements to help your store be successful.
- Make sure you have WordPress 5.4+ and WooCommerce 4.3+
- The plugin version is available on WordPress.org. Download the plugin version here.
- Activate the plugin.
Installing the development version
- Make sure you have WordPress 5.4+ and WooCommerce 4.3+
- Get a copy of this plugin using the green "Clone or download" button on the right.
npm install
to install the dependencies.composer install
to install core dependencies.npm run build
(build once) ornpm start
(keep watching for changes) to compile the code.- Activate the plugin.
The source code is in the assets/
folder and the compiled code is built into build/
.
Getting started with block development
Run through the "Writing Your First Block Type" tutorial for a quick course in block-building.
For deeper dive, try looking at the core blocks code, or see what components are available.
To begin contributing to the WooCommerce Blocks plugin, see our getting started guide and developer handbook.
Other useful docs to explore:
Long-term vision
WooCommerce Blocks are the easiest, most flexible way to build your store user interface and showcase your products.