Skip to content
This repository has been archived by the owner on Mar 17, 2022. It is now read-only.

Variation Attribute not synced #5

Closed
phoenix4rmhell opened this issue Jun 18, 2015 · 11 comments
Closed

Variation Attribute not synced #5

phoenix4rmhell opened this issue Jun 18, 2015 · 11 comments
Labels

Comments

@phoenix4rmhell
Copy link

Hello Hyyan,

Thanks for the awesome plugin.
There is a problem with variable product attribute when creating the copy of the product variations for another language. The meta 'attribute_' is not synced. All the other metas are being copied except the main attribute.
I'm a new developer and as far as I've looked into it the problem seems to be in
File: src/Hyyan/WPI/product/variation.php
Function: protected function copyVariationMetas($from, $to){...}

the array $translated is always empty so the value is not getting copied. I'm not sure if that is the problem or I'm doing something wrong. Can you check that please?

Regards,
Akash Kanojia

@hyyan
Copy link
Owner

hyyan commented Jun 18, 2015

@phoenix4rmhell I don't think the problem is in the function logic here , you an do two things to make sure :

After disabling all plugin in your site except for this one and (ploylang , WooCommerce) :

  • Make sure the attribute sync is enabled in the plugin settings page / Meta tab ,
  • Enable the Synchronization for taxonomies in polylang settings page

If non of that worked for you and that might be strange , add this function somewhere in your theme funciton file then navigate to your post in default language in the wp admin and paste the result you see here please .

add_action('admin_ini', function() {

      var_dump(get_post_meta(@$_GET['post']));
});

@phoenix4rmhell
Copy link
Author

Hello Hyyan!

Thanks for the quick reply.

I've tried the solutions you mentioned above

  • disable all plugins then check
  • enabled Sync for all attributes on woo-poly metas list
  • Enabled Synchronization fro taxonomies

Still its not working.
After that I tried the same with a fresh WP install
installed only the required plugins (Used Storefront Theme)

Still the same issue.
I even checked the DB (wp_postmeta table)
only the original post (post in default language that I create) has the meta_key = attribute_size attached with it. The variations created by woo-poly has other meta_key(s) but not attribute_size key.

Product Variation Tabs for Default Language:
default

Product Variation Tabs for Second Language:
second

And this is the dump I get after adding your code in functions.php
The hook was admin_init right?

array(41) { ["_translation_porduct_type"]=> array(1) { [0]=> string(8) "variable" } ["_edit_last"]=> array(1) { [0]=> string(1) "1" } ["_edit_lock"]=> array(1) { [0]=> string(12) "1434707605:1" } ["_product_attributes"]=> array(1) { [0]=> string(161) "a:1:{s:4:"size";a:6:{s:4:"name";s:4:"Size";s:5:"value";s:5:"6 | 7";s:8:"position";s:1:"0";s:10:"is_visible";i:1;s:12:"is_variation";i:1;s:11:"is_taxonomy";i:0;}}" } ["_visibility"]=> array(1) { [0]=> string(7) "visible" } ["_stock_status"]=> array(1) { [0]=> string(7) "instock" } ["total_sales"]=> array(1) { [0]=> string(1) "0" } ["_downloadable"]=> array(1) { [0]=> string(2) "no" } ["_virtual"]=> array(1) { [0]=> string(2) "no" } ["_regular_price"]=> array(1) { [0]=> string(0) "" } ["_sale_price"]=> array(1) { [0]=> string(0) "" } ["_purchase_note"]=> array(1) { [0]=> string(0) "" } ["_featured"]=> array(1) { [0]=> string(2) "no" } ["_weight"]=> array(1) { [0]=> string(0) "" } ["_length"]=> array(1) { [0]=> string(0) "" } ["_width"]=> array(1) { [0]=> string(0) "" } ["_height"]=> array(1) { [0]=> string(0) "" } ["_sku"]=> array(1) { [0]=> string(0) "" } ["_sale_price_dates_from"]=> array(1) { [0]=> string(0) "" } ["_sale_price_dates_to"]=> array(1) { [0]=> string(0) "" } ["_price"]=> array(1) { [0]=> string(1) "9" } ["_sold_individually"]=> array(1) { [0]=> string(0) "" } ["_manage_stock"]=> array(1) { [0]=> string(2) "no" } ["_backorders"]=> array(1) { [0]=> string(2) "no" } ["_stock"]=> array(1) { [0]=> string(0) "" } ["_upsell_ids"]=> array(1) { [0]=> string(6) "a:0:{}" } ["_crosssell_ids"]=> array(1) { [0]=> string(6) "a:0:{}" } ["_min_variation_price"]=> array(1) { [0]=> string(1) "9" } ["_max_variation_price"]=> array(1) { [0]=> string(2) "10" } ["_min_price_variation_id"]=> array(1) { [0]=> string(2) "35" } ["_max_price_variation_id"]=> array(1) { [0]=> string(2) "36" } ["_min_variation_regular_price"]=> array(1) { [0]=> string(2) "10" } ["_max_variation_regular_price"]=> array(1) { [0]=> string(2) "12" } ["_min_regular_price_variation_id"]=> array(1) { [0]=> string(2) "35" } ["_max_regular_price_variation_id"]=> array(1) { [0]=> string(2) "36" } ["_min_variation_sale_price"]=> array(1) { [0]=> string(1) "9" } ["_max_variation_sale_price"]=> array(1) { [0]=> string(2) "10" } ["_min_sale_price_variation_id"]=> array(1) { [0]=> string(2) "35" } ["_max_sale_price_variation_id"]=> array(1) { [0]=> string(2) "36" } ["_default_attributes"]=> array(1) { [0]=> string(6) "a:0:{}" } ["_product_image_gallery"]=> array(1) { [0]=> string(0) "" } }

