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

Add shipping partner suggestions api #37155

Merged
merged 12 commits into from Mar 20, 2023

Conversation

moon0326
Copy link
Contributor

@moon0326 moon0326 commented Mar 9, 2023

All Submissions:

Changes proposed in this Pull Request:

Closes #36281

This PR adds /wp-json/wp-admin/shipping-partner-suggestions. The endpoint is designed to be used with the shipping cost task.

Default shipping list test

When woocommerce_show_marketplace_suggestions option is set to no, the endpoint should use the default shipping partner list

  1. Make sure _transient_woocommerce_admin_shipping_partner_suggestions_specs optoin does not exist.
  2. Set woocommerce_show_marketplace_suggestions option to no
  3. Acces /wp-json/wp-admin/shipping-partner-suggestions
  4. Confirm the endpoint returns a valid JSON.
  5. Confirm _transient_woocommerce_admin_shipping_partner_suggestions_specs option still does not exist.

Getting the list from WCCOM

  1. Setup your local WCCOM env with https://github.com/Automattic/woocommerce.com/pull/16291 branch.

  2. Open this file and change the DATA_SOURCES to your local WCCOM.

  3. Make sure woocommerce_show_marketplace_suggestions is set to yes

  4. Make sure _transient_woocommerce_admin_shipping_partner_suggestions_specs does not exist.

  5. Acces /wp-json/wp-admin/shipping-partner-suggestions

  6. Confirm the endpoint returns a valid JSON

  7. Confirm _transient_woocommerce_admin_shipping_partner_suggestions_specs exists.

*Depending on your local setup, you might need to set WP_PROXY_HOST to access your local WCCOM env from your WooCommerce dev.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you created a changelog file for each project being changed, ie pnpm --filter=<project> changelog add?
  • Have you included testing instructions?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@moon0326 moon0326 requested review from a team, adrianduffell and rjchow March 9, 2023 22:02
@github-actions github-actions bot added focus: react admin [team:Ghidorah] plugin: woocommerce Issues related to the WooCommerce Core plugin. labels Mar 9, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2023

Test Results Summary

Commit SHA: 9ff33fe

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests25900202611m 5s
E2E Tests1910010020114m 27s

To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Merging #37155 (9ff33fe) into trunk (be43265) will decrease coverage by 0.0%.
The diff coverage is 27.5%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             trunk   #37155     +/-   ##
==========================================
- Coverage     46.7%    46.7%   -0.0%     
- Complexity   17183    17197     +14     
==========================================
  Files          429      429             
  Lines        64799    64893     +94     
==========================================
+ Hits         30251    30287     +36     
- Misses       34548    34606     +58     
Impacted Files Coverage Δ
...mmerce/includes/admin/class-wc-admin-importers.php 0.0% <0.0%> (ø)
...rters/class-wc-product-csv-importer-controller.php 36.1% <28.6%> (ø)
.../includes/import/class-wc-product-csv-importer.php 75.1% <44.4%> (+0.2%) ⬆️
...e/includes/import/abstract-wc-product-importer.php 63.7% <100.0%> (ø)

... and 16 files with indirect coverage changes

Copy link
Member

@chihsuan chihsuan 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 working on it! @moon0326

I just left some comments and I think we should replace DefaultPaymentGateways with DefaultShippingPartners.

'is_visible' => array(
self::get_rules_for_countries( array( 'MX', 'CO' ) ),
),
'available_layouts' => array( 'single' ),
Copy link
Member

Choose a reason for hiding this comment

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

Should it be "row" layout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chihsuan Thank you for catching it 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated in 302ffe0

'args' => array(
'force_default_suggestions' => array(
'type' => 'boolean',
'description' => __( 'Return the default shipping partner suggestions when woocommerce_show_shipping_partner_suggestions and woocommerce_setting_payments_recommendations_hidden options are set to no', 'woocommerce' ),
Copy link
Member

Choose a reason for hiding this comment

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

Do you know where we set woocommerce_show_shipping_partner_suggestions options? And I guess we don't need woocommerce_setting_payments_recommendations_hidden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That description needs an update 😄 It only works when woocommerce_show_marketplace_suggestions is set to false and force_default_suggestions is set to true

Code is here: https://github.com/woocommerce/woocommerce/pull/37155/files#diff-d0513d5e143fc2d4484715f024daa474107356bc224e4fa6e20bea70c04c03fdR97

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chihsuan Updated in 6625537 🙏

'type' => 'array',
'items' => array(
'type' => 'string',
'enum' => array( 'row', 'column' ),
Copy link
Contributor Author

@moon0326 moon0326 Mar 13, 2023

Choose a reason for hiding this comment

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

FYI, I borrowed row and column concept from CSS flex-direction.

Layout row represents a smaller banner (?) that can be placed with other smaller banners in a single row.
Layout column represents a banner that takes the whole row width.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think i'd go with 'narrow' and 'wide' but no objections to this way either 😀

),
'is_visible' => array(
'description' => __( 'Suggestion visibility.', 'woocommerce' ),
'type' => 'boolean',
Copy link
Member

Choose a reason for hiding this comment

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

@moon0326 I just noticed that is_visible is not a boolean value in the API response. Should we change it to boolean?

Screenshot 2023-03-14 at 09 53 21

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch!

It should be set to boolean after rule evaluation. Updated in 88bf071

@chihsuan
Copy link
Member

BTW, looks like PHP linting is failing (also WCCOM side).

chihsuan
chihsuan previously approved these changes Mar 16, 2023
Copy link
Member

@chihsuan chihsuan left a comment

Choose a reason for hiding this comment

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

Nice work! Looks good to me and tested well. 💯

* @return array Default specs.
*/
public static function get_all() {
$asset_base_url = WC()->plugin_url() . 'assets/images/shipping_partners/';
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there's a missing slash between woocommerce and assets in the path - I get a 404 with the URL that's generated but its found if i add the slash
image

rjchow
rjchow previously approved these changes Mar 17, 2023
Copy link
Contributor

@rjchow rjchow left a comment

Choose a reason for hiding this comment

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

Left two comments but lgtm overall, thanks! We can iterate on this with the UI work next 😄

@moon0326 moon0326 dismissed stale reviews from rjchow and chihsuan via 3d43434 March 20, 2023 04:14
Copy link
Member

@chihsuan chihsuan 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!

@moon0326 moon0326 merged commit 1aa899a into trunk Mar 20, 2023
18 of 20 checks passed
@moon0326 moon0326 deleted the add/36281-shipping-partners-suggestion-api branch March 20, 2023 05:37
@github-actions github-actions bot added this to the 7.6.0 milestone Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: woocommerce Issues related to the WooCommerce Core plugin.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add remote endpoint API support for shipping partners in shipping task
3 participants