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

Checkout: Display introductory offer intervals in the cart line items #50494

Merged
merged 7 commits into from
Mar 17, 2021

Conversation

danielmx-dev
Copy link

@danielmx-dev danielmx-dev commented Feb 25, 2021

Changes proposed in this Pull Request

  • Display the introductory offer discount/free trial intervals (only yearly and monthly intervals contain specific language) as discount callouts in the line items.
    image

Testing instructions

  • Follow the same steps described in the test plan of D58043-code to enable an introductory offer for your user.
  • When you arrive to the checkout, a discount callout should be displayed in the shopping cart line item like the one in the screenshot above.

@matticbot
Copy link
Contributor

}
if ( intervalUnit === 'year' ) {
if ( intervalCount === 1 ) {
text = translate( 'Free for first year' );
Copy link

Choose a reason for hiding this comment

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

ℹ️ String reuse speeds up translation and improves consistency. The following string might make a good alternative and has already been translated 23 times:
translate( 'First year free' ) ES Score: 6

@matticbot
Copy link
Contributor

matticbot commented Feb 25, 2021

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~198 bytes added 📈 [gzipped])

name      parsed_size           gzip_size
checkout       +903 B  (+0.1%)     +198 B  (+0.1%)

Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to.

Async-loaded Components (~194 bytes added 📈 [gzipped])

name                                             parsed_size           gzip_size
async-load-calypso-blocks-editor-checkout-modal       +903 B  (+0.1%)     +194 B  (+0.1%)

React components that are loaded lazily, when a certain part of UI is displayed for the first time.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@danielmx-dev danielmx-dev self-assigned this Feb 25, 2021
@danielmx-dev danielmx-dev added the [Feature] Checkout The checkout screen and process for purchases made on WordPress.com. label Feb 25, 2021
@danielmx-dev danielmx-dev changed the title [WIP] Display introductory offer intervals in the cart line items [WIP] Checkout: Display introductory offer intervals in the cart line items Feb 25, 2021
@danielmx-dev danielmx-dev requested a review from a team February 26, 2021 21:29
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 26, 2021
@danielmx-dev danielmx-dev added [Status] In Progress and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Feb 26, 2021
@danielmx-dev danielmx-dev changed the title [WIP] Checkout: Display introductory offer intervals in the cart line items Checkout: Display introductory offer intervals in the cart line items Mar 16, 2021
@danielmx-dev danielmx-dev marked this pull request as ready for review March 16, 2021 17:33
@danielmx-dev danielmx-dev requested a review from a team as a code owner March 16, 2021 17:33
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Mar 16, 2021
@danielmx-dev danielmx-dev force-pushed the update/add-introductory-offers-support-to-cart branch from a2aa5c6 to 619587b Compare March 16, 2021 17:35
@danielmx-dev danielmx-dev requested a review from a team March 16, 2021 18:35
@danielmx-dev danielmx-dev force-pushed the update/add-introductory-offers-support-to-cart branch from d303cc0 to 9b6310e Compare March 16, 2021 18:37
Comment on lines +465 to +467
if ( ! isRenewalItem && serverCartItem.months_per_bill_period === 1 ) {
return translate( 'Monthly subscription' );
}
Copy link
Author

Choose a reason for hiding this comment

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

Without this then all the components dependent on the existing of a sublabel won't be rendered (including the discount callouts). This also is helpful to highlight a monthly subscription since our usual billing intervals are annual.

return translate( 'Renewal' );
}

return '';
Copy link
Author

Choose a reason for hiding this comment

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

I thought it would be better to separate the default case.

Copy link
Member

@sirbrillig sirbrillig left a comment

Choose a reason for hiding this comment

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

This looks good to me! I left one small suggestion but it's minor.

I didn't test with the backend patch but I hacked the front-end to add introductory_offer_terms to a product and saw the display as expected.

Screen Shot 2021-03-16 at 4 20 32 PM

const intervalUnit = product.introductory_offer_terms.interval_unit;
const intervalCount = product.introductory_offer_terms.interval_count;

if ( product.cost === 0 ) {
Copy link
Member

Choose a reason for hiding this comment

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

It might not matter for the case of 0, but in general it might be safer to use product_cost_integer instead of cost, because it will be an integer in the currency's smallest unit rather than a float in a larger unit. For example, the cost might be 95.25 but the product_cost_integer would be 9525. (This is true of all the ..._integer prices in the cart; I'd like to deprecate the old properties that use floats.)

Copy link
Author

Choose a reason for hiding this comment

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

I used item_subtotal_integer instead of cost, I noticed it is used in other places as well to determine free line items. Thanks for the suggestion!

@danielmx-dev danielmx-dev added [Status] Ready to Merge and removed [Status] In Progress [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Mar 16, 2021
Copy link
Contributor

@daledupreez daledupreez left a comment

Choose a reason for hiding this comment

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

Overall the wording looks good to me.

product: ResponseCartProduct;
} ): JSX.Element | null {
const translate = useTranslate();
let text = String( translate( 'Discount for first period' ) );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we can define text after the exit condition on the next line. Same probably applies to setting translate.

Copy link
Author

Choose a reason for hiding this comment

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

I think I could move the variable but I'm not sure about the translate assignment. I think it's a good practice to always define the hooks at the top, unaffected by conditional statements.


if ( product.item_subtotal_integer === 0 ) {
if ( intervalUnit === 'month' ) {
if ( intervalCount === 1 ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this use the three-argument form of translate()? The same applies to all the locations below.

Suggested change
if ( intervalCount === 1 ) {
text = translate(
'First month free',
'First %(numberOfMonths)s months free',
{
args: {
numberOfMonths: intervalCount,
},
count: intervalCount,
}
);

Copy link
Author

Choose a reason for hiding this comment

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

I did that at first but I got a warning telling me that I had to use the placeholders in both strings, that's why I ended up separating them using an if.

image

@danielmx-dev danielmx-dev merged commit 4761004 into trunk Mar 17, 2021
@danielmx-dev danielmx-dev deleted the update/add-introductory-offers-support-to-cart branch March 17, 2021 17:10
@a8ci18n
Copy link

a8ci18n commented Mar 17, 2021

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/5587988

Thank you @dylanrevisited for including a screenshot in the description! This is really helpful for our translators.

@a8ci18n
Copy link

a8ci18n commented Mar 24, 2021

Translation for this Pull Request has now been finished.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Checkout The checkout screen and process for purchases made on WordPress.com.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants