facebook-for-woocommerce
facebook-for-woocommerce copied to clipboard
Why is the variation id overwritten in WC_Facebook_Product->prepare_product ?
When the sync buttons product is clicked, item updates are scheduled and Background->process_item_update is run for each product id. There is a check if the product is a variation and $this->prepare_product_variation_data is run accordingly. But in the WC_Facebook_Product->prepare_product function the variation id is overwritten with the parent id at the beginning of the the function so the same is called for every variation of a product
if ( WC_Facebookcommerce_Utils::is_variation_type( $this->get_type() ) ) {
$id = $this->get_parent_id();
}
Is there a reason why this is done? This also prevents to hook facebook_for_woocommerce_integration_prepare_product and modify the data for product variations.
@lxbdr,
Is there a reason why this is done?
We use the $id to load $brand and $categories term values from what I can see. These terms aren't available to the variation product, so we get them from the parent.
https://github.com/woocommerce/facebook-for-woocommerce/blob/7050354be7a647cda5839eb157e25a622fb2a460/includes/fbproduct.php#L561-L566
This also prevents to hook facebook_for_woocommerce_integration_prepare_product and modify the data for product variations. You're right, the
$idpassed to the filter, and you no longer have access to the original $id. We'll need to look into this issue further and prioritize accordingly. I have some suggestions:
The $product_data array has the retail_id index, which concatenates the SKU and id. You could use this value to load the product.
https://github.com/woocommerce/facebook-for-woocommerce/blob/7050354be7a647cda5839eb157e25a622fb2a460/includes/fbproduct.php#L545-L546
Let me know if that helps.
@rawdreeg Thanks a lot for taking to the time to answer this! I will try to parse it from the retailer_id