Please help us to make AbanteCart Ideal Open Source Ecommerce Solution for everyone.

Support AbanteCart eCommerce

Author Topic: How to get and return data to Listing_Grid Hook  (Read 1528 times)

Offline dhigz

  • Newbie
  • *
  • Posts: 27
  • Karma: +8/-0
    • View Profile
    • My AbanteCart Site:
How to get and return data to Listing_Grid Hook
« on: September 08, 2016, 07:37:09 PM »
Hi,

What I am trying to is to add an additional drop down to the product search/filer form on the catalog/products page. No problem adding the field to the form through a hook. The problem is getting and returning data to the listing_grid controller with any form of hook (on, before, etc. & InitData, ProcessData, etc.)

With a standard controller, you can get data from the controller with $that->view->getData when the controller data is in the form of $this->data, $this->post, etc.. You can transfer data from the hook to the controller with $that->view->assign or $that->view->batchAssign($this->data). You can even resort to sessions.

Keeping in mind that we do not want to unnecessarily edit the base controller file, how do you transfer data back and forth with a listing_grid controller? Specifically how would I get filter data in and/or the response back? I could not find anything in the Developer guide that helps.

What have I tried?
1 - With the original goal I tried to add the new field value to the filter value with onControllerResponsesListingGridProduct_InitData and onControllerResponsesListingGridProduct_UpdateData. This is useless as anything you submit is overwritten in the function.

2 - Rewrote the entire ControllerResponsesListingGridProduct under onControllerResponsesListingGridProduct_UpdateData starting off by setting the original response to an empty array. The final command of the hook function is to set the output. I also created another query with parameters added for my filter data and call this query in the hook function.

Now what happens is both run, first the original then the hook. Tried using InitData, same result just the hook runs first then the base function. No matter which option, the output is still the result of the base controller function.

3 - Tried  aroundControllerResponsesListingGridProduct_InitData. Around does not work.

The only way I got it to work is commenting out  $this->load->library('json'); and $this->response->setOutput(AJson::encode($response)); in the base controller. Exactly what I want to avoid.


Any suggestions, ideas?



« Last Edit: September 08, 2016, 07:44:56 PM by dhigz »
Don Higbee

Offline abolabo

  • core-developer
  • Administrator
  • Hero Member
  • *****
  • Posts: 1712
  • Karma: +227/-10
  • web for all, all for web!
    • View Profile
    • AbanteCart
Re: How to get and return data to Listing_Grid Hook
« Reply #1 on: September 09, 2016, 03:56:14 AM »
Hello.
You should to replace listing_grid response controller with your own controller (listing_grid/your_products)  via hook.
Just hook to common/listing_grid controller and update url.

Something like this

Code: [Select]
public function onControllerCommonListingGrid_InitData(){
                $that = $this->baseObject;
$data = &$this->baseObject->data;
//skip other grids
if ($data['table_id'] == 'product_grid'){
                          $data['url'] = $that->html->getSecureURL('listing_grid/your_products', $params);
                          $data['colModel'] = array (.....

                 }
................

and then call your own model inside your controller.
« Last Edit: September 09, 2016, 08:25:02 AM by abolabo »
“No one is useless in this world who lightens the burdens of another.”
― Charles Dickens

Offline dhigz

  • Newbie
  • *
  • Posts: 27
  • Karma: +8/-0
    • View Profile
    • My AbanteCart Site:
Re: How to get and return data to Listing_Grid Hook
« Reply #2 on: September 09, 2016, 06:55:09 PM »


Wow, that worked great. Didn't even think about using CommonListingGrid. I'm going to use this for some other added features.


Thanks for your help Dimitri.
Don Higbee

 

LoliPromDress.com Prom dresses 2018