Change product variants prices.

  • Posts: 12
  • Thank you received: 0
4 years 6 months 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: 4 years 6 months ago by starko.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 6 months 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: 12
  • Thank you received: 0
4 years 5 months 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: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 5 months 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.

  • Posts: 12
  • Thank you received: 0
4 years 5 months ago #320030

UPDATE `jos_hikashop_price` as var 
right join jos_hikashop_product as pvar on pvar.product_id=var.price_product_id 
right join jos_hikashop_variant as vvar on vvar.variant_product_id=pvar.product_id

left JOIN (
    SELECT *
	FROM `jos_hikashop_price` as main 
	left join jos_hikashop_product as pmain on pmain.product_id=main.price_product_id 

	where pmain.product_type='main' 
    
    ) as main on main.product_id=pvar.product_parent_id

set var.price_value = main.price_value + 5
    
where pvar.product_type='variant' and vvar.variant_characteristic_id=xxx

Today I worked with this and saw that the query does not do what I need.
Your SQL query adds a constant to the value of the variant.
I need a more flexible solution, depending on the base price of the product.

This new code works, although it still requires the existence of an record of variant price.


Non-existent prices can be added through mass actions!
I did it by editing the price with filtering records. If the record does not exist, your code adds a new record to the price table.



Unfortunately filtering the characteristics does not work, this would simplify the task.
An error has occurred.
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`` = '1' AND hk_characteristic_parent3.characteristic_value = 'Wood handle')' at line 1

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
4 years 5 months ago #320058

Hi,

We were reported a similar issue recently with the mass action system on characteristics:
www.hikashop.com/support/forum/mass-acti...ql-error.html#319877
We've added a patch on our end for that. Download again the install package of HikaShop on our website and install it on your website and it should hopefully work properly.

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

Time to create page: 0.060 seconds
Powered by Kunena Forum