* account for registration enabled setting when creating accounts
* default to false instead of global setting for initial allowCreateAccount attribute
* consider global allows signup value for whether account creation checkbox shows
* include existing hook when determining if checkout signup is available:
- woocommerce_checkout_registration_enabled hook
* use public api for registration settings (via WC_Checkout)
* initial round of test fixes
* fix logic flaw exposed by tests and align tests with actual values in real use
* return early if WC_Checkout is not available
* remove temporary test group and uncomment new test.
* improve test method name
* fix comment to match new routine name
* ensure block shows login prompt when store disables checkout signup
* fix incorrect conditional order and cover with tests
Co-authored-by: Rua Haszard <rua.haszard@automattic.com>
* prototype 'create account' checkbox in checkout block
* expose store config for generating password/username to blocks:
+ use FILTER_VALIDATE_BOOLEAN instead of hard-coded `yes`
* stub out signup form in checkout block
* context / provider to store checkout signup form data
* revert signup form - checkout block will always generate username etc
* persist signup checkbox in checkout state & pass to checkout API
* add `create_account` param to order API, fix name in client POST
* handle creating user account as part of order (first cut)
* ensure the order is associated with the new customer
* only show 'create account' checkbox when appropriate (guest checkout)
* remove unnecessary username/password variables
* refactor account-creation logic into functions:
- clarify inputs and outputs
- use RouteException for error handling
- use woo options directly, avoid dependency on WC_Checkout
* update "email exists" error message to use existing error message text
* handle all known errors from wc_create_new_customer + use core message
* only show "create account" checkbox to shopper when necessary:
- if guest checkout is disabled, user must create account - not optional
* only show "create account" if account creation is optional:
- fixes incorrect logic in previous commit
- add some comments to clarify
* fix create account logic in API when checkout requires account:
- use correct woo setting option name
- reverse logic to match option = allow guest false means registration required
* strip html tags from create account error messages
* temporarily force enable autogenerate user/pass in new account API
* fix rebase errors
* add new allowCreateAccount attribute in checkout block
* show/hide `Create account` checkbox dependent on block attribute:
- previously was dependent on store setting
* new create user API, with set initial password email (first cut):
- use core register_new_user for creating the user
- this triggers core "set new password" email
- generate username using logic lifted from WC core
- rough cut, lots to tidy/polish here
* remove alternative/unused create account function
* set `Customer` role for signups during checkout
* eslint fix - switch case break
* remove comments that mirror code & might go stale
* tidy func comment
* remove unused function
* use store setting `allow signup` for default value of new block option
* refactor order signup logic to service class first cut:
- new CreateAccount service
- hook up via custom action (for now at least)
- paste over existing create account logic (temporary - will be replaced)
* adapt wc_create_new_customer logic in CreateAccount service (WIP)
* set default_password_nag on new account + throw instead of WP_Error
* rename `createAccount` => `shouldCreateAccount` to clarify meaning
* fix checkout block - renamed `shouldCreateAccount` (missed in prev commit)
* prototype sending alternative email template for checkout signup
* add magic link to set password to blocks new account html email
* tidy up new account email templates - set password link, subject/heading
* use same id so merchant setting tweaks apply to our new improved email
* remove logging
* code tidies in CreateAccount service:
- remove unnecessary constructor
- type-hint in should_create_customer_account
- streamline logic in should_create_customer_account - remove
unnecessary `empty` check
- add comments to illuminate different use-cases handled by should_create_customer_account
* don't provide password to new account email templates (no longer used)
* declare dependencies in root namespace
* code tidies on new account email class:
- correct namespace and camelcase name
- declare class in file, don't instantiate; instantiate in client code
(CreateAccount service) when used
- no require/file import, use `use`
* move CustomerNewEmail to folder matching namespace
* use Package->get_path for email template paths:
- CreateAccount service now depends on Package
- CreateAccount passes Package to email class so it can use `get_path`
- note: CustomerNewAccount is not registered with DI container as it
needs to be instantiated after Woo init (for `WC_Email`)
- shift email templates to {plugin}/templates, consistent with WP
convention
* call CreateAccount::from_order_request directly, no custom hook:
- custom hook is not appropriate as we may not want to allow
extensibility in this way - TBD
* add appropriate margin above create account checkbox
* remove unnecessary direct-access protection
* generalise name of error-handling method
* simplify CustomerNewAccount - instantiate directly, when needed
* remove unused new_account_email member - now instantiated on demand
* numerous fixes and updates due to rebase changes
* fix typo in name of CustomerNewAccount php file (missing `n`)
* experiment - link to lost-password form in my-account (prototype branded screen)
* Revert "experiment - link to lost-password form in my-account (prototype branded screen)"
This reverts commit e1dc6dd5e9f0218ede81da92188d813c2d0856d9.
* feature gate CreateAccount service init to dev build only +
+ remove stale comment
* feature gate front end "Create account" checkbox to feature plugin only
* feature gate editor "allow signup" option to dev build only
* feature gate checkout api create account - dev build only
* tweak feature gating PHP logic so it's robust:
- all PHP feature gating is in the service class
- all publicly-available methods return early if feature gate off
- Checkout rest API transparently calls service - no explicit feature
gate at API level
* ensure frontend/editor features are feature gated (isExperimentalBuild is a function)
* feature gate value of checkoutAllowsSignup - can only be true in feature plugin
* fix a / an typo in comment
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* remove commented code
* hello world unit test (doesn't test anything yet)
* add a command for running unit tests when container already up:
- this should probably move to another PR/branch
* basic tests of core logic in CreateAccount service
* import isExperimentalBuild direct:
- import from alias package was causing an issue, likely a dependency cycle
* refactor from_order_request to return new user ID so it's easier to test
* test creating a customer from an order + rest request:
- i.e. a full end-to-end integration test
* delete redundant test and tidy comments
* generalise test to provider format
* refactor create-dup-user err test to use same approach as success test
* add test for when user should not be created
* don't hard-code options in "create" test, remove redundant provider in no-account-requested test
* de-generalise "user already signed up" test
* add test for malformed email
* flesh out & comment successful signup tests
* flesh out "invalid email" tests
* clarify no account requested test comment
* remove phpunit:quick - I don't think it's needed
* add comment explaining this is an integration test
* experiment – disable feature flag, is this why the tests are failing?
* revert test commit - restore feature gate (experimental flag)
* skip all tests if CreateAccount is disabled due to feature flag
* d'oh - expose CreateAccount:is_feature_enabled so can be used in tests
* add jsdoc for checkout-state shouldCreateAccount field
* remove unnecessary comment + fix whitespace/indentation
* simulate logged-out user for createaccount signup tests
* use a single, compound if statement for early return (review nitpick)
* don't hide `checkoutAllowsSignup` store setting behind feature flag:
- the feature flag should be used to enable/disable behaviour
- it's dangerous to adjust store settings/options based on feature flag
* rejig tests so they require woocommerce_blocks_phase==3:
- make feature gate method private to avoid exposing
- remove feature flag check & test skip for other builds
- set blocks phase in travis config
* remove redundant user-logout in test setup - cleaner to just require this
* use WP function bracket style (same line)
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* refactor all draft order functionality to be in it’s own class and feature gate it.
* move and fix tests for draft order deletes
* add test to ensure only draft orders are deleted
* implement review feedback and assert valid results before deleting
* update tests
* doh method can’t be protected
* fix conditional for removing scheduled action
* switch to use Woo Core function for catching the exception
* add tests for error handling.
* use `$wpdb->prepare` and remove temp group on test
* Show backorder notice in the Cart block
* Don't render variation <div> if empty
* Create ProductBackorderNotification component
* Add product backorder notification to the checkout block
* Fix classname and comment
* Rename notification->badge and don't show low stock badge if backorder is shown
* Use ternary to dispaly backorder/low stock badge
* Add attributes to API
* Add component
* API updates to return variation data
* Update to handle updated api responses
* Working picker
* Update tests
* update test
* Use SelectControl
* Add Picker to Form Block
* Code cleanup and splitting
* Inline todos
* Update todos
* Update assets/js/atomic/blocks/product/add-to-cart/product-types/variable/variation-attributes/index.js
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* change classname and move styles within component
* Correct conditional
* Avoid nesting filters
* Remove exclude from getVariationsMatchingSelectedAttributes
* basic select styles
* remove custom select styles
Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
* Remove summary from API
* Add wordCountType to assets
* Update packages
* Remove summary from test data
* Featured product uses short desc
* Pass description instead of summary
* Use new Summary Component
* Component and tests
* Increased versititilty of methods
* Update assets/js/base/components/cart-checkout/product-summary/index.js
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* Extra tests for html tags
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* Remove unused wc/blocks/cart endpoint
* remove unused withProducts hoc
* Remove getProducts util
* Use store API products endpoint in product blocks
* Remove product endpoint tests
* Remove controller
* Switch attributes endpoint to store api
* Refactor withAttributes to use store API
* Migrate tags and cats to store API
* MIgrate variations to store api
* Migrate reviews to store API
* Drop dedicated variation endpoint
* Move tests
* Move cart init
* Fix reviews
* Comment out broken tests
* Remove old class based with-attributes test
* `use` is never relative - absolute is always used so backslash is not needed
* Move process_legacy_payment code to rest api class
* Move storeapi directory
* Updated namespaces and moved tests
* Return updated cart if there is a conflict (409 response) e.g. item no longer exists
* Receive updated carts
* Update tests and coupon handling
* Further rewording
* Switch add to cart events to useStoreCart hook
* Add to cart endpoint
* Inject dependenct schemas
* Feedback, cart items are based on product schema
* Variable typo
* Move hook to base
* Update totals correcrly
* Update tests to use schema/routes class
* Update tests to correctly use schema
* Remove type hint to prevent strict standards error
* CheckoutProcessing work
add missing memoization and implement useRef strategically
This prevents effects from firing unnecessarily.
Tweak assets registration
Order hydration and checkout/ endpoint updates
Fix error handling
Error handling
* Missing isset in stripe
* Fedeback
* rename draft order ID action
* Todos
* Disable authentication for the Store API completely.
This may also resolvewoocommerce/woocommerce-blocks#1991
* Add nonce handling to the abstract route
* Default state
* Add shared controls including nonce api fetch
* Use shared controls
* Hydrate inital nonce
* Update data stores
* Update nonce validation
* Fix tests by setting nonces
* Remove print_r debug
* Revert useStoreCart change
* Add nonce middleware
Co-Authored-By: Darren Ethier <darren@roughsmootheng.in>
* Switch back to apiFetchWithHeaders
* Docs
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* Remove CartShippingRates endpoint
This was moved to the /cart endpoint
* Unused customer endpoint
* Split controllers into routes
* Update/fix tests
* Add draft order ID property to the Cart schema.
* Fix status check
* cart/order-create endpoint
* Placeholder for checkout endpoint
* Resolve merge conflict
* Update classes to match master
* Use correct schema
* Remove CartShippingRates endpoint
This was moved to the /cart endpoint
* Unused customer endpoint
* Split controllers into routes
* Update/fix tests
* Create RouteException and single handler per route
* Move exception to cart controller
- `useStoreCartItemQuantity` now receives the cartItem instead of the `cartItemKey` as an argument. I didn't notice in previous reviews how it's used in the context where we already have a cartItem so implementing this reduces complexity and makes the hook more precise for it's purpose.
- Add `backorders_allowed` to the CartItem schema for the API. This allows for client to have correct logic for maximum quantity when this value is true.
- Implement the above in the `CartLineItemRow` so that quantity picker is limited by the amount of stock remaining if that is available (`lowStockRemaining`) and the `backorders_allowed` is false.
- maximum quantity is currently hardcoded to a (filtered) value of `99` when other conditions don't apply (see related issue in woocommerce/woocommerce-blocks#1913)
* Add expires column to table
* Use core class if it exists.
* Add Exception class
* Update for currcurrency
* Update tests to handle exception
* Add back legacy stock handling
* Update comments
* add select shipping endpoint to router
* add select shipping method
* add selected rates to cart
* better select rates
* move schema function to seperate function
* move validation to Cart Controller
* fix wrong session key
* Update shipping/cart endpoints (https://github.com/woocommerce/woocommerce-blocks/pull/1833)
* Items should not have keys in API response
* Include package ID in response (this is just a basic index)
* /cart/select-shipping-rate/package_id
* Add package_id to package array
* Update responses and add shipping-rates to main cart endpoint
* update-shipping endpoint
* Add querying selected shipping rate to the store (https://github.com/woocommerce/woocommerce-blocks/pull/1829)
* add selecting shipping to store
* directly call useSelectShippingRate
* refactor cart keys transformation to reducer
* remove selecting first result and accept selecting
* move update shipping to new endpoint
* pass selected rates down
* select shipping right directly and fix editor issues
* fix some broken prop types
* key -> package id
* Update and fix cart/shipping-rate tests
* fix case for when rates are set
* Update useShippingRates test
* add args to rest endpoint
* move selecting shipping rate logic to hook
* fix some naming issues
* update propTypes
* update action call
* fully watch cart state
* address review issues
* fix prop type issues
* fix issue with rates not loading in checkout
* remove extra package for shipping
* move ShippingCalculatorOptions to outside
Co-authored-by: Mike Jolley <mike.jolley@me.com>
Co-authored-by: Albert Juhé Lluveras <aljullu@gmail.com>
* ensure cart totals update when items are removed (prototype):
- return complete cart object from DELETE cart/items/:key
- use receiveCart on client to update whole cart including total
* move API endpoint for removing cart items to cart controller:
- returns full cart schema so should be part of cart controller
- is now a POST request with param - not strict REST
- fix up client action to use new API
* move API test for removing cart items (API has moved)
* use correct path for remove API in tests (doh!)
* add extra API test for remove_cart_item with bad key => 404 (experiment)
* experiment: delete test_remove_cart_item, does test_remove_bad_cart_item work?
* reinstate test_remove_cart_item with single valid request
* remove unnecessary newline
* tidy comments in PHP api tests, rerun travis?
* remove test_remove_cart_item which may be causing problems
* reinstate troublesome remove cart item api test (experiment):
- see if this works now travis issue is resolved
* whitespace
* show correct total when changing cart item quantity:
- move update cart item quantity API to cart controller
- & return full cart response
- update js action to new API route & receive full cart response
* simplify test_remove_cart_item API test - now just tests a valid remove succeeds
* remove test_update_item (API has moved) +
+ experimentally remove test_remove_bad_cart_item
- testing if cart remove tests interact with each other
* fix tests (🤞) - pass params in body, not as query params
* reinstate test for re-deleting same item
* update API docs - update/delete cart item have moved to /cart
* add response data checks to new cart API tests:
- extra protection against expected 404 "false positives"
* reinstate API test for changing cart item quantity
* fix remove cart item body tests - MIA items return error code, not cart
* fix test - quantity param is int not string
* attempt fix 404ing test_update_item:
- only allow POST, remove trailing `/`
- align array equals for good measure :)
* fix action for update-item - method=POST, now takes body params
* fix response body asserts in test_update_item
* reinstate update_item and delete_item on CartItems controller
* typos + examples in new cart items API docs
* reorder previous cart item docs to minimise diff/churn
* reinstate tabs in docs response example
* Persist previous shipping rates while loading
* Refactor ShippingRatesControl LoadingMask
* Show package name
* Simplify CSS to avoid using the adjacent selector
* Add comment to explain why 'selected' is hardcoded in the editor
* Rename package 'index' to 'key'
* Move coupon code for API requests to body - fixes issues with coupon codes containing special characters
* Use wc_format_coupon_code when applying/removing coupons via the cart endpoint
* Add tests
* useStoreCartCoupons hook
* Apply coupon w/ basic error handling for the fetch
* Basic store specifically for cart data
* Working on error states
* Show error on coupon fail
* removeCoupon action
* Added extra endpoints for more efficient cart queries
* Apply/remove coupons working
* Track applying/removing state
* StoreCartCoupon typedef
* Use coupon code on index
* Remove custom controls definition
* Adjust storecartcoupons mapper and remove ref
* Move cartData defaults and remove ref
* Call API directly, avoid schema lookup
* Improved selectors
* StoreCart typedef
* Split up cart state data and add more typedefs
* Add API tests for apply/remove coupon
* Jest tests
* Move default cart data to constant
* Comment indentation
* Create ShippingMethodsControl component
* Hook up shipping methods to API
* Add support for several packages
* Add tests to useShippingRates
* Fix shipping_rates property name
* Only show the products list if there are several packages
* Use <FormattedMonetaryAmount> to display shipping rate prices
* Make 'country' optional in CartShippingRates
* Make CartShippingRate API return currency info
* Minor improvements
* Fix shipping fields hidden in editor
* Fix missing currency in Checkout shipping rates selector
* Add links to issues in @todo comments
* Improve ShippingRatesControl useEffect
* Remove unnecessary tab
* Remove unnecessary id in RadioControl
* API: Add error when country is invalid
* Debounce shipping rates API requests
* 'Country key' -> 'Country code'
* Don't display radio input when there is only one option
* Add message when there are no results
* Minor enhacements
* Remove unnecessary Fragment
* Simplify RadioControlOption export
* Refactor 'renderOptions' and split it into several components
* Prevent Card sidebar from taking too much width
* Move country request check outside of the loop
* Fix failing test
* Audit atomic block labels
* Add summary, descrtiption, and short description to API and use for summary block
* Add summary to cart item api
* Respect short description
* Tweak label of summary block
* Revert product rating label
* One description vs 3
* Update sample content with more appropriate values, and match in cart items sample
* Move summary generation to class
* Tests
* Prevent extending `ProductSummary`
* Tweak $paragraph handling
* More accurate word counting
* add tear down for filter
* Add schema validation helper
* Add tests for cart item schema
* Fix schema errors found by tests
* Add tests and fix validation for remaining store API endpoints
* Tweak response for nested diffs
* Array syntax
* Improved nesting and type validation for schema
* Implement and fix type checking across test suite
* Type validation fixes
* Fix null comparison
* Fix array handling
* Switch to number type and support in validation
* Test the tests
* Update tests to use objects which match schema, avoiding JSON encode/decode
* Checkout/order WIP schema
* Add _address suffix for billing/shipping
* Rename schema, update endpoints, create tests
* Fix POST in test
* Fix test response checks
* Stock reservation and draft order status
* Add todo for shipping lines
* Readme
* Rename address fields in readme
* 10 min timeout of stock
* Fix broken test
* Update src/RestApi/StoreApi/Controllers/CartOrder.php
Co-Authored-By: Darren Ethier <darren@roughsmootheng.in>
* Add typehinting where possible
* Remove explicit pass by reference
* Further typehinting
* Clarify todo comment
* Validate product instances
* Specific phpcs exclusion rule
* Exclusion rule
* Move ReserveStock code to class
* Correct shipping-rates schema to shipping_rates
* Save shipping rates and lines if included with request
* Insert todo for shipping rate code
* Calculate shipping and selected shipping from order properties, not global cart properties
* Prevent error when shipping is not needed
* Update API readme
* Added tests for stock reserve class
* Fixes conflicts with draft statuses
Co-authored-by: Darren Ethier <darren@roughsmootheng.in>
* Add schema/GET endpoint
* Customer data updates + create tests
* Update docs
* Unused method
* Use ID from the customer object, rather than checking logged in user
* PHP 5.6 incompatibility
* Correct docblock
* Implement coupons endpoint with add/delete/get functionality
* Add totals
* Use money formatting
* Added tests for new endpoints
* Add coupons to main cart endpoint and update docs to match
* Fix indenting in readme
* is_a to instanceof
* Update coupon_exists logic
* Documentation/tidy class
* Update currency responses for coupon totals w/ tests
* Consistent currency data and formatting for product prices
* Consistent get_store_currency_properties usage
* Update tests with schema changes
* min_price and max_price to subunit format
* Product query of min and max prices using subunit
* Cart item totals
* Collection data schema object and currency data inclusion
* Handle subunits and new API in product prices
* Update price slider to format numbers using library and new API responses for subunits
* Product query of min and max prices using subunit
* Fix indents in readme
* Add todo for currency formatting
* Handle step for subunits, fixes min/max constraints
* Handle subunit conversion on display, using consistent currency object and wrapped NumberFormat component.
* Prettier ran
* Update usePriceConstraints tests so rounding doesn't make all values be 0
* Rename to minorUnitValue
* Move currencyToNumberFormat to index file
* siteCurrencySettings to constant rather than function
* remove cents term
* cents->minor unit
* typo in todo note
* Switch to FormattedMonetaryAmount
* Formatting
* wrong case
* Implement basic version of MoneyValue with decimal conversion
* Implement MoneyValue in cart classes
* Add minor unit to schema
* Update tests
* Add tests
* Tweak minor unit description
* Replace pow
* Dump rounding mode and use constant values
* Only return strings
* prepare_money_response method
* Update types back to string
* Remove unnecessary parentheses
* Feedback; force integer rounding mode to prevent notices
* add more pricing detail to cart line items api:
- total line price, before any coupon/discount
- saving, aka discount amount (if any)
- boolean if saving > 0
* add new cart price info properties to schema
* tidy field naming – line subtotal=pre discounts, line total=discounted
* remove saving / discount fields from API – could be calculated on client
* return numbers (not string) for price fields
* rename API field "price" to product price for clarity
* fix schema type for total fields (now float)
* Total descriptions in schema
* Format all costs as strings to follow core rest api
* Add totals to cart schema
* Update tests
* tax_lines
* Update Domain/Package so plugin file is not required, only a path.
* remove WC_BLOCKS_PLUGIN_FILE constant and add more inline docs
* Update tests
* Remove WC_BLOCKS_PLUGIN_FILE constant
* restore back-compat switch
* update woocommerce/components dependency to latest version
* fix bug in AssetDataRegistry and add tests to guard against regressions
* Add context for collection data query
* Introduce useCollectionData hook
* Implement hook in filter blocks
* Update API to handle nuances of counts instead of client side
* Clone requests so original is untouched
* Prevent dupe requests is working
* Cleanup
* Update assets/js/base/hooks/use-collection-data.js
Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com>
* Update assets/js/base/hooks/use-collection-data.js
Co-Authored-By: Albert Juhé Lluveras <aljullu@gmail.com>
* Feedback
* Remove context