Change product variants prices.

  • Posts: 7
  • Thank you received: 0
  • Hikashop Business
1 week 2 days ago #319535

Hello.
Could you help with the make of the SQL query?
It seems to me that this cannot be done with the help of mass actions.

My product has some characteristics.
I need to change the price of a product variant with a certain characteristic, adding a constant (5) to the main price.

A change in price is required for all products that have this characteristic!

Thanks.

Last edit: 1 week 2 days ago by starko.

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

  • Posts: 69451
  • Thank you received: 10401
  • MODERATOR
1 week 1 day ago #319550

Hi,

This indeed can't be done with a mass action as the filter on characteristic will only target the main products, not the variants, and thus you can't change the price of the variants if you want to restrict it to only a particular characteristic.

Regarding a MySQL query, something like that:

UPDATE #__hikashop_variant AS v
LEFT JOIN #__hikashop_product AS p ON v.variant_product_id = p.product_id
LEFT JOIN #__hikashop_characteristic AS c ON v.variant_characteristic_id = c.characteristic_id
LEFT JOIN #__hikashop_price AS price ON p.product_id = price.price_product_id
SET price.price_value = price.price_value + 5 WHERE c.characteristic_parent_id = XXX AND p.product_type = 'variant'
where XXX is to be replaced with the id of the characteristic.
Of course, I recommend to make a backup before so that you can easily roll back if it doesn't work like you want.

The following user(s) said Thank You: starko

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

  • Posts: 7
  • Thank you received: 0
  • Hikashop Business
6 days 23 hours ago #319642

Yes, all this works fine (c.characteristic_id)
Thanks, Nicolas.

But there's a problem)
There are no records in the price table, that is, I have to make an insert for each record I need with this characteristic.

Do I have to write a PHP loop for multiple insertion? Or is there another possibility?

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

  • Posts: 69451
  • Thank you received: 10401
  • MODERATOR
5 days 7 hours ago #319675

Hi,

That's indeed correct. You need a loop in PHP to insert all the entries in the hikashop_price table. My MySQL query will only work supposing that all the variants already have a price.

Alternatively, for the variants without a price, if you want to add the same value for all of them, then you can add it directly in the main product and the price will be user dynamically by the variants without price. But as I don't know your situation, this might not be a solution to your problematic.

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

Time to create page: 0.056 seconds
Powered by Kunena Forum