Several problem related variants

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282075

-- HikaShop version -- : 3.2.1
-- Joomla version -- : 3.8.2
-- PHP version -- : 7.1.9

Hi, I have the following problems with the variants.
The first if I try to set a variant (created by a partner) by default from the administration of Hikashop, I will get the following error:



The second is if I try to change the variant (created by a partner) from the panel of Hikamarket will get this error:


This is a short video of the test: youtu.be/Hjh5h7AoEDE

Attachments:
Last edit: 7 years 6 months ago by neo191987.

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

  • Posts: 83780
  • Thank you received: 13568
  • MODERATOR
7 years 6 months ago #282079

Hi,

Regarding HikaShop, this can only happen if you have variants with data in the hikashop_product but not in the hikashop_variant table.
This should normally not happen. So the issue is not really that setting the default variant doesn't work, but something else which made that situation possible.
Normally, when the first variant is created for a product, it is automatically selected as default, and the data is automatically generated in both tables for all the variants when you create them.
Are you able to reproduce the problem with another product ? What are the steps you took to reach that state ?

Also, which version of HikaMarket do you have ?

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

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282122

Hi, all the variants added by other users through Hikamarket is getting this problem. For the test I used the example demo of Hikashop and execute scenarios with two users-one is a user (the partner who added the variant), the other is like a super admin. You can see in the video I've shared in the first post, the exact steps I've done. I use the latest versions of your products (downloaded from today).

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

  • Posts: 26232
  • Thank you received: 4035
  • MODERATOR
7 years 6 months ago #282123

Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282160

Yes, I opened a new topic because, as far as I understand, it should be in the Hikashop section and we have already commented on some issues that have already been fixed.

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

  • Posts: 83780
  • Thank you received: 13568
  • MODERATOR
7 years 6 months ago #282164

Hi,

As Jerome said on the other thread, and as I said in my last message here, we need to understand how you are able to reproduce the issue.
What you provided in the video only shows the result: the operations in the video don't work. And I already told you, that it's normal, that is because the data is missing in the database.
What we need to know is how you create that situation. So again, could you provide precise instructions of what you do to get to that state with a product which has one variant which isn't default and is missing half of the data in the database ? How is that product created ? How is the variant added exactly ?

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

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282234

Hi I made a video from the installation of your products until the creation of the variants and the manifestation of the two errors: youtu.be/iuls_2ReJsY

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

  • Posts: 83780
  • Thank you received: 13568
  • MODERATOR
7 years 6 months ago #282238

Hi,

Great. That helps a lot, thanks.
So change the code:

if(!empty($element->characteristics)) {
				$insert = array();
				foreach(array_keys($element->characteristics) as $c) {
					if(is_numeric($c) && (int)$c > 0)
						$insert[] = (int)$c . ',' . (int)$product_id . ',0';
				}
				if(empty($insert))
					return false;

				$query = 'INSERT IGNORE INTO ' . hikashop_table('variant').
						' (variant_characteristic_id, variant_product_id, ordering)'.
						' VALUES (' . implode('),(', $insert) . ');';
				$this->database->setQuery($query);
				$this->database->query();

				unset($insert);
			}
to:
if(empty($element->characteristics))
				return true;

			$insert = array();
			foreach(array_keys($element->characteristics) as $c) {
				if(is_numeric($c) && (int)$c > 0)
					$insert[] = (int)$c . ',' . (int)$product_id . ',0';
			}
			if(empty($insert))
				return false;

			$query = 'INSERT IGNORE INTO ' . hikashop_table('variant').
					' (variant_characteristic_id, variant_product_id, ordering)'.
					' VALUES (' . implode('),(', $insert) . ');';
			$this->database->setQuery($query);
			$this->database->query();

			unset($insert);

			if(empty($element->product_parent_id))
				return true;

			// We also check if there is a default variant for the main product
			$query = 'SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id = ' . $element->product_parent_id . ' AND variant_characteristic_id NOT IN (' . implode(',', array_keys($element->characteristics)) . ')';
			$this->database->setQuery($query);
			$default = $this->database->loadObject();
			if(!empty($default))
				return true;

			// If not, we add the entries for it too using the current variant
			$insert = array();
			foreach(array_keys($element->characteristics) as $c) {
				if(is_numeric($c) && (int)$c > 0)
					$insert[] = (int)$c . ',' . (int)$element->product_parent_id . ',0';
			}
			if(empty($insert))
				return false;

			$query = 'INSERT IGNORE INTO ' . hikashop_table('variant').
					' (variant_characteristic_id, variant_product_id, ordering)'.
					' VALUES (' . implode('),(', $insert) . ');';
			$this->database->setQuery($query);
			$this->database->query();

			unset($insert);
in the file administrator/components/com_hikashop/classes/product.php
Then, create a new product like this one and test again the same steps and it should hopefully work fine.

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

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282270

Hi, unfortunately I got the same error.

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

  • Posts: 26232
  • Thank you received: 4035
  • MODERATOR
7 years 6 months ago #282273

Hello,

Basically, a characteristic "vendor" do not have any value in the database ; that characteristic is using element provided dynamically via a special trigger.
Due to the fact that there is no "values", you can't have a default value for the vendor because you can't store that information in the database.

So, something has to be changed in the "toggle" in order to avoid to affect a value where there is no available values.

Now regarding the rest, there is a line of code :

$query = 'SELECT * FROM ' . hikashop_table('variant') . ' WHERE variant_product_id = ' . $element->product_parent_id . ' AND variant_characteristic_id NOT IN (' . implode(',', array_keys($element->characteristics)) . ')';
The variable $element->characteristics can have an entry without a name ; so if you do a "array_keys", you can have an empty string in the array of result and not just numbers. That explain one of the errors you got.

That's why, I proposed to replace for the HikaShop product class (in the function updateCharacteristics, that code
	$query = 'DELETE FROM ' . hikashop_table('variant') . ' WHERE variant_product_id = ' . $product_id;
	if(!empty($element->characteristics))
		$query .= ' AND variant_characteristic_id NOT IN (' . implode(',', array_keys($element->characteristics)) . ')';
into
	$c = $element->characteristics;
	unset($c['']);
	$query = 'DELETE FROM ' . hikashop_table('variant') . ' WHERE variant_product_id = ' . $product_id;
	if(!empty($c))
		$query .= ' AND variant_characteristic_id NOT IN (' . implode(',', array_keys($c)) . ')';
	unset($c);
Thus it will avoid the SQL error when updating the characteristics.

Regarding the toggle part ; we have to perform deeper investigation and see how we can improve the structure to allow dynamic characteristics like the "vendors" one, to still have the possibility to have a default value (even if there is no values in the database).

Please note that you have to revert the Nicolas' patch.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 431
  • Thank you received: 19
7 years 6 months ago #282285

Thanks for the reply. I've been seeing this mistake for a long time, but Jerome told me a while ago that you would release Hikamarket 2 and that's why I did not report this problem to see if it was fixed there. When you're done with the patch, let me know. I have not found any errors more like this :)

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

  • Posts: 83780
  • Thank you received: 13568
  • MODERATOR
7 years 6 months ago #282289

Hi,

We've added these patches on our end so that the interface doesn't crash when using it, in both HikaShop and HikaMarket.

For the default variant selection to work with dynamic characteristics like the "vendor" one will require a profound rework of the characteristics/variants system. We have an idea of what should be done, basically transfer the data from the hikashop_variant table to a column in the hikashop_product table for the default variant selection, but it means a lot of things to be adapted here and there to handle that change.

The following user(s) said Thank You: neo191987

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

Time to create page: 0.101 seconds
Powered by Kunena Forum