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

Vdimitrakis/add price in posts endpoint #35066

Merged
merged 20 commits into from
Feb 19, 2024

Conversation

therocket-gr
Copy link
Contributor

@therocket-gr therocket-gr commented Jan 16, 2024

We need to expose the WooCommerce price in the blaze dashboard list (in Advertising - or in the new Marketing page)

This change will check if the wc_get_product method is available and will call for each of the items/posts, it will retrieve the price of each post (if a product) and will inject it in the final results.

This will only work for self-hosted or pressable sites.

Fixes #

Proposed changes:

Other information:

  • Have you written new tests for your changes, if applicable?
  • Have you checked the E2E test CI results, and verified that your changes do not break them?
  • Have you tested your changes on WordPress.com, if applicable (if so, you'll see a generated comment below with a script to run)?

Jetpack product discussion

Does this pull request change what data or activity we track or use?

Testing instructions:

You need to have Woo installed in your testing site and to have (at least) a product created.
Navigate to the advertising page and check your network inspect tab. Filter requests by /blaze/posts
In the request result, you should see the price data when the post is a product.

Screenshot 2024-01-17 at 17 01 50

Then click on the Promote button (on the top right corner of your page). Click continue to load all posts again and check the network for the same call.

you should see the price entry in the posts/results array

posts that are not of product type should have the property but with an empty value (empty string)

  • Go to '..'

Copy link
Contributor

github-actions bot commented Jan 16, 2024

Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.

  • To test on WoA, go to the Plugins menu on a WordPress.com Simple site. Click on the "Upload" button and follow the upgrade flow to be able to upload, install, and activate the Jetpack Beta plugin. Once the plugin is active, go to Jetpack > Jetpack Beta, select your plugin, and enable the vdimitrakis/add-price-in-posts-endpoint branch.

  • To test on Simple, run the following command on your sandbox:

    bin/jetpack-downloader test jetpack vdimitrakis/add-price-in-posts-endpoint
    

Interested in more tips and information?

  • In your local development environment, use the jetpack rsync command to sync your changes to a WoA dev blog.
  • Read more about our development workflow here: PCYsg-eg0-p2
  • Figure out when your changes will be shipped to customers here: PCYsg-eg5-p2

Copy link
Contributor

github-actions bot commented Jan 16, 2024

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.
  • ✅ Add changelog entries to affected projects

This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖


The e2e test report can be found here. Please note that it can take a few minutes after the e2e tests checks are complete for the report to be available.


Once your PR is ready for review, check one last time that all required checks appearing at the bottom of this PR are passing or skipped.
Then, add the "[Status] Needs Team Review" label and ask someone from your team review the code. Once reviewed, it can then be merged.
If you need an extra review from someone familiar with the codebase, you can update the labels from "[Status] Needs Team Review" to "[Status] Needs Review", and in that case Jetpack Approvers will do a final review of your PR.


Jetpack plugin:

The Jetpack plugin has different release cadences depending on the platform:

  • WordPress.com Simple releases happen daily.
  • WoA releases happen weekly.
  • Releases to self-hosted sites happen monthly. The next release is scheduled for March 5, 2024 (scheduled code freeze on March 4, 2024).

If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack.

@therocket-gr therocket-gr added the [Status] Needs Review To request a review from Crew. Label will be renamed soon. label Jan 16, 2024
@therocket-gr therocket-gr marked this pull request as ready for review January 16, 2024 16:48
@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Jan 16, 2024
Copy link
Contributor

@sbarbosa sbarbosa left a comment

Choose a reason for hiding this comment

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

Hi @therocket-gr!
I checked the response and I am getting some scaped HTML code on it. I would be nice if we can clean that up. Just to be more compatible with other clients like Mobile apps.

Screenshot 2024-01-16 at 14 31 50

We are already cleaning up all HTML tags, maybe we can also run html_entity_decode to decode the rest of the code. That function should convert $  to the correct $

sbarbosa
sbarbosa previously approved these changes Jan 17, 2024
Copy link
Contributor

@sbarbosa sbarbosa left a comment

Choose a reason for hiding this comment

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

Thanks for the change Vassilis!
I made a couple of changes to the dashboard to display the new price, and the changes in the endpoint are working great

Screenshot 2024-01-17 at 14 02 26

Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This makes sense. I only have a minor question, and I believe this will need a rebase.

Comment on lines 677 to 682
$posts[ $key ]['price'] = html_entity_decode(
wp_strip_all_tags(
wc_price( $product->get_price() )
),
ENT_QUOTES
);
Copy link
Member

Choose a reason for hiding this comment

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

I take it there is no simple function to retrieve a formatted and escaped product price?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeherve sorry for the delay in responding... we were in a division meetup.

i did some research and asked around, I changed the code (even though it is more lines of code) i think it is better to not use entity_decode and strip tags

@sbarbosa please let me know what you think as well

@jeherve jeherve added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! [Pri] Normal and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Jan 29, 2024
@therocket-gr therocket-gr force-pushed the vdimitrakis/add-price-in-posts-endpoint branch from a032d70 to b375a5d Compare February 1, 2024 16:44
PanosSynetos
PanosSynetos previously approved these changes Feb 13, 2024
Copy link
Contributor

@PanosSynetos PanosSynetos left a comment

Choose a reason for hiding this comment

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

Hey @therocket-gr - As we discussed over DMs, you followed the same approach as what wc_price is doing.

I like the defensive coding, maybe you're overdoing it with checking all the functions, but better safe than sorry :)

Pre-approving this in order not to block you, my comments are minor

FYI - didn't actually tested the endpoint, I just reviewed the PHP side of getting the prices

sbarbosa
sbarbosa previously approved these changes Feb 15, 2024
Copy link
Contributor

@sbarbosa sbarbosa left a comment

Choose a reason for hiding this comment

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

I re-tested the changes and they are working fine 👍

Screenshot 2024-02-15 at 10 39 17
Screenshot 2024-02-15 at 10 39 24

@therocket-gr
Copy link
Contributor Author

@jeherve i think we are good to go!! I refactored a bit the code on how the price is fetched. I would appreciate your thoughts and if you think we are ok i will merge this one. Thanks in advance

@therocket-gr therocket-gr removed the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 16, 2024
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This tests well for me. I only have one small remark to ensure compatibility with other Woo extensions.

continue;
}
$product = wc_get_product( $item['ID'] );
if ( $product ) {
Copy link
Member

Choose a reason for hiding this comment

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

You may have to be more defensive here, just like in #35566, to avoid fatals in some scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeherve check out this comment by Panos

#35066 (comment)

i think we should be ok

Copy link
Member

Choose a reason for hiding this comment

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

I'm afraid that's not going to be enough. In some scenarios, Woo extensions may change what's returned there. That's something we ran into a few times in the past, and why we ended up checking for $product instanceof WC_Product in the PR I linked to earlier. Also see #11301 for another example.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok fixed, added the extra condition

Copy link
Contributor

Choose a reason for hiding this comment

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

Being extra defensive doesn't hurt :)

@jeherve jeherve added the [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! label Feb 16, 2024
Copy link
Contributor

@PanosSynetos PanosSynetos left a comment

Choose a reason for hiding this comment

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

Code reviewed - being extra defensive is good!

@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Feb 19, 2024
@therocket-gr
Copy link
Contributor Author

Thank you both @PanosSynetos and @jeherve for reviewing and approving it...

@therocket-gr therocket-gr merged commit ce56219 into trunk Feb 19, 2024
55 checks passed
@therocket-gr therocket-gr deleted the vdimitrakis/add-price-in-posts-endpoint branch February 19, 2024 12:51
@github-actions github-actions bot added this to the jetpack/13.2 milestone Feb 19, 2024
@github-actions github-actions bot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Blaze [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ [Pri] Normal [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants