* Show total sale badge in medium carts
* Add markup to cart line item row to enable it to be displayed as flex
* Add styling to display price and sale badge as flex
* Revert product price being displayed as block
* Rename sale badge and price wrapper
* Hide line-total sale badge on mobile
* Change class name on total price and sale badge wrapper again
* Fix cart line subtotal display when currency has 0 decimals
* Fix wrong usages of getCurrency instead of getCurrencyFromPriceResponse
* Add tests
* Move comment in tests to relevant line
* Use else if in ProductPrice
This is because the priceComponent variable should be set depending on some conditions, but multiple of them could be true, so by using else if we only handle the first true case
* Update snapshots for jest
* Show cart item total price including taxes when DISPLAY_CART_PRICES_INCLUDING_TAX is true
* Show cart item total price including taxes in Checkout block too
* 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
* Add filter to extend product price
* Extend order summary product price too
* Make it so 'format' is applied to all product price types
* Order
* Pass lineItem to the filter
* Remove code targeting WC Subscriptions
* Rename filter
* Remove unnecessary CSS block that made prices be displayed as blocks
* Use line item totals instead of product price multiplied by quantity to show line item price
* Fix wrong currency usage
* Add comment to disable eslint
* Fix JS error when totals is undefined
* Align order summary item price to the right
* Use extendibility API instead of filters
* Remove __EXPERIMENTAL_CART_ITEM_PRICE_FILTER from docs
* fix rebase
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* Pass get_country_locale via assets
* Create helper to prepare and merge address fields
* Use new helper in address form
* Only pass field overrides now that fields are merged
* Fixc configs and remove lodash usage
* Prevent formatting of empty postcodes to suppress api error
* prevent memo on rerender
* Conitonal enqueue of locale data
* define index in increments of 10
* remove address-form
* circ deps changes
* Workaround for core data issue
* fix test
* remove prepareAddressFields export
* Remove old comment
* object from.entries polyfil
* Revert "object from.entries polyfil"
This reverts commit ba343adcf5fd2f843b225aebe340cce9b664c851.
* replace fromentries
* fix final fromentries
* Add validation function
* Prefix validateElementOrString with __experimental
* Update experimental docs
* Typo
* Update JS docs
* Use an object for applyCheckoutFilter args
* Args doesn't need to be an object
* Wrap validation function execution in a try/catch block
* Only accept strings for the totalLabel filter
* Change applyCheckoutFilter signature
* Add validation function
* Add Product name filter
* rebase
* update second filter call
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* Replace filters with an extendibility API to hook into Cart and Checkout blocks
* Update docs
* Add a validate argument
* Add docs comments
* Add tests
* Add validation function
* Prefix validateElementOrString with __experimental
* Update experimental docs
* Typo
* Update comment
* Update JS docs
* Use an object for applyCheckoutFilter args
* Args doesn't need to be an object
* Wrap validation function execution in a try/catch block
* Only accept strings for the totalLabel filter
* Change applyCheckoutFilter signature
* Apply filters for subtotal and sale badge in CartLineItemRow
* Append suffix to prices and SaleBadge if passed in as a prop
* Add subtotal filter to OrderSummaryItem
* Add tests for OrderSummaryItem and ProductPrice
* Rename test for ProductPrice
* Update checkout filter registration plugin name
* Remove obsolete snapshop
* Remove suffix and change to format
This is because we want to make the entire price string editable, not just the part after it.
* Change formatting on SaleBadge to use createInterpolateElement
* Remove tests that are no longer needed.
* Update ProductPrice tests to reflect changes to format prop
* Check that subtotalPriceFormat contains <price/> in OrderSummaryItem
* Fix cart block styling to stop badges overflowing the container
* Add <price/> placeholder in OrderSummaryItem price filter
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* Replace filters with an extendibility API to hook into Cart and Checkout blocks
* Update docs
* Add a validate argument
* Add docs comments
* Add tests
* Add validation function
* Prefix validateElementOrString with __experimental
* Update experimental docs
* Typo
* Update comment
* Update JS docs
* Use an object for applyCheckoutFilter args
* Args doesn't need to be an object
* Wrap validation function execution in a try/catch block
* Only accept strings for the totalLabel filter
* Change applyCheckoutFilter signature
* Fix ShippingRatesControl not honoring renderOption prop
* Update order summary design
* Updates TotalsCoupon design
* Update Cart block sidebar title design
* Make values bold and labels regular in Cart and Checkout sidebar
* Update styles of shipping rates selector and radio control
* Remove unnecessary overflow rule in Panel content
* Fix shipping options in Checkout block
* Add some Twenty Twenty One fixes
* Fix saved payment methods display
* Remove top spacing no longer necessary in order summary quantity badge
* turn Totals title to bold
* Move right padding from product name to item description
* Take left margin off list items in product details
This is because in themes where a left margin is applied to li elements, the product detail/addon gets indented and it does not sit flush with the edge of the product details container. Adding this rule to the main wc-block-components-product-details rule will stop other themes indenting <li>s
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
Co-authored-by: Thomas Roberts <thomas.roberts@automattic.com>
* move shipping-rates-control and shipping totals back into base/components/cart-checkout
* fix notice styling
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* Add left vertical bar to payments methods step.
* Remove horizontal borders around order notes.
* Add class to order notes component.
We need it to traget that element with CSS.
* Update padding on order notes checkbox to match desing.
* Remove full stop to match the design.
* Add label for not saved payment methods option.
* Remove use new payment radio.
* Always show new ayment methods selector
* Remove editor context for now.
* Add accordion component skeleton.
* Small component refactor.
* Use accordion for new payment options.
* Fix jsdoc.
* Add styling.
* Add input styling.
* Hide label if we don't have saved methods.
* Cleanup.
* Cleanup and styling.
* Add target class to aid with alignment.
* Update use new payments label styling.
* Update Place Order button location.
* add full stop to payment method copy
* ensure that there is always a (default) selected payment method:
- using `activePaymentMethod` from context
- this ensures there is a default selected on initial render
- and handles any dynamic changes to available payment methods
- e.g. COD disappearing when change shipping option
- remove unused / redundant selectedMethod prop - context is best
* use tab-based payment UI for 2 or fewer payment methods:
- move saved payment state to payment context; it's shared state needed
by both PaymentMethodOptions and SavedPaymentMethodOptions
- show previous tabs UI if:
- customer has no saved payment methods (cards)
- store has 2 or fewer payment methods available
- when initialising SavedPaymentMethodOptions, only select one if the
user hasn't selected a real payment method - this ensures radio
buttons switch correctly between saved card => `Use another`
- remove various props and local state that is no longer required (🤞🏻)
* experimental - styling tweaks for single payment tab (remove "tab" UI)
* Revert "experimental - styling tweaks for single payment tab (remove "tab" UI)"
This reverts commit e09dd4862b97d989d950a9d67672d83e7b8992e4.
* Add single payment method UI.
* Adjust single method styling.
* Add outline and margin to two methods version.
* Fix gap for order notes on/off option.
* Update Order button spacing CSS.
* Reuse computed values.
* Remove tabs and single payment option.
* We no longer need this test as the UI was changed.
* Fix payment methods labels height.
* Simplify.
* Remove not needed import.
* Typecheck an option.
* Refactor code.
* Rename.
* Rename.
* Update typdefs.
* Remove border for add order notes.
* Correct spacing for radio-button and label.
* Add simple test. Switch to payment method.
* Update style.
Co-authored-by: Rua Haszard <rua.haszard@automattic.com>
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* Improve nonce handling by rejecting previous nonces from cache
* use timestamp instead of previous nonce
* Switch back to time()
* Seconds not ms
* Add comment about the date code
* Add supports data to payment methods abstractions. Implement in Stripe.
* Add capabilities to the payment gateway.
* Payment requirements in cart schema.
* Supported features format update.
* Formatting.
* Check required payment features.
* Refactor capabilieties check.
* No need for the cart parameter.
* Allow external modifiacation of features capability.
* Use ExtendRestApi to inject payment requirements into cart endpoint.
* Simplify the code.
* Enable more integrations.
* Enable Stripe payment request.
* Move the filter to a more correc location.
* Add features check.
* Update typedefs and documentation.
* Update tests with new functionality.
* Style fixes.
* Expose schemas
* Accept strings for select shipping rate
* strings are allowed
* Refactor shipping package to hold it's own state
* Add extension data to cart hook
* Progress but state is broken
* Move state back to hook
* Progress but state is broken
* use shipping hook updates
* Fix re-render issue
* hide x1
* Shipping slot fill
* Working slot fills
* Do not export package
* Update extend usage in unit tests
* update mock test data
* Package per slotfill
* Resolved merge conflicts
* Update assets/js/blocks/cart-checkout/subscriptions-integration.js
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* rename slot
* deriveSelectedRates return doc
* useCallback in throwError
* final class ExtendRestApi
* spacing
* Move shipping rate selection to package level
* remove const for counts
* Remove schemas from extend
* unused use
* move to a single fill for packages
* add todos
* move subs code
* fix extra extensions
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* Fix image link in all products block.
- add alt text on product image
- prevent the appearance of both product and placeholder image at the same time
- make anchor with placeholder image accessible
* Add testing for product-elements/image block.
* Create new vars to differentiate between single and multiple item price
This is because we need to display the subtotal of the item AND the total (subtotal * quantity)
* Add subtotal and move quantity picker
As per the new designs, the quantity picker should be moved below the product metadata, and the product subtotals should appear below the product name.
* Move line item total to top of grid on mobile/medium/small
* Remove CSS for trash icon that is no longer used.
* Remove link style colour override from product name and make total bold
* Remove quantity column from CartLineItem
This is because the quantity picker is now displayed below the product metadata and name.
* Fix margins around quantity picker and its width
* Always disable link to product in OrderSummaryItem
* Add single price below product name in OrderSummaryItem
* Add styles for new OrderItemSummary design
* Move total into its own "column"
This is to stop product description text flowing under the total and making it look untidy.
* Add styles to cater for total price being its own column
* Convert precision after multiplication instead of before
* Remove unnecessary div from OrderSummaryItem
* Remove line height from product names on order summary
* Add more margin to the bottom of the product metadata div
* Delete trash icon
* Only remove margin from the bottom of last product-details
* Move quantity input to below product name in cart skeleton
* Add placeholder for individual price to Cart skeleton
* Honor hidden property of cart item data and add support for experimental property
* Add docs to experimental property
* Typo
* Add protection in ProductDetails for the case where 'details' is not an array
* Update ProductDetails so it works properly in cases where 'name' is not provided
* Add snapshot testing to ProductDetails
* Remove savePaymentInfo check when displaying payment methods
This is because the savePaymentInfo is derived from whether the save payment method checkbox shows. This check doesn't make sense to do because it's not a good indicator of whether the payment method is enabled. Subscriptions for example hides the checkbox because it is implied that the method will be saved. We should instead rely on the server-side to only send permitted saved payment methods.
* Add safely_get_request_payment_method
This will allow us to try to get the payment method if it was passed in the request, but will default to an empty string if not. This is different to get_request_payment_method because it doesn't throw any errors. We need it to be different because get_request_payment_method is used when the order definitely needs payment (so a normal checkout scenario, vs. a £0 subscription checkout)
* Add action to update order meta when checking out
This is needed because some extensions rely on this action to add their information to the metadata of order items.
* Remove safely_get_request_payment_method
This is no longer needed.
* Remove @since from experimental hook
* Add PHPDoc for new update_order_meta hook
* Document use of experimental hook
* Reinstate the check for allowing saved cards
* Add method to Stripe integration to determine if saved_cards is enabled
* Add new field to get_payment_method_data
This adds displaySavePaymentMethodCheckbox which will be used to determine if the checkbox to save payment methods should display.
* Add displaySavePaymentMethodCheckbox option to client
This will determine whether the "Save payment information" checkbox will be displayed.
* Add requiresSaving option to Stripe payment method data
This is informed by the saved_cards option and the result of the wc_stripe_display_save_payment_method_checkbox filter.
* Rename displaySavePaymentMethodCheckbox to requiresSaving & fix logic
* Revert negation on display_save_payment method_checkbox filter & rename
We are going to rename the properties we use to determine whether saved cards are shown, or whether the save payment method checkbox is shown, so that their names are more descriptive of what they are for.
* Rename allowSavedCards and requiresSaving in Stripe integration
* Rename savePaymentInfo&requiresSaving to showSavedCards & showSaveOption
This is so we can hide the checkbox independently of hiding the saved payment methods.
* Show deprecated message if payment methods use savePaymentInfo
This is because we are leaving it in to enable backward compatibility but payment methods registering using this should be informed of the change in case it gets removed.
* Update Stripe typedefs and keys of supports object
* Show customer payment methods if showSavedCards is true on the method
* Make PaymentMethodTab accept showSaveOption prop
This will allow us to show the save checkbox only if the payment method says it should be shown.
* Update tests to use new keys in supports when reg'ing payment methods
* Add optional chaining when validating payment method config
This makes the code a little tidier :)
* Update assets/js/blocks-registry/payment-methods/payment-method-config.js
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* Add more information to deprecated call in payment method config
* Fix lint error
* Fix prop types for PaymentMethodTab
* Add information about supports on payment methods to docs
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* move items to package
* move components to package
* fix dep issue
* pass down classname
* move Panel and Price utils
* expose extensions
* fix import
* move cart call to inside slot
* fix unit tests
* fixes after rebase
* move ShippingRatesControl into packages/checkout
This fixes the `wc-blocks-checkout` circular dependency because `Package` was importing from `@woocommerce/checkout`.
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* generating changeset for pull request
* generating changeset for pull request
* Update changelog.txt for 4.3.0 release.
* Update testing instructions for 4.3.0 releae.
* Update testing instruction for review.
* Revert "Improve error displayed to customers when an item's stock status changes during checkout. (https://github.com/woocommerce/woocommerce-blocks/pull/3656)"
This reverts commit a30179f165.
* Revert 3656 documentation changes.
* Update test zip link.
* Update release date for 4.2.0.
* Bumping version strings to new version.
Co-authored-by: github-actions <github-actions@github.com>
Co-authored-by: budzanowski <bartosz.budzanowski@gmail.com>
* fix circular dependency in text-input
* fix circular dependency in chip component
* fix circular dependencies in AddressForm component
* fix circular dependencies in product-list
* fix circular dependencies in hooks
* fix circular dependencies in context
* Fix circular dependencies in components/cart-checkout
* fix use-checkout-submit test
- can’t mock the hook alias anymore
- account for undefined object returned from `usePaymentMethods`
* 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
* Inject the routes controller
* Cart totals need to be calculated on cart routes or fees will be missing
* Add fees to schema and response
* Add fees to useStoreCart
* Fix styling of multiple fee rows
* Fix test shape
* update input colors for dark and light mode + tweak padding and alignment
* update light input dropdown text color
* Fix lint errors
* Fix package lock.
* Use input-text-active for select options
* Make sizes responsive in radio control
* Unify border colors of text inputs, checkboxes and radio controls
* Unify radio control sizes in mobile/desktop
Co-authored-by: David Levin <davidlevin@Davids-MacBook-Pro-2.local>
Co-authored-by: budzanowski <bartosz.budzanowski@gmail.com>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* add plugin area
* add invisible errorBoundary
* introduce slot
* change name to OrderMeta
* fix rebase
* wip
* create checkout file
* Import ExperimentalOrderMeta from @woocommerce/checkout
* Rename wc-checkout-packages handle to wc-blocks-checkout
* Only import wc-blocks-checkout in the feature plugin
* Move checkout package to packages folder
* Add @woocommerce/blocks-checkout to tsconfig
* Move TotalsItem to @woocommerce/checkout
* Use Fragment short syntax
* Remove example code
* Honor renderError prop in BlockErrorBoundary
* Rename error boundary
* Add example code
This reverts commit 9b6af7178cbef05589779ef7f5a750d53e7fc8cf.
* Revert "Add example code"
This reverts commit 2f50349692f53c5bb143516365eee7a98d580dfd.
* Add @woocommerce/blocks-checkout to jest config
Co-authored-by: Seghir Nadir <nadir.seghir@gmail.com>
* add you don’t need lodash eslint plugin
* handle lodash.omit eslint errors
- storybook and webpack config implementations were just ignored.
- shared/validation/index.js was converted to use ES6 destructuring to eliminate usage.
* remove lodash assign usage
* convert lodash isNan to Number.isNan
* ignore lodash.flatten lint error for now
* remove usage of lodash.isNil
* add exclusions for lodash rules in main eslintrc file rather than per file.
* Allow integers in payment_data values
* Revert "Allow integers in payment_data values"
This reverts commit b7f2ca4a5b696091afe796f47e84f584a0b27d9e.
* Enforce payment tokens to be strings
* Revert "Add 'hidden' class name when using the 'hidden' attribute"
This reverts commit 0332e33a60a516506718e8ed4659e45d32dc80a4.
* Add styles for hidden panel content
* Add docs about account for the hidden attribute in styles
* Update docs/theming/README.md
Co-authored-by: Rua Haszard <rua.haszard@automattic.com>
Co-authored-by: Rua Haszard <rua.haszard@automattic.com>