Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Expose discount_type in Store API coupon endpoints #3399

Merged
merged 3 commits into from Nov 15, 2020

Conversation

haszari
Copy link
Member

@haszari haszari commented Nov 13, 2020

Fixes #3274

Screenshots

Example after POSTing two coupons in cart, POST /wc/store/cart/apply-coupon

Screen Shot 2020-11-13 at 2 26 13 PM

How to test the changes in this Pull Request:

  1. Test cart & checkout with & without various coupons. Check network requests inspector in dev tools and confirm coupon type is present and correct.

Changelog

Store API: Add discount_type field to coupon-related requests.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 13, 2020

Size Change: 0 B

Total Size: 1.12 MB

ℹ️ View Unchanged
Filename Size Change
build/active-filters-frontend.js 8.88 kB 0 B
build/active-filters.js 8.94 kB 0 B
build/all-products-frontend.js 31.2 kB 0 B
build/all-products.js 36.1 kB 0 B
build/all-reviews.js 9.78 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/button.js 3.19 kB 0 B
build/atomic-block-components/add-to-cart--atomic-block-components/image--atomic-block-components/title.js 335 B 0 B
build/atomic-block-components/add-to-cart-frontend.js 8.94 kB 0 B
build/atomic-block-components/add-to-cart.js 7.52 kB 0 B
build/atomic-block-components/button-frontend.js 2.02 kB 0 B
build/atomic-block-components/button.js 840 B 0 B
build/atomic-block-components/category-list-frontend.js 469 B 0 B
build/atomic-block-components/category-list.js 478 B 0 B
build/atomic-block-components/image-frontend.js 1.7 kB 0 B
build/atomic-block-components/image.js 1.15 kB 0 B
build/atomic-block-components/price-frontend.js 2.29 kB 0 B
build/atomic-block-components/price.js 2.32 kB 0 B
build/atomic-block-components/rating-frontend.js 524 B 0 B
build/atomic-block-components/rating.js 526 B 0 B
build/atomic-block-components/sale-badge-frontend.js 857 B 0 B
build/atomic-block-components/sale-badge.js 863 B 0 B
build/atomic-block-components/sku-frontend.js 386 B 0 B
build/atomic-block-components/sku.js 395 B 0 B
build/atomic-block-components/stock-indicator-frontend.js 568 B 0 B
build/atomic-block-components/stock-indicator.js 573 B 0 B
build/atomic-block-components/summary-frontend.js 917 B 0 B
build/atomic-block-components/summary.js 927 B 0 B
build/atomic-block-components/tag-list-frontend.js 467 B 0 B
build/atomic-block-components/tag-list.js 474 B 0 B
build/atomic-block-components/title-frontend.js 1.23 kB 0 B
build/atomic-block-components/title.js 1.06 kB 0 B
build/attribute-filter-frontend.js 18.3 kB 0 B
build/attribute-filter.js 12.5 kB 0 B
build/blocks.js 3.54 kB 0 B
build/cart-frontend.js 70.1 kB 0 B
build/cart.js 38.8 kB 0 B
build/checkout-frontend.js 85.9 kB 0 B
build/checkout.js 42.1 kB 0 B
build/editor-rtl.css 13.8 kB 0 B
build/editor.css 13.9 kB 0 B
build/featured-category.js 7.73 kB 0 B
build/featured-product.js 9.97 kB 0 B
build/handpicked-products.js 7.37 kB 0 B
build/price-filter-frontend.js 14.9 kB 0 B
build/price-filter.js 10.4 kB 0 B
build/product-best-sellers.js 7.45 kB 0 B
build/product-categories.js 3.23 kB 0 B
build/product-category.js 8.38 kB 0 B
build/product-new.js 7.61 kB 0 B
build/product-on-sale.js 8 kB 0 B
build/product-search.js 3.56 kB 0 B
build/product-tag.js 6.53 kB 0 B
build/product-top-rated.js 7.58 kB 0 B
build/products-by-attribute.js 8.35 kB 0 B
build/reviews-by-category.js 11.8 kB 0 B
build/reviews-by-product.js 13.4 kB 0 B
build/reviews-frontend.js 9.37 kB 0 B
build/single-product-frontend.js 33.8 kB 0 B
build/single-product.js 10.1 kB 0 B
build/style-rtl.css 17.9 kB 0 B
build/style.css 17.9 kB 0 B
build/vendors--atomic-block-components/price-frontend.js 5.65 kB 0 B
build/vendors-style-rtl.css 1.03 kB 0 B
build/vendors-style.css 1.03 kB 0 B
build/vendors.js 417 kB 0 B
build/wc-blocks-data.js 7.1 kB 0 B
build/wc-blocks-middleware.js 931 B 0 B
build/wc-blocks-registry.js 2.32 kB 0 B
build/wc-payment-method-bacs.js 790 B 0 B
build/wc-payment-method-cheque.js 787 B 0 B
build/wc-payment-method-cod.js 879 B 0 B
build/wc-payment-method-paypal.js 831 B 0 B
build/wc-payment-method-stripe.js 12 kB 0 B
build/wc-settings.js 2.35 kB 0 B
build/wc-shared-context.js 1.53 kB 0 B
build/wc-shared-hocs.js 1.66 kB 0 B

compressed-size-action

@haszari
Copy link
Member Author

haszari commented Nov 13, 2020

@mikejolley I see in the schema for coupons that most fields have 'context' => [ 'view', 'edit' ]. Does this mean that the schema allows POST (edit, write, mutate) of these fields?

For coupons, I'm thinking the only one that we allow POST for is the coupon ID. The rest (coupon type, discount etc) are all read-only. Should we change the schema to view only?

Or ... am I completely misunderstanding the meaning of context param 😸

@haszari haszari marked this pull request as ready for review November 13, 2020 01:47
@haszari haszari requested a review from a team as a code owner November 13, 2020 01:47
@haszari haszari requested review from senadir and removed request for a team November 13, 2020 01:47
@senadir
Copy link
Member

senadir commented Nov 13, 2020

Context means the place this request is going to be consumed in, and it would return extra fields depending on that.
In our case, it means we're going to return this field when viewing content (storefront) and when editing content (editor, backend).
Different context requires certain authentications.
Your misunderstanding is a common one, you can see an extended explanation here.

Copy link
Member

@senadir senadir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this and it works fine, it exposed WCS coupons types just fine, and the data is passed in useStoreCartCoupons and useStoreCart so no extra handling is required there.

@@ -8,6 +8,7 @@
*
* @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions.
* @since 2.5.0
* @since $VID:$ Coupon type (`discount_type`) added.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This API is not public yet so I don't think we need this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it's not public I still think it's useful to track when fields are added or schema changed – doesn't hurt right?

@haszari haszari self-assigned this Nov 15, 2020
@haszari haszari added this to the 3.9.0 milestone Nov 15, 2020
@haszari haszari merged commit 9fdb7ac into trunk Nov 15, 2020
@haszari haszari deleted the add/store-api-coupon-discount-type branch November 15, 2020 21:30
@nerrad nerrad added focus: rest api Work impacting REST api routes. type: enhancement The issue is a request for an enhancement. labels Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
focus: rest api Work impacting REST api routes. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration Tracking (WC Subscriptions): Add coupon type to coupons endpoint
3 participants