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

Fix - Sync product GTIN when available #2810

Merged
merged 2 commits into from
Dec 5, 2024

Conversation

mshymon
Copy link
Contributor

@mshymon mshymon commented Oct 3, 2024

Changes proposed in this Pull Request:

This change suggests to sync to Meta a product GTIN when it is available.

Screenshots:

N/A (no changes to UI/UX)

Detailed test instructions:

  1. Run new tests
    ./vendor/bin/phpunit --filter test_gtin_for_simple_product_set
    ./vendor/bin/phpunit --filter test_gtin_for_simple_product_unset
    ./vendor/bin/phpunit --filter test_gtin_for_variable_product_set
    ./vendor/bin/phpunit --filter test_gtin_for_variable_product_unset

  2. Run all tests
    npm run test:php

  3. Manual testing. I tested this in the locally hosted WP WooCommerce website and checked logs on Meta side to verify the request is being sent with the "gtin" populated correctly. Tested on both simple and variable product.

Changelog entry

Fix - Sync product GTIN when available.

@rawdreeg rawdreeg requested a review from a team November 4, 2024 12:15
Copy link
Contributor

@rawdreeg rawdreeg left a comment

Choose a reason for hiding this comment

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

Hello @mshymon,

Thanks for you contribution. I left a couple of comment for your your consideration. Let me know if you have questions

@@ -720,6 +720,11 @@ public function prepare_product( $retailer_id = null, $type_to_prepare_for = sel
$product_data['quantity_to_sell_on_facebook'] = (int) max( 0, $this->woo_product->get_stock_quantity() );
}

// Add GTIN (Global Trade Item Number)
if ( $gtin = $this->woo_product->get_global_unique_id() ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

2 Issues I see here:

  1. get_global_unique_id has only been available since WooCommerce version 9.2, we should check this before calling this method (Add unique_id field to product woocommerce/woocommerce#47364).

  2. get_global_unique_id() could return values that are not GTIN such ISBN, EAN etc... If Meta is expecting a GTIN specifically, I think we should validate that the value returned is a valid GTIN. Since version 9.3.3, We added prepare_gtin to WC_Structured_Data for this (Validate and prepare GTIN in structured data woocommerce/woocommerce#50926)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rawdreeg thank you very much for reviewing! And sorry for late follow up.

1/ Make sense, will address this.

2/ Re "could return values that are not GTIN such ISBN, EAN etc...", on Meta side the GTIN is a super set of all types of identifiers, including:
UPC (North America / GTIN-12): 12-digit number.
EAN (Europe / GTIN-13): 13-digit number.
JAN (Japan / GTIN-13): 8 or 13-digit number.
ISBN (for books / ISBN-13): 13-digit number. Convert any 10-digit ISBN-10 numbers to ISBN-13.
ITF-14 (for multipacks / GTIN-14): 14-digit number.

Here is the API dev doc: https://developers.facebook.com/docs/commerce-platform/catalog/fields/

Plus, we have own validators of the GTIN on our side, so if it does it conform to any of the acceptable formats we would just not persist it.

So, whatever user input into Woo GTIN UI field, we can just pass to the Meta as raw value in my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

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

Plus, we have own validators of the GTIN on our side, so if it does it conform to any of the acceptable formats we would just not persist it.

If you have your validation, then it should be fine. Thanks for your response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rawdreeg added plugin version check before calling the function.

@mshymon mshymon requested a review from rawdreeg November 28, 2024 14:22
@vahidkay-meta vahidkay-meta merged commit 20397ef into vahidkay-meta:develop Dec 5, 2024
4 checks passed
@vahidkay-meta vahidkay-meta mentioned this pull request Dec 6, 2024
29 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants