Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PWA-240] [feature]: Cart Price Summary #2092

Merged
merged 21 commits into from
Jan 15, 2020
Merged

Conversation

sirugh
Copy link
Contributor

@sirugh sirugh commented Jan 9, 2020

Description

Adds a price summary to the cart page. Each of the more "complex" line items have been broken into separate components. To avoid having "magical" named queries being used in the parent I added a dependency called fraql that allows you to create unnamed queries. Look at priceSummary.js for usage example.

Image from Gyazo

Related Issue

Closes PWA-240.

Acceptance

Verification Stakeholders

Specification

Verification Steps

For reference, use the tutorial for checkout w/ graphQL.

Empty cart

Go to the /cart page. The summary should not appear when there are no items.

With items

  1. Add an item to your cart and obtain the cart id.
  2. Using graphql playground/postman/etc, apply a coupon (you may need to create a coupon for your storefront)
  3. Using graphql playground/postman/etc, set shipping address.
  4. Using graphql playground/postman/etc, set shipping method (using "flatrate"/"flatrate" for carrier/method)
  5. Refresh the /cart page. You should see an updated summary.

Image from Gyazo

Scrolling view

The summary should scroll with the contents of the cart page.

Note

  • Coupons values are represented in an array with other possible values and no way to identify it as such. For now, I have represented this as a "Discount" line item.

  • Gift Cards can be enabled/disabled at build time if we're on EE or not, but that work needs to be done. In this PR they are disabled entirely with a local flag but we should address that soon. Deferred the work to PWA-78 for now.

Checklist

  • I have updated the documentation accordingly, if necessary.
  • I have added tests to cover my changes, if necessary.

@PWAStudioBot
Copy link
Contributor

PWAStudioBot commented Jan 9, 2020

Messages
📖

Access a deployed version of this PR here. Make sure to wait for the "pwa-pull-request-deploy" job to complete.

📖 DangerCI Failures related to missing labels/description/linked issues/etc will persist until the next push or next nightly build run (assuming they are fixed).
📖

Associated JIRA tickets: PWA-240.

Generated by 🚫 dangerJS against 7b27b29

@sirugh sirugh added the version: Minor This changeset includes functionality added in a backwards compatible manner. label Jan 10, 2020
@sirugh sirugh force-pushed the rugh/price-summary branch 2 times, most recently from 3e71954 to f05a8c3 Compare January 10, 2020 15:56
@sirugh sirugh force-pushed the rugh/price-summary branch 2 times, most recently from 5adb2cc to d6a0984 Compare January 10, 2020 18:16
Signed-off-by: Stephen Rugh <[email protected]>
Signed-off-by: Stephen Rugh <[email protected]>
) : null;
};

// TODO: Gift cards are only enabled in EE, write a build time tool that turns the component into a no-op and the static fragments into __typename requests.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a big TODO. Before we merge this PR we have to have a way to determine which fragment to use, otherwise we risk breaking CE.

@sirugh sirugh marked this pull request as ready for review January 10, 2020 20:27
DiscountSummary.fragments = {
discounts: gql`
fragment _ on CartPrices {
discounts {
Copy link
Contributor Author

@sirugh sirugh Jan 10, 2020

Choose a reason for hiding this comment

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

In 2.3.3 we have discount, which is a "deprecated but functional" field in 2.3.4
In 2.3.4 we have discounts, which 2.3.3 does not have.

If we want to support both versions we will need to provide some way (build or runtime?) to determine which field is valid for the current backend.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am going to proceed with the assumption that we don't need to support 2.3.3, so discounts is valid.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am going to proceed with the assumption that we don't need to support 2.3.3, so discounts is valid.

We do need to support 2.3.3.

variables: {
cartId
},
fetchPolicy: 'no-cache'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should verify that actions that modify the price summary values such as shipping method or adding a shipping address elsewhere also update the price summary even if no-cache is used here.

@revanth0212 revanth0212 changed the title [feature]: Cart Price Summary [PWA-240] [feature]: Cart Price Summary Jan 14, 2020
revanth0212
revanth0212 previously approved these changes Jan 14, 2020
Copy link
Contributor

@jimbo jimbo left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'd like to know what effect fraql has on the bundle before approving this; I'm fine with it from a fragment authoring perspective.

Also note that we do have to support 2.3.3.

DiscountSummary.fragments = {
discounts: gql`
fragment _ on CartPrices {
discounts {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am going to proceed with the assumption that we don't need to support 2.3.3, so discounts is valid.

We do need to support 2.3.3.

@sirugh
Copy link
Contributor Author

sirugh commented Jan 15, 2020

Looks good to me. I'd like to know what effect fraql has on the bundle before approving this; I'm fine with it from a fragment authoring perspective.

I have removed it and used named exports instead. This just leaves a little coupling magic in terms of fragment name and the name of the export but that's not a big deal, and is preferable over using a new dependency IMO.

Also note that we do have to support 2.3.3.

Rather than go back and forth on this, let's put that in documentation somewhere and make sure the entire team knows exactly what backend version we have to support when we are coding. I spoke with @tjwiebell and we both thought that this code wouldn't be released until our next release which would coincide with 2.3.5. And we both thought that we were supporting "current - 1", so 6.0.0 would have to support 2.3.5 and 2.3.4 whereas 5.0.0 which is releasing now will have to support 2.3.4 and 2.3.3

In regards to this specific PR, I can work around that by using the discount field which is deprecated in 2.3.4 but still exists. I just worry that we're going to run into complete removal of fields that we have to support since GQL doesn't really do semver "the right way".

@jimbo
Copy link
Contributor

jimbo commented Jan 15, 2020

Yes, my mistake. This can be for 2.3.4, so we're good here. 👍

Signed-off-by: Stephen Rugh <[email protected]>
jimbo
jimbo previously approved these changes Jan 15, 2020
@dpatil-magento
Copy link
Contributor

QA Pass, can be merged once re-approved.

@dpatil-magento dpatil-magento merged commit a4a67ba into develop Jan 15, 2020
@dpatil-magento dpatil-magento deleted the rugh/price-summary branch January 15, 2020 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:peregrine pkg:venia-ui version: Minor This changeset includes functionality added in a backwards compatible manner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants