Mass action delete extra or some character from product name

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 1 month ago #336429

-- 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: 3 years 2 weeks ago by naizak.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 1 month ago #336433

Hi,

It's should be possible with an action "Run MySQL query" and the text:

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.

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 1 month ago #336444

Thank you very much Nicolas

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

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 4 weeks ago #336503

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.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 4 weeks ago #336511

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:

$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: 3 years 3 weeks ago by nicolas.
The following user(s) said Thank You: naizak

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

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 4 weeks ago #336537

Thank you Very much Nicolas

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

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 3 weeks ago #336660

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: 3 years 3 weeks ago by naizak.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
3 years 3 weeks ago #336666

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.

  • Posts: 148
  • Thank you received: 13
  • Hikashop Business Hikashop Essential
3 years 2 weeks ago #336739

Work like a charm , thanks you very very much Monsieur :woohoo: :)

PS : i didn't get mail notification sorry for late answer

Last edit: 3 years 2 weeks 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.066 seconds
Powered by Kunena Forum