Hikashop default variant in database

  • Posts: 2
  • Thank you received: 0
3 months 2 weeks ago #362548

-- HikaShop version -- : 4.7.0
-- Joomla version -- : 7.2.24
-- Error-message(debug-mod must be tuned on) -- : Column is_default is not found on table oah2p_hikashop_product

Hello,

I need some advice on where to find information in the database about whether the variant is the default or not. In the picture I marked what I mean.
I need a SQL query that will return 1 if the variant is the default and 0 if the variant is not the default.

I can't find that information anywhere in the database, I have searched all the Hikashop database tables.

Thanks for advice very much.

Attachments:

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

  • Posts: 82863
  • Thank you received: 13370
  • MODERATOR
3 months 2 weeks ago #362552

Hi,

This will be difficult.
In the hikashop_variant table, you have, for each characteristic of a product, one entry linking the product in the hikashop_product table and the characteristic in the hikashop_characteristic table, and one entry linking the product and the default value of the characteristic for that product.
So once you know the characteristic_id of the default values of the product with one MySQL query, you can run a second MySQL query to look of the entry in hikashop_product with its product_parent_id equal to the product_id of the main product, and with an entry for each characteristic in the hikashop_variant table with a link to the characteristic_id of the default value.
Doing all this in a single MySQL query, while allowing for multiple characteristics per product and supporting many characteristics will be quite difficult. I don't know if it's even possible.
In HikaShop, we don't do that in MySQL. We load the variants of the product, we load the links of the variants to the characteristic values, we load the links of the main product to the entries in the hikashop_characteristic table, and we sort this in PHP in order to know the default variant.

The following user(s) said Thank You: mydreams

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

  • Posts: 2
  • Thank you received: 0
3 months 2 weeks ago #362556

Thank you for your advice. Isn't it possible to get the SQL query and the additional PHP logic from the hikashop code somewhere?

I understand that it is not possible to get a list of all variants from the database itself or by using JOIN and whether the variant is the default or not?

This is bad:

v.is_default AS is_deafult -- this is bad
I have this SQL query:
SELECT 
	p.product_id AS 'ID produktu', 
	p.product_name AS 'název hlavního produktu',
	COALESCE(v.product_quantity, p.product_quantity) AS 'Počet',
	c.characteristic_id AS 'characteristic_id',
	c.characteristic_value AS 'název varianty',
	prc.price_product_id AS 'price_product_id',
	prc.price_id AS 'ID ceny',
	prc.price_value AS 'Cena',
	p.product_published AS 'published_hlavni',
	v.product_published AS 'published_varianta',
	v.product_id AS 'ID varianty',
	v.is_default AS is_deafult -- this is bad -----------------------------
FROM oah2p_hikashop_product AS p
	LEFT JOIN oah2p_hikashop_product AS v ON v.product_parent_id = p.product_id
	LEFT JOIN oah2p_hikashop_variant AS v_c ON v.product_id = v_c.variant_product_id
	LEFT JOIN oah2p_hikashop_characteristic AS c ON v_c.variant_characteristic_id = c.characteristic_id
	LEFT JOIN oah2p_hikashop_price AS prc ON prc.price_product_id = COALESCE(v.product_id, p.product_id)
	WHERE p.product_parent_id = 0 OR p.product_parent_id IS NULL
	ORDER BY p.product_id, v.product_id;

Last edit: 3 months 2 weeks ago by mydreams.

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

  • Posts: 82863
  • Thank you received: 13370
  • MODERATOR
3 months 1 week ago #362559

Hi,

As I said, it's not just on MySQL query.
If you want to look at what we have to get the default variant, you have two places:
- in the backend variants listing we calculate the default variant with the code from the form_variants method of administrator/components/com_hikashop/views/product/view.html.php which loads the data, and the code in the administrator/components/com_hikashop/views/product/tmpl/form_variants.php which calculates the default variant while displaying the table list of variants.
- on the product page on the frontend, we load the variants and characteristics data in the show function of components/com_hikashop/views/product/view.html.php and we then call addCharacteristics of administrator/components/com_hikashop/classes/product.php to find the default variant, and order the characteristics and variants properly.

It's a lot of code, as we don't just want to know the default variant, but a whole bunch of other things.

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

Time to create page: 0.065 seconds
Powered by Kunena Forum