Adding a filter plugin

  • Posts: 28
  • Thank you received: 0
9 years 1 week ago #220307

Can I extend the filter classes without editing the filter.php file? I want to add a new filter search function to getProductList() but I don't want to lose the ability to upgrade easily.

Or is there filter plugins?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 1 week ago #220347

You can extend it with a system plugin yes.
In fact, you can extend any class in the folders classes and helpers of the backend like that. You can find more information here:
www.hikashop.com/forum/2-general-talk-ab...custom-features.html

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

  • Posts: 28
  • Thank you received: 0
9 years 1 week ago #220676

okay I don't know how to do it. I don't want to replace the whole class, only one of the functions, getproductlist.
Something like this.

class hikashopFilterClass extends hikashopClass {
function getProductList(){ echo('test'; }
}

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 1 week ago #220733

That's not a problem.
You can have such code in your plugin:

include(HIKASHOP_BACK.'classes'.DS.'filter.php');
class hikashopFilterClassOverride extends hikashopFilterClass{
function getProductList(&$parent, $filters){ echo 'test'; }
}
The hikashop_get function which loads the classes will automatically load the override class instead of the normal class if it is already initialized in memory thanks to your system plugin.

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

  • Posts: 28
  • Thank you received: 0
9 years 1 week ago #220764

Thanks, but I'm way over my head here as I can't seem to modify the existing output list.

Basically I am trying to look for a URL variable (eg &something=true) and do a query to generate my own list of products instead of what the current page is doing.

I try to override GetProductList to intercept the output but it doesn't change anything.

I need to be able to generate a list of products and apply the same 'listing_img_desc.php' templates to the output to keep it all looking the same.

Last edit: 9 years 1 week ago by terryt.

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 week ago #220806

Hi,

Another solution could be to edit the view "product / listing_div" and add code like:

if(JRequest::getVar('something','','GET') == true){
	$products = array();
	// Get the products
	/* Add your code there */
	
	// Replace the content of $this->rows
	$this->rows = $products;
}

That way, you can have the desired products thanks to an url parameter, filters are not mandatory.

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

  • Posts: 28
  • Thank you received: 0
9 years 1 week ago #220886

Yes but is there a function to get the product row data by supplying a list of product id?

And the pagination will be wrong wont it?

I am trying to use the helper API but I don't know if this would be the correct way to get product id #66.

$helperProduct = hikashop::get('helper.product');
$this->rows = $helperProduct->processRequest('', '/products/:id', $this-params, array('ids'=>array(66));

Last edit: 9 years 1 week ago by terryt. Reason: details

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

  • Posts: 13201
  • Thank you received: 2322
9 years 1 week ago #220934

Hi,

For the pagination, you can change the "$this->pageInfo" PHP object values.

To get the products from ids, you can use that code:

$ids = array('1','2','x');
$productClass = hikashop_get('class.product');
$productClass->getProducts($ids);

var_dump($productClass->products);

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

  • Posts: 28
  • Thank you received: 0
9 years 6 days ago #221121

Can't I run the product ID's through the helper? I need some way to check the product IDs are valid for the current visitor.
With hikashop_get('class.product') the prices come out as $0.00

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 6 days ago #221211

Hi,

In each entry of the $productClass->products array, you have a "prices" attribute which itself is an array of all the prices of the product.
That way, you can access the prices of the products and use them.

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

  • Posts: 28
  • Thank you received: 0
9 years 5 days ago #221255

Yes I can see those, but that doesn't explain why the prices are $0 and the images are missing when outputting the row. It seesm like they need to be sent through some function to be processed for row output but I don't know what that is. That is why I thought the helper function would be more useful because it would probably be intended for that, but no one uses it?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 5 days ago #221358

I don't see why the prices would be 0. The prices array should contain all the data of each price of the product available for the current customer.
Could you do a var_dump of the prices attribute ?
What do you get ?

The currencyHelper->format function call that you see in a lot of views is just to display the price_value of the price nicely, but the amount is already in there. So it's not necessary to use it.

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

  • Posts: 28
  • Thank you received: 0
9 years 2 days ago #221514

Here is a whole product.

object(stdClass)#825 (59) {
	["product_id"]=> string(2) "40"
	["product_parent_id"]=> string(1) "0"
	["product_name"]=> string(13) "Vanilla Fudge"
	["product_description"]=> string(27) ""
	["product_quantity"]=> string(1) "0"
	["product_code"]=> string(16) "FF_Vanilla Fudge"
	["product_published"]=> string(1) "1"
	["product_hit"]=> string(1) "3"
	["product_created"]=> string(10) "1286498642"
	["product_sale_start"]=> string(10) "1286492400"
	["product_sale_end"]=> string(1) "0"
	["product_delay_id"]=> string(1) "0"
	["product_tax_id"]=> string(2) "11"
	["product_type"]=> string(4) "main"
	["product_vendor_id"]=> string(1) "0"
	["product_manufacturer_id"]=> string(2) "38"
	["product_url"]=> string(0) ""
	["product_weight"]=> string(5) "0.000"
	["product_keywords"]=> string(0) ""
	["product_weight_unit"]=> string(2) "lb"
	["product_modified"]=> string(10) "1447656993"
	["product_meta_description"]=> string(0) ""
	["product_dimension_unit"]=> string(2) "in"
	["product_width"]=> string(5) "0.000"
	["product_length"]=> string(5) "0.000"
	["product_height"]=> string(5) "0.000"
	["product_max_per_order"]=> string(1) "0"
	["product_access"]=> string(3) "all"
	["product_group_after_purchase"]=> string(0) ""
	["product_min_per_order"]=> string(1) "0"
	["product_contact"]=> string(1) "0"
	["product_display_quantity_field"]=> string(1) "0"
	["product_last_seen_date"]=> string(10) "1447901881"
	["product_sales"]=> string(1) "5"
	["product_waitlist"]=> string(1) "0"
	["product_layout"]=> string(0) ""
	["product_average_score"]=> string(1) "0"
	["product_total_vote"]=> string(1) "0"
	["product_page_title"]=> string(0) ""
	["product_alias"]=> string(13) "vanilla-fudge"
	["product_price_percentage"]=> string(9) "0.0000000"
	["product_msrp"]=> string(9) "0.0000000"
	["product_canonical"]=> string(42) "buy/ordering/product/40-vanilla-fudge.html"
	["product_warehouse_id"]=> string(1) "0"
	["product_quantity_layout"]=> string(0) ""
	["ingredients"]=> string(0) ""
	["intro"]=> string(0) ""
	["glutenfree"]=> string(5) "Vegan"
	["special"]=> string(0) ""
	["prices"]=> array(1) {
		[0]=> 	object(stdClass)#830 (7) {
			["price_id"]=> 		string(2) "32"
			["price_currency_id"]=> 		string(1) "6"
			["price_product_id"]=> 		string(2) "40"
			["price_value"]=> 		string(7) "8.63636"
			["price_min_quantity"]=> 		string(1) "0"
			["price_access"]=> 		string(3) "all"
			["price_site_id"]=> 		string(0) ""
		}
	}
	["files"]=> array(0) {
	}
	["images"]=> array(1) {
		[0]=> 	object(stdClass)#832 (9) {
			["file_id"]=> 		string(2) "15"
			["file_name"]=> 		string(0) ""
			["file_description"]=> 		string(0) ""
			["file_path"]=> 		string(31) "Vanilla_Fudge_4cae6952a2a4c.jpg"
			["file_type"]=> 		string(7) "product"
			["file_ref_id"]=> 		string(2) "40"
			["file_free_download"]=> 		string(1) "0"
			["file_ordering"]=> 		string(1) "0"
			["file_limit"]=> 		string(1) "0"
		}
	}
	["variant_links"]=> array(0) {
	}
	["translations"]=> array(0) {
	}
	["categories"]=> array(1) {
		[0]=> 	string(2) "41"
	}
	["categories_ordering"]=> array(1) {
		[0]=> 	string(1) "3"
	}
	["related"]=> array(0) {
	}
	["options"]=> array(0) {
	}
	["variants"]=> array(0) {
	}
}

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 2 days ago #221566

