VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: caesarsk on October 21, 2018, 12:15:48 PM

Title: override VM module function (sortSearchListQuery from modules/product.php)
Post by: caesarsk on October 21, 2018, 12:15:48 PM
Hi all,

can be override VM core module function by my own (for example by vmcustom or system plugin)? I dont want to modify core file after each update.
I need modify function "sortSearchListQuery" from file "/administrator/com_virtuemart/modules/product.php" (add some own product sorting items).

thx for advice
Title: Re: override VM module function (sortSearchListQuery from modules/product.php)
Post by: GJC Web Design on October 21, 2018, 13:11:03 PM
you can add your own myproducts.php in the models folder and extend so

class VirtueMartModelMyproduct extends VirtueMartModelProduct {

      public function getProductListing ($group = FALSE, $nbrReturnProducts = FALSE, $withCalc = TRUE, $onlyPublished = TRUE, $single = FALSE, $filterCategory = TRUE, $category_id = 0, $filterManufacturer = TRUE, $manufacturer_id = 0) {
//blah blah

     $ids = $this->sortSearchListQuery ($onlyPublished, $this->virtuemart_category_id, $group, $nbrReturnProducts);
    return ids;

}

   function sortSearchListQuery ($onlyPublished = TRUE, $virtuemart_category_id = FALSE, $group = FALSE, $nbrReturnProducts = FALSE, $instock = 0) {

/* my code*/

    return $product_ids;


}
}

and call it by

$myproductModel = VmModel::getModel('Myproduct');

$products = $myproductModel->getProductListing(false,$pnumber, true, true, true, false, $catids, false, 0, $instock);

you get the idea

Title: Re: override VM module function (sortSearchListQuery from modules/product.php)
Post by: caesarsk on October 21, 2018, 13:54:33 PM
ou, nice. thx you very much
Title: Re: override VM module function (sortSearchListQuery from modules/product.php)
Post by: Studio 42 on October 21, 2018, 17:39:40 PM
Or you can do your own function, eg if you need to get ordered product by user or cart products ...