a932ceb59f
* Add context to type * Clean up notifyerrors helpers * Notify and clear top level cart errors * changelog * Make extensionCartUpdate surface the errors * No automatic clearing of notice * Handle generic errors only, add docs * Rename param * Fix linting in readme * Update toc * test coverage * Unused import * We're only dealing with arrays of errors so simplify logic |
||
---|---|---|
.. | ||
validation | ||
README.md | ||
extension-cart-update.ts | ||
index.js |
README.md
Utilities
Table of Contents
extensionCartUpdate
-extensionCartUpdate
Usage -extensionCartUpdate
Options -args (object, required)
mustContain
-mustContain
Usage -mustContain
Options -value (string, required)
-requiredValue (string, required)
Miscellaneous utility functions for dealing with checkout functionality.
extensionCartUpdate
When executed, this will call the cart/extensions REST API endpoint. The new cart is then received into the client-side store. extensionCartUpdate
returns a promise that resolves when the cart is updated which should also be used for error handling.
extensionCartUpdate
Usage
// Aliased import
import { extensionCartUpdate } from '@woocommerce/blocks-checkout';
// Global import
// const { extensionCartUpdate } = wc.blocksCheckout;
extensionCartUpdate( {
namespace: 'extension-unique-namespace',
data: {
key: 'value',
},
} ).then( () => {
// Cart has been updated.
} ).catch( ( error ) => {
// Handle error.
} );
extensionCartUpdate
Options
The following options are available:
args (object, required)
Args to pass to the Rest API endpoint. This can contain data and a namespace to trigger extension specific functionality on the server-side. You can read more about this, and the server-side implementation, in this doc.
mustContain
Ensures that a given value contains a string, or throws an error.
mustContain
Usage
// Aliased import
import { mustContain } from '@woocommerce/blocks-checkout';
// Global import
// const { mustContain } = wc.blocksCheckout;
mustContain( 'This is a string containing a <price />', '<price />' ); // This will not throw an error
mustContain( 'This is a string', '<price />' ); // This will throw an error
mustContain
Options
The following options are available:
value (string, required)
Value being checked. Must be a string.
requiredValue (string, required)
What value must contain. If this is not found within value
, and error will be thrown.
We're hiring! Come work with us!
🐞 Found a mistake, or have a suggestion? Leave feedback about this document here.