Page 1 of 2
hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Wed Nov 29, 2023 3:30 pm
by loop
Hi All
My Problem is, i have 4 languages in my shop and if the user orders in french, thenn the products_name in the orders_products table is also in french
And for us it's difficult to manage this in the shop ...so my question. what is the easiesst, best way to save in the mysql table the default language of the products_name
my idea is to make a hook to update it with the right language as i have done with manufacturers_id
Code: Select all
class hook_shop_checkout_process__15_update_manufacturers_id {
public function listen_startCheckout() {
$GLOBALS['db']->query(sprintf(<<<'EOSQL'
UPDATE orders_products op INNER JOIN products p ON op.products_id = p.products_id
SET op.manufacturers_id = p.manufacturers_id
WHERE op.orders_id = %d
EOSQL
, $GLOBALS['order_id']));
}
}
ist there a better way? if not, what is the cleanest query to update it to the products_name with languages_id = 2 ?
thanks in advance!
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Nov 30, 2023 2:47 am
by ecartz
Don't store it in the database. Just read the correct name in admin.
Remember that the database name is what is shown to the customer. You don't want to change that. Just use the product ID to fetch the correct name in admin and display that to your users. The hook to do that would be hook_admin_orders_rewrite_name and the listener would be listen_editAction
Beyond that, what you're describing is what the model or GTIN should do. If your employees used either or both of those, they are language independent.
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Nov 30, 2023 3:39 pm
by loop
Hi ecartz, i know that ean is worldwide, the point is the invoice is printed out in our warehouse and the employe looks on the invoice (paper) and search the product. And it's more difficult to read and understand which product the customer like than in the own language....that's why i wanted
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Nov 30, 2023 11:10 pm
by ecartz
loop wrote: ↑Thu Nov 30, 2023 3:39 pm
the invoice is printed out in our warehouse
Yes. That's what I'm saying. Either change that step and print the product name that you want or change the next step and have the employee look at something other than the product name. The product model should already be on the invoice.
If you want to change the invoice, it would be hook_admin_invoice_rewrite_name and listen_injectBodyStart -- iterate over the products and change the names as desired.
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Sun Dec 03, 2023 10:33 am
by burt
If using the name is non-negotiable in your system...ie, you cannot change to GTIN or Model...
Rather than change the name of what the buyer ordered, which would change other things (update emails, account_history and so on)...add in a column in the orders_products table which is just for admin use;
admin_view_product_name varchar 255
have a hook which activates in the checkout process which updates this to the product in your needed language.
Then add this into the invoice or packing slip (or whatever you use for order picking).
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Feb 01, 2024 2:14 pm
by loop
Hi All
i have GTIN and everything but i like to have the german language in the db after customer bought it. it's easyer for us, for warehouse for admin ...
i already made a hook in checkout_process
Code: Select all
class hook_shop_checkout_process__15_update_orders_products {
public function listen_startCheckout() {
$GLOBALS['db']->query(sprintf(<<<'EOSQL'
UPDATE orders_products op
INNER JOIN products p ON op.products_id = p.products_id
INNER JOIN products_description pd ON p.products_id = pd.products_id
SET op.manufacturers_id = p.manufacturers_id, op.products_name = pd.products_name
WHERE pd.language_id = '2' AND op.orders_id = %d
EOSQL
, $GLOBALS['order_id']));
}
}
the strange thing is the code works 100% (if i execute it in sql it works 100%, if i make a testorder it also executed) but i have a couple of orders where this is not triggered or at least not with the right order_id
does somebody has a idea under which circumstances this hook is not fired or has no orders_id? in 90% it works perfect, but not everytime

Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Feb 01, 2024 3:17 pm
by loop
i changed (moved) the hook to checkout_success, now it works. i think i have no disadvantage here:
Code: Select all
<?php
/*
$Id$
CE Phoenix, E-Commerce made Easy
https://phoenixcart.org
Copyright (c) 2021 Phoenix Cart
Released under the GNU General Public License
*/
class hook_shop_checkout_success_orders_products_update {
public function listen_injectSiteStart() {
if(!empty($GLOBALS['order_id']) && $GLOBALS['order_id'] > 0){
$GLOBALS['db']->query(sprintf(<<<'EOSQL'
UPDATE orders_products op
INNER JOIN products p ON op.products_id = p.products_id
INNER JOIN products_description pd ON p.products_id = pd.products_id
SET op.manufacturers_id = p.manufacturers_id, op.products_name = pd.products_name
WHERE pd.language_id = '2' AND op.orders_id = %d
EOSQL
, $GLOBALS['order_id']));
}
}
}
let me know if it's not a good idea here
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Feb 01, 2024 4:08 pm
by burt
There are probably many ways to achieve this. Here is my thought;
A new checkout segment;
https://github.com/CE-PhoenixCart/Phoen ... s/checkout
which loops through your order_products and updates new DB column of each with the "main language" name, using;
https://github.com/CE-PhoenixCart/Phoen ... er.php#L92
$name = \Product::fetch_name($x, $y);
Where x is product ID and $y is the main language ID.
Admin Side (for viewing), eg invoice.php, you'll need to make the order get the new DB column.
This hook might do it;
https://github.com/CE-PhoenixCart/Phoen ... er.php#L47
And then some hardcoded change in invoice.php (I do have invoice/packingslip on the "needs to be looked" list to make
no core code changes possible, but that is off in the future somewhere).
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Feb 01, 2024 4:33 pm
by loop
hi burt, thank you
but how is my solution? with a hook (no hardcoding) in checkout_success.php? i mean it works perfect and at the moment i don't see something bad about it...
Re: hook (or other solution) to save the products_name in the orders_products table in "standard" language
Posted: Thu Feb 01, 2024 4:42 pm
by burt
My view is always this:
If it works for your needs, it is good.