Hi,

So the price is not 0. You can see there that the price is 8.63636:
take.ms/MSDA2
You can access it like that:

$product->prices[0]->price_value

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

  • Posts: 28
  • Thank you received: 0
9 years 2 days ago #221584

Yes I know that, but you said I could replace the old $this->rows in the listing.php with the new rows from the getProducts function. I assume it would also use the prices since they are the same object layout.

Do I need to replace $this->rows[x]->prices, with the ones from each new row too?

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 1 day ago #221602

Hi,

I've reread the whole thread but I couldn't find any mention of "replacing" from us.

Xavier gave you some code on how to get the products data based on the ids of the products.
You then replied that the prices where 0.
We then asked for a var_dump of the products in order to check on that, as that should not happen.
And in the var_dump you provided, the price is not 0.

So I'm a bit lost. I don't understand what replacing you're trying to do, where your trying to do it, or why you're trying to do it ?

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

  • Posts: 28
  • Thank you received: 0
9 years 1 day ago #221705

In this post - www.hikashop.com/support/forum/filters-s...r-plugin.html#220806
// Replace the content of $this->rows
$this->rows = $products;

I am trying to replace the product list with a new product list of specific product IDs that I select from the database while keeping the same template style.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 1 day ago #221706

Hi,

The problem is that the getProducts function gives you the data of the product taken from the database.
It doesn't compute all the prices based on the tax rules, the discount rules, etc.
Thus the system might try to use a price which handle been computed if you just copy the rows "as is".
So what you can do is call the getPrices function of the class.currency for each product so that it will compute the prices for them to be displayed by the view of the frontend.

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

  • Posts: 28
  • Thank you received: 0
9 years 1 day ago #221865

That is the kind of thing I was trying to avoid. I don't want to reinvent the whole process if there is some way of doing it as if it was a regular listing page with one or two functions.

Otherwise I have to get products, get prices, get images, get badges and some other steps I am not aware of that will cause problems later.

Why can't I use hikashop::get('helper.product'); for this? - I don't know how to use it but it doesn't seem to work.

BTW getPrices() is wrong, you need to use getListingPrices() for consistent layout

Last edit: 9 years 21 hours ago by terryt.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
9 years 10 hours ago #221871

Hi,

Well, the getProducts function is the closest we have of a function to easily load all the data of a bunch of products.
It is used for the export, copy and mass action systems, which don't require any calculation of the prices.
It's either that, or you basically have to do all the queries and processing manually, like in the listing function of the components/com_hikashop/views/product/view.html.php file.
Why there is no easy function to do that same thing in the class.product ? Well that's because the only place where that is needed is in that view file so there was no point in moving the code in the class.

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

Time to create page: 0.110 seconds
Powered by Kunena Forum