Skip to main content

Mass action delete extra or some character from product name

More
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 :
  • 10-produitun
  • 11-produitdeux
  • 12-produitdeux
would be possible to delete with mass action only "10-" "11-" "12-" etc... ,
if it's possible how can i do it please :unsure:
Best regards
Last edit: 4 years 11 months ago by naizak.

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago #336433 by nicolas
Hi,

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.

More
4 years 11 months ago #336444 by naizak
Thank you very much Nicolas

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago #336503 by naizak
i got an error when i tested
"1305 FUNCTION adp_migrer.REGEX_REPLACE does not exist "

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago - 4 years 11 months ago #336511 by nicolas
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:
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();
That will do the same but got through PHP to run the regex before doing the MySQL query from the PHP code.
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.

More
4 years 11 months ago #336537 by naizak
Thank you Very much Nicolas

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago - 4 years 11 months ago #336660 by naizak
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
Last edit: 4 years 11 months ago by naizak.

Please Log in or Create an account to join the conversation.

More
4 years 11 months ago #336666 by nicolas
Hi,

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.

More
4 years 11 months ago - 4 years 11 months ago #336739 by naizak
Work like a charm , thanks you very very much Monsieur :woohoo: :)

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.242 seconds
Powered by Kunena Forum