Pick the right string value translate

Hello, I would like to know if there is any solution to what I am facing:

I have cs-cart installation with two storefronts. I have already set a string value translate to each storefront. So I do this:

I go to Settings - Texts & languages and “Add Language Variable” (for the first storefront add “Hello storefront 1”… After that, go to second storefront and insert the its own value “Hello storefront 2”.

Now, inside my custom addon code, I call this variable to send mail to customers when they are completing an order, let’s say __("da_notify").

But, sometimes the customer is ording from the Storefront 1, and goes the Language Variable from the Storefront 2. Is there any way to add the correct language variable and not mess up the variables? What I am doing wrong or what I am missing?

For example, I know there is $runtime.company_id which returns the company id, could I use this to confirm the right lang variable?

Thanks in advance

Hi!

You’d better use the $runtime.storefront_id variable in your template.

Thanks for your answer. The variable is the same… I mean how to use it inside my mail template (controller) php file? Could you give an example?
The client of my ecommerce make an order from Store 1, why the language variable did not taken from the store 1, which it is the correct one, and get it from Store 2?

I do not have and if statement or any other conditions … but is it required ?

In your controller you can get it in a similar way:

use Tygh\Registry;
use Tygh\Storefront\Repository;

$storefront = Repository::findById(Registry::get('runtime.storefront_id'));
fn_print_r($storefront->toArray());

Sorry, I don’t get it. Language variables are global and are not separated by storefronts in any way. If you’ve meant something else, please clarify.

Hello, thank you for your respond… Never seen that code, to be honest… I will give it a try and let you know if I have any questions about it…

I will try to explain in more detail here what I did with language variables I am talking about and want is my goal.

I have two storefronts in my installation of cs-cart
All”, “Store 1”, “Store 2”.

I have created a new lang variable “da_license_keys_pdf” and I have added the appropriate value to each storefront. Inside the value I have this code:

Download PDF <a href="https://store_1.com.gr/images/files/licenses_pdf/[pdf_name]">here</a>

The above code is inside the lang value da_license_keys_pdf of Store 1 (I have already picked the Store 1).

Now, I choose the Store 2, and inside the lang value I have this:
Download PDF <a href="https://store_2.com.gr/images/files/licenses_pdf/[pdf_name]">here</a>

Now inside my controller, I have this:

$license_keys_text = "";
if(!empty($pdf_name)) {
$license_keys_text .= '<p>';
$license_keys_text .= str_replace("[pdf_name]", $pdf_name, __("da_license_keys_pdf"));
$license_keys_text .= '</p>';
}

So, my client is in my store_1.com, making an order. After user completes the order, I am checking the products in the cart. If the value $pdf_name is not empty I want to send mail (which I did, correctly). but, the link inside value language (this one: da_license_keys_pdf) has the link from the Store 2:

Download PDF <a href="https://store_2.com.gr/images/files/licenses_pdf/[pdf_name]">here</a>

Why cs-cart take this value from another Store? this is my question…


What exactly returns the code you mention? Does this help to load the language variables?

$storefront = Repository::findById(Registry::get('runtime.storefront_id'));
fn_print_r($storefront->toArray());

Thank you for your time!

There is no way in the default Multi-Vendor or Store-Builder to create different values for the language variables depending on the storefront. There is no storefront selector on the Translations page, so either you are using a third party add-on or we are talking about different things :slight_smile:

This code prints all the data that is related to the Storefront entity (see the Tygh\Storefront\Storefront class, app/Tygh/Storefront/Storefront.php), so you can check what exactly can be usable for your case.

Hello, maybe I am not explain it correctly. I have attached two images to understand better and give more info:

I have a variable “da_license_keys_pdf” in two different storefronts. Thus, the URL of the value, is different!

Thus, when a user is shopping in my store, I want to grab the appropriate language variable which is:
https://domain123.gr/.../../some.pdf
Instead of this, I am getting the value of the second image, which the other storefront and is:
https://domain-something-else.gr/.../../some.pdf

This is not a third party addon or anything else… I am talking about storefronts and languages variables between them, right?

This is not happening all the time from clients buying from eshop … but 3 from 10 times, the values of these are mixed up.

My bad, I forgot that Store-Builder indeed has this feature. I’m spending too much time with Multi-Vendor :sweat_smile:

In this case it seems like something is affecting the value in the Registry’s value for the runtime.company_id during the page render. I don’t see any conditions in the clean installation where it could affect this value. Try checking third party add-ons.

Hello there,

My client has over 94+ active addons… Is there any other cs-cart’s variable like storefront_id or sothing, in order to get what I want similar to runtime.company_id? I do not know but I believe I am doing circles arround myself… sometimes it is working as expected and sometimes not.

thanks in advance

Please try

$storefront = Tygh::$app['storefront'];
$storefront_id = $storefront->storefront_id;

Or this one:

<?php
use Tygh\Tygh;

$repository = Tygh::$app['storefront.repository'];
$storefront = $repository->findByUrl(REAL_HOST);
$storefront_id = $storefront->storefront_id;