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

Problem with shop translation #400

Closed
Ketuax opened this issue Mar 3, 2019 · 4 comments
Closed

Problem with shop translation #400

Ketuax opened this issue Mar 3, 2019 · 4 comments

Comments

@Ketuax
Copy link

Ketuax commented Mar 3, 2019

Hello,
my name is Katerina and I am just about to complete my first shop page www.kypseliworkshop.gr. I have a very weird thing happening with my website and it would be great if you could help.

I have a shop page in greek: https://www.kypseliworkshop.gr/gr/shop/
And a translated shop page in english: https://www.kypseliworkshop.gr/en/shop-2/
When I'm on the greek shop page trying to go to the english one it requests this link: https://www.kypseliworkshop-2.gr/el/shop-2/
I have tried with many names for the shop but what always happens is that it replaces the word "shop" in the main url (www.kypseliworkshop.gr) with whatever the english shop slug is. So if the slug is 'tree' then the requested url becomes www.kypseliworktree.gr/el/tree. This only happens in this case, i.e. only from the specified woocommerce shop page to the translated shop page. Not the other way round, not for any other page or product.

I disabled the woo-poly integration plugin and the language switching and everything else works fine.
(I have now turned it back on so you can see what happens)

Steps to Reproduce

  1. Go on the Greek shop page (Designated woo commerce shop page) from the main menu
  2. Change language to English

What I Expected

To go to the english shop page

What Happened Instead

Server not found error. The link requested was: https://www.kypseliworkshop-2.gr/el/shop-2/
instead of: https://www.kypseliworkshop.gr/en/shop-2/

  • PHP: 7.0.33
  • WordPress: 5.1
  • WooCommerce: 3.5.5
  • Polylang: [state if using Polylang PRO] 2.5.2
  • Hyyan WooCommerce Polylang Integration: 1.2.0
  • Browser: Safari, Chrome
@Ketuax
Copy link
Author

Ketuax commented Mar 3, 2019

Sorry, but I hadn't seen the previous comments.

This fixed it:
(thanks AlexeyArder!

Begin quoted post:

I had changed Pages.php

public function translateShopUrl($url, $language)
...
if ($shopPageTranslation) {
...
// $shopPage->post_name, $shopPageTranslation->post_name, $url
$shopPage->post_name, $url

Now all work as expected

@Jon007
Copy link
Contributor

Jon007 commented May 6, 2019

@Ketuax I also have not seen the previous comments.
What was the fix and why was it necessary? (as it seems to work for everyone else)
if we don't get the fix into the plugin you will have to re-apply it after next releases.

What is the final code you are using? as the quoted code is incomplete and incorrect syntax

@Ketuax
Copy link
Author

Ketuax commented May 8, 2019

Hi, here's what I did to fix the problem.

From this part of the code in pages.php

if ($shopPage) {
$shopPageTranslatedID = pll_get_post($shopPageID, $language);
$shopPageTranslation = get_post($shopPageTranslatedID);

        if ($shopPageTranslation) {
            $result = str_replace(
                    $shopPage->post_name, $shopPageTranslation->post_name, $url
            );
        }

I removed the word "Translation" from the last line.

The problem occurs when the page url contains the word "shop" as part of the company name. In my case it was Kypseli Workshop (www.kypseliworkshop.gr). Then the plugin goes and replaces the word "shop", with the slug translation.

I do not know php so I cannot say if this is correct coding but it solved my problem.

I hope this helps.

@Jon007
Copy link
Contributor

Jon007 commented May 11, 2019

ok with that change that bit of code would do nothing, which only works in your case because the shop page in both languages has the same slug "shop", so this is not a general purpose fix.

What it should do is only replace the last occurrence of the post_name (or not at all if both post names are the same...)

@Jon007 Jon007 closed this as completed in df30c59 May 12, 2019
Jon007 added a commit that referenced this issue May 19, 2019
bad merge in previous checkin
Jon007 added a commit that referenced this issue May 22, 2019
fixes #400 for additional use case where shop page is set to home page
AND shop page slug is also contained in home page
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants