Product filtering sql error

  • Posts: 10
  • Thank you received: 0
12 years 4 months ago #57340

My product has two characteristics, I use two dynamic checkbox filters for filtering by those characteristics.
When i chose two options in differnt filters i have an SQL error:

JDatabaseMySQLi::query: 1066 - Not unique table/alias: 'c' SQL=SELECT DISTINCT b.* FROM ai0zt_hikashop_product_category AS a LEFT JOIN ai0zt_hikashop_product AS b ON a.product_id=b.product_id LEFT JOIN ai0zt_hikashop_product AS c ON b.product_id=c.product_parent_id LEFT JOIN ai0zt_hikashop_variant AS choosebysize1 ON choosebysize1.variant_product_id=c.product_id LEFT JOIN ai0zt_hikashop_product AS c ON b.product_id=c.product_parent_id LEFT JOIN ai0zt_hikashop_variant AS choosebycolor2 ON choosebycolor2.variant_product_id=c.product_id WHERE b.product_published=1 AND b.product_type = 'main' AND a.category_id IN (32,33,36,38,39,40,41,31) AND (b.product_access = 'all' OR b.product_access LIKE '%,8,%') AND choosebysize1.variant_characteristic_id IN (7) AND choosebycolor2.variant_characteristic_id IN (4) ORDER BY b.product_created DESC LIMIT 0, 12

Is there need more info?

Last edit: 12 years 4 months ago by Asty.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 4 months ago #57402

Hi,

Please change the line:

$on.=' LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_parent_id LEFT JOIN '.hikashop_table('variant').' AS '.$filter->filter_namekey.$i.' ON '.$filter->filter_namekey.$i.'.variant_product_id=c.product_id';


to:
static $done = false;
					if(!$done){
						$done = true;
						$on.=' LEFT JOIN '.hikashop_table('product').' AS c ON b.product_id=c.product_parent_id';
					}
					$on.=' LEFT JOIN '.hikashop_table('variant').' AS '.$filter->filter_namekey.$i.' ON '.$filter->filter_namekey.$i.'.variant_product_id=c.product_id';

in the file administrator/components/com_hikashop/classes/filter.php and that should fix the problem.

The following user(s) said Thank You: Asty

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

  • Posts: 165
  • Thank you received: 3
10 years 10 months ago #139214

Hi i Made the modification as suggest to have the product page sort by cheapest price first automatically as suggested in the link below.
www.hikashop.com/forum/4-how-to/57655-or...-cheapest-price.html

The problem is when i use this modification I get the below error when I select any characteristic checkbox in my filter setting,

SQL=SELECT DISTINCT b.* FROM hkta4_hikashop_product_category AS a LEFT JOIN hkta4_hikashop_product AS b ON a.product_id=b.product_id LEFT JOIN hkta4_hikashop_product AS c ON b.product_id=c.product_parent_id LEFT JOIN hkta4_hikashop_variant AS Mattress_Size2 ON Mattress_Size2.variant_product_id=c.product_id LEFT JOIN hkta4_hikashop_price AS c ON c.price_product_id=b.product_id WHERE b.product_published=1 AND b.product_type = 'main' AND a.category_id IN (21) AND (b.product_access = 'all' OR b.product_access LIKE '%,1,%') AND Mattress_Size2.variant_characteristic_id IN (6) AND c.product_quantity!=0 ORDER BY c.price_value ASC LIMIT 0, 12

I tried the solution you have posted above above because it seems like the same error, but instead when i implement the code you listed i get the following error:
Parse error: syntax error, unexpected T_CLASS, expecting T_FUNCTION in /xxx/xxxx/public_html/administrator/components/com_hikashop/classes/filter.php on line 1247

How can I fix this?...this is pretty urgent I have to have the site done by the end of the week and I need to be able to have to product listing page automatically list the product by cheapest price first and not get the above error when I filter a characteristic in the filter.

Thanks,

Josh

Last edit: 10 years 10 months ago by jschroeder.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 10 months ago #139242

Hi,

The code on this current thread has no link to your issue.

I've updated the code on the other thread as that's the one that should be changed :
www.hikashop.com/forum/4-how-to/57655-or...st-price.html#139240

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

  • Posts: 165
  • Thank you received: 3
10 years 10 months ago #139419

Hi nicolas i changed the code as you suggested and thought it was working but i am still getting another SQL error now. I have a price slider in my filtering system. Whenever I select my price slider/cursor price and select the product brand i still get the following sql error:

SQL=SELECT DISTINCT b.* FROM hkta4_hikashop_product_category AS a LEFT JOIN (SELECT * FROM hkta4_hikashop_product AS product2 LEFT JOIN hkta4_hikashop_price AS price2 ON product2.product_id=price2.price_product_id WHERE (price2.price_access = 'all' OR price2.price_access LIKE '%,1,%' OR ISNULL(price2.price_access)) AND product2.product_type='main' GROUP BY product2.product_id ORDER BY price2.price_min_quantity ASC) AS b ON a.product_id=b.product_id INNER JOIN hkta4_hikashop_product_category AS Mattress_Brand1 ON Mattress_Brand1.product_id=product2.product_id AND Mattress_Brand1.category_id IN (30) LEFT JOIN hkta4_hikashop_price AS price_join ON price_join.price_product_id=b.product_id WHERE b.product_published=1 AND b.product_type = 'main' AND a.category_id IN (21) AND (b.product_access = 'all' OR b.product_access LIKE '%,1,%') AND ( ( case when b.price_currency_id IS NULL then 0 when b.price_currency_id = '1' then (b.price_value/0.73465) when b.price_currency_id IS NULL then 0 when b.price_currency_id = '2' then b.price_value end ) >= 1 ) AND ( case when b.price_currency_id IS NULL then 0 when b.price_currency_id = '1' then (b.price_value/0.73465) when b.price_currency_id IS NULL then 0 when b.price_currency_id = '2' then b.price_value end ) BETWEEN 3070 AND 20000 ORDER BY price_join.price_value ASC LIMIT 0, 12


when changing the price to filter from lowest to highest. It now interferes with the price cursor slider..How can i fix the above error
?

Last edit: 10 years 10 months ago by jschroeder.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
10 years 10 months ago #139531

Hi,

Change the line:

if(preg_match('#hikashop_product AS ([a-z0-9_]+)#i',$a,$matches)){
to:
if($a[0]!='(' && strpos($a,') AS b') && preg_match('#hikashop_product AS ([a-z0-9_]+)#i',$a,$matches)){
in the file administrator/components/com_hikashop/classes/filter.php and that should avoid that other issue.

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

  • Posts: 165
  • Thank you received: 3
10 years 10 months ago #139573

Thank you so much that worked!

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

Time to create page: 0.078 seconds
Powered by Kunena Forum