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

Free Listings + Paid Ads: Update product feed API to return the bestselling product #1681

Conversation

ianlin
Copy link
Member

@ianlin ianlin commented Sep 20, 2022

Changes proposed in this Pull Request:

This PR implements the backend task 4 📌 Return merchants key product data (e.g. bestselling) from the epic issue #1610. Here are what have changed:

  • Extend an existing API mc/product-feed by adding a new condition total_sales to the parameter orderby.
    • total_sales is one of the meta keys of a product.
    • Combining with other parameters we can get the product which has the most sales. E.g.
      • GET mc/product-feed?per_page=1&orderby=total_sales&order=desc
  • Extend an existing API mc/product-feed to return price and image url of a product.
  • Add siteLogoUrl to glaData for the frontend.

Detailed test instructions:

  1. Make a GET request to mc/product-feed API with parameters:
    • per_page=1
    • orderby=total_sales
    • order=desc
    • Full example: GET mc/product-feed?per_page=1&orderby=total_sales&order=desc
  2. The response should contain only one product, with new response data price and image_url.
  3. To verify if the returned product has the most sales, use this query in your local database:
    • SELECT * FROM wp_postmeta WHERE meta_key = 'total_sales' ORDER BY CAST( meta_value AS unsigned ) DESC;
  4. Go to GLA dashboard, open the dev tool console, and type window.glaData
    • You should see there is a new data siteLogoUrl.
    • It would be null if you did not upload a custom site logo.
  5. If the siteLogoUrl is null, go to wp-admin/admin.php?page=wc-admin&task=appearance and upload a logo.
  6. Open the dev tool console and type window.glaData again, you should see the value of siteLogoUrl.

Changelog entry

@ianlin ianlin added php Pull requests that update Php code changelog: none Skip changelog entry for this PR labels Sep 20, 2022
@ianlin ianlin requested a review from a team September 20, 2022 05:30
@github-actions github-actions bot added the changelog: update Big changes to something that wasn't broken. label Sep 20, 2022
@eason9487 eason9487 requested review from a team and removed request for a team September 20, 2022 10:01
@eason9487 eason9487 changed the title Update product feed API to return the bestselling product Free Listings + Paid Ads: Update product feed API to return the bestselling product Sep 20, 2022
Copy link
Contributor

@mikkamp mikkamp 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 changes, I'm getting the response as expected.

{
	"products": [
		{
			"id": 1695,
			"title": "Incredible Steel Coat",
			"visible": true,
			"status": "not_synced",
			"errors": []
		}
	],
	"total": 316,
	"page": 1
}

Just double checking if the product status makes a difference? In my case it picks a product that's not synced (excluded).

I just left a few smaller comments but they aren't blocking so I'll go ahead and approve the PR.

case 'total_sales':
$args['meta_key'] = ProductMetaHandler::KEY_TOTAL_SALES;
$args['orderby'] = [ 'meta_value_num' => $this->get_order() ] + $args['orderby'];
break;
default:
throw InvalidValue::not_in_allowed_list( 'orderby', [ 'title', 'id', 'visible', 'status' ] );
Copy link
Contributor

Choose a reason for hiding this comment

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

We should add total_sales as that's an allowed value.

@@ -165,6 +167,10 @@ protected function prepare_query_args(): array {
$args['meta_key'] = $this->prefix_meta_key( ProductMetaHandler::KEY_MC_STATUS );
$args['orderby'] = [ 'meta_value' => $this->get_order() ] + $args['orderby'];
break;
case 'total_sales':
$args['meta_key'] = ProductMetaHandler::KEY_TOTAL_SALES;
Copy link
Contributor

Choose a reason for hiding this comment

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

I personally think we should just use a constant string of total_sales here. I don't think it really fits within the ProductMetaHandler class as that's to manage product meta fields we add for the extension, also it means we can call update/get/delete for this field, but it won't target the right entry because it will be adding the prefix. So it can be removed from the ProductMetaHandler class.

@ianlin
Copy link
Member Author

ianlin commented Sep 21, 2022

@mikkamp

Just double checking if the product status makes a difference? In my case it picks a product that's not synced (excluded).

I think for most new users when they reach that step of the onboarding flow their products haven't been synced to GMC, so filtering only for synced products might have some problems.

@ianlin ianlin force-pushed the update/1610-order-by-total-sales-in-product-feed-api branch from f45ab12 to 7e3caaf Compare September 21, 2022 11:59
@ianlin ianlin changed the base branch from update/1610-add-api-to-get-sync-ready-products to feature/1610-streamlined-onboarding September 21, 2022 12:00
@ianlin
Copy link
Member Author

ianlin commented Sep 21, 2022

The original base branch this PR was trying to merge into was update/1610-add-api-to-get-sync-ready-products. However due to PR #1667 will be closed so I changed the base branch to feature/1610-streamlined-onboarding.

@ianlin ianlin merged commit 046f8fe into feature/1610-streamlined-onboarding Sep 21, 2022
@ianlin ianlin deleted the update/1610-order-by-total-sales-in-product-feed-api branch September 21, 2022 12:06
@eason9487 eason9487 removed the changelog: none Skip changelog entry for this PR label Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: update Big changes to something that wasn't broken. php Pull requests that update Php code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants