- Posts: 153
- Thank you received: 13
Mass action delete extra or some character from product name
4 years 11 months ago - 4 years 11 months ago #336429
by naizak
-- HikaShop version -- : 4.4.4 Essential
-- Joomla version -- : 3.10.2
-- PHP version -- : 7.4.24
Hi,
i have 900 product witch i would like to delete first 3 character in the name of the products
Example :
if it's possible how can i do it please
Best regards
-- Joomla version -- : 3.10.2
-- PHP version -- : 7.4.24
Hi,
i have 900 product witch i would like to delete first 3 character in the name of the products
Example :
- 10-produitun
- 11-produitdeux
- 12-produitdeux
if it's possible how can i do it please
Best regards
Last edit: 4 years 11 months ago by naizak.
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336433
by nicolas
Replied by nicolas on topic Mass action delete extra or some character from product name
Hi,
It's should be possible with an action "Run MySQL query" and the text:
It's should be possible with an action "Run MySQL query" and the text:
Code:
UPDATE #__hikashop_product SET product_name = REGEX_REPLACE(product_name, '^[0-9]+\-', '') WHERE product_id={product_id};
The following user(s) said Thank You: naizak
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336444
by naizak
Replied by naizak on topic Mass action delete extra or some character from product name
Thank you very much Nicolas
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336503
by naizak
Replied by naizak on topic Mass action delete extra or some character from product name
i got an error when i tested
"1305 FUNCTION adp_migrer.REGEX_REPLACE does not exist "
"1305 FUNCTION adp_migrer.REGEX_REPLACE does not exist "
Please Log in or Create an account to join the conversation.
4 years 11 months ago - 4 years 11 months ago #336511
by nicolas
Replied by nicolas on topic Mass action delete extra or some character from product name
Hi,
The function REGEX_REPLACE was added in MySQL 8.0.4. You must be using an older version of MySQL.
Unfortunately, with old versions of MySQL there is no regex replacement functions so you can't use this.
In that case, you can try instead to use a "run PHP code" action with the code:
That will do the same but got through PHP to run the regex before doing the MySQL query from the PHP code.
The function REGEX_REPLACE was added in MySQL 8.0.4. You must be using an older version of MySQL.
Unfortunately, with old versions of MySQL there is no regex replacement functions so you can't use this.
In that case, you can try instead to use a "run PHP code" action with the code:
Code:
$db = JFactory::getDBO();
$name = preg_replace('#^[0-9]+\-#','', '{product_name}');
$db->setQuery('UPDATE #__hikashop_product SET product_name =' . $db->Quote($name).' WHERE product_id = {product_id}');
$db->execute();
Last edit: 4 years 11 months ago by nicolas.
The following user(s) said Thank You: naizak
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336537
by naizak
Replied by naizak on topic Mass action delete extra or some character from product name
Thank you Very much Nicolas
Please Log in or Create an account to join the conversation.
4 years 11 months ago - 4 years 11 months ago #336660
by naizak
Replied by naizak on topic Mass action delete extra or some character from product name
hi,
Seems to be an error in the code :
syntax error, unexpected '$db' (T_VARIABLE), expecting ')'
i'm so bad in php
php versions :7.4.25
Joomla : 4.0.4
Seems to be an error in the code :
syntax error, unexpected '$db' (T_VARIABLE), expecting ')'
i'm so bad in php
php versions :7.4.25
Joomla : 4.0.4
Last edit: 4 years 11 months ago by naizak.
Please Log in or Create an account to join the conversation.
4 years 11 months ago #336666
by nicolas
Replied by nicolas on topic Mass action delete extra or some character from product name
Hi,
I modified the code in my previous message. Please try with the new version of the code there.
I modified the code in my previous message. Please try with the new version of the code there.
The following user(s) said Thank You: naizak
Please Log in or Create an account to join the conversation.
4 years 11 months ago - 4 years 11 months ago #336739
by naizak
Replied by naizak on topic Mass action delete extra or some character from product name
Work like a charm , thanks you very very much Monsieur :woohoo: 
PS : i didn't get mail notification sorry for late answer
PS : i didn't get mail notification sorry for late answer
Last edit: 4 years 11 months ago by naizak.
The following user(s) said Thank You: Philip
Please Log in or Create an account to join the conversation.
Time to create page: 0.227 seconds