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

_price meta data in variable products and replication DB #9892

Closed
shmuelgutman opened this issue Dec 22, 2015 · 2 comments
Closed

_price meta data in variable products and replication DB #9892

shmuelgutman opened this issue Dec 22, 2015 · 2 comments

Comments

@shmuelgutman
Copy link

Hello,

I want to share with you a problem

What is the symptom?

I have a variable product with couple of valid variations. After saving the product from the admin page there is no price html in the front product page.

What I saw so far ?

Searching how the price html is processing and found that the _price meta data for this product is empty string.
I went deeper and found that the _price metadata is updated twice in every product save execution:
once in includes/admin/meta-boxes/class-wc-meta-box-product-data.php:996 and once in includes/class-wc-product-variable.php:809 . in the first time it always update empty string and in the second time it process sync method that update it properly.

So whats the problem ?

I'm working with replication DB and hyperDB WP Plugin. Lets see the problem step by step:

  • The current value of _price is 199
  • Performs update_post_meta( $post_id, '_price', '' ); - _price is updated in master DB, metadata cache deleted.
  • Performs update_post_meta( $product_id, '_price', $min_price ); - where $min_price is 199, update_metadata functions first check the current value and get the result from the slave DB that haven't being updated yet from the master and get the value 199 which is equal to the $min_price, hence, the metadata is not updated , cache is not set and false is returned.
  • Slave DB is updating from master with the wrong value of empty string.
  • Next time get_post_meta( $post_id, '_price', true ); will return empty string.

My questions is:

  1. Do we really need to maintain _price metadata in variable products ?
    WC_Product_Variable::get_price_html method is checking this value first, and then uses get_variation_prices which is much more efficient
  2. If the answer to 1 is yes. Why to do it twice ?
  3. Is my issue with the replication DB is a general problem ?

Thanks ahead

@mikejolley
Copy link
Member

@sh-guti I see what you mean, but surely this is a problem with the hyperDB plugin if it cannot update values correctly? Meta data (from any plugin!) doesn't necessarily only get set once per session.

@shmuelgutman
Copy link
Author

Thanks for your commit, helps me a lot.

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

No branches or pull requests

2 participants