You can reproduce the problem easily. I've tried my best to explain the issue. Still I don't know if I'm doing something wrong. And yes I selected default language before adding variable product (any product).

Can you check if the issue is in plugin or I'm making any mistake?

Thanks for the help!
Regards,
Akash Kanojia

@phoenix4rmhell
Copy link
Author

Just for the test I tried adding some code in
src\Hyyan\WPI\Product\Variation.php

in function

    protected function copyVariationMetas($from, $to){...}

if I change this code

    foreach ($metas[$key] as $termSlug) {
        $term = get_term_by('slug', $termSlug, $tax);
        if ($term) {
            $lang = isset($_GET['new_lang']) ? esc_attr($_GET['new_lang']) : pll_get_post_language($this->to->id);
            $translated[] = get_term_by('id', pll_get_term($term->term_id, $lang), $tax)->slug;
        }
    }

to:

    foreach ($metas[$key] as $termSlug) {
        $term = get_term_by('slug', $termSlug, $tax);
        if ($term) {
            $lang = isset($_GET['new_lang']) ? esc_attr($_GET['new_lang']) : pll_get_post_language($this->to->id);
            $translated[] = get_term_by('id', pll_get_term($term->term_id, $lang), $tax)->slug;
        }else{
            $translated[] = $termSlug;
        }
    }

then it starts working fine.
After a little debugging as I saw the value was missing from meta_key => attribute_size.
I added the else part because $translated[] was passed empty to the next code without the value.
After adding this it started working fine.
Maybe you can put it in the code in the right manner.

Regards,
Akash Kanojia

@hyyan
Copy link
Owner

hyyan commented Jun 18, 2015

@phoenix4rmhell thank you for the great effort in explaining the issue , but I have to ask you this question to make sure before I go any deeper in this issue , have you translated the attributes you are using to generate the variations ? as it seems in the photos , you did not ? am I right ?

@hyyan hyyan added the bug label Jun 18, 2015
@phoenix4rmhell
Copy link
Author

@hyyan I'm not sure how to translate the attributes. Is there any interface to translate the attributes on admin section or do I have to add the translation for attributes in translation files?
I've checked the woo-poly settings and polylang settings and I can't find the interface to translate the attributes. Can you guide me how to do that?

@hyyan
Copy link
Owner

hyyan commented Jun 19, 2015

@phoenix4rmhell The plugin does not create any new interface , but it uses the current avaliable woocommere and polylang interface.

To translate your attributes follow these steps in the images below :

fireshot capture - attributes woo wordpress_ - http___woo localhost com_wp-admin_edit php

fireshot capture - attributes woo wordpress_ - http___woo localhost com_wp-admin_edit php

ds

fireshot capture - add attribute name here woo _ - http___woo localhost com_wp-admin_edit-tags php

if you have created attributes when you created your product in the default language , then go on and translate you created attributes in the same interface before you start creating translation for your product .

Hope that helps !

@phoenix4rmhell
Copy link
Author

@hyyan Thank you very much for the support. I didn't know about attribute translation. Everything seems to be working fine now.
Thanks again for the plugin.

@hyyan
Copy link
Owner

hyyan commented Jun 19, 2015

@phoenix4rmhell you are more than welcome , and please do not hesitate to ask more questions , I'll always be here to help .

@hyyan hyyan closed this as completed Jun 19, 2015
@hyyan hyyan added question and removed bug labels Jun 19, 2015
@dharamgoyal
Copy link

Hello,
Not getting woocommerce product attribute in hindi while use hinidi code(hi) with REST API also using polylang and your plugin

@raynov
Copy link

raynov commented Sep 2, 2016

Hi guys,
The above code didn't do it for me either. I figured must be because the attributes names and slugs are in cyrillic. So I changed the code in
protected function copyVariationMetas($from, $to) {..}
as follows:
$tax = str_replace('attribute_', '', $key);
to
$tax = urldecode(str_replace('attribute_', '', $key));
and
$term = get_term_by('slug', $termSlug, $tax);
to
$term = get_term_by('slug', urldecode($termSlug), $tax);

@dharamgoyal suppose this helps with hindi too

@bgmeet
Copy link

bgmeet commented Jan 29, 2017

Hello Hyyan,
Hello,

everything work perfect except that when translate product the new translated product come absolute empty. Only the name and product description is translated. Noting more. Noting more inside.
My tags and attributes are translated. I translate them before translate products.

Price, attributes, Taxes, even image is empty.

I have about 1900 products if i must add those attributes manual will cost me months.

Look examle:

Upload photos.

Any advice will be most welcome:

Thx in advanced:

Kind Regards:

Venetta

original product
original product2
translated product
translated product1
translated product2

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants