Post by Itendtomarketalso » Fri Feb 23, 2018 9:00 pm

Post by Itendtomarketalso » Fri Feb 23, 2018 8:55 pm

Hey,
I want to return products to be displayed on my category page between 2 price ranges. I have managed to get this working without a product having a special but not with. All code in the controller and view pages work fine, it's just the model.

This is the code I use within the getProducts method.

Code: Select all

if (!empty($data["PriceLow"]) && !empty($data["PriceHigh"])) {
    	$sql .=  " AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) >='". $data["PriceLow"] ." ' AND (CASE WHEN special IS NOT NULL THEN special WHEN discount IS NOT NULL THEN discount ELSE p.price END) <='". $data["PriceHigh"] ."'" ;		}  
Without the case it's prefect.
I saw a similar tread on stackoverflow but it didn't fix this, in fact it returned an error.

Also, when it works without the special using the following code:

Code: Select all

   	if (!empty($data["PriceLow"]) && !empty($data["PriceHigh"])) {
    	$sql .=  " AND p.price >='". $data["PriceLow"] ." ' AND p.price <='". $data["PriceHigh"] ."'" ;
		}  

It returns empty products, meaning the page navigation is available with products missing between. So page one can have 3 products, 2 five products, 4 no products and 5 two products


Posts

Joined
Wed Feb 21, 2018 5:47 pm

Post by straightlight » Sat Feb 24, 2018 4:44 am

I saw a similar tread on stackoverflow but it didn't fix this, in fact it returned an error.
What error? More information is needed.

The most generated errors being found on Opencart forum originates from contributed programming.

Regards,
Straightlight


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON


Posts

Joined
Wed Feb 21, 2018 5:47 pm
Who is online

Users browsing this forum: No registered users and 24 guests