markguinn / silverstripe-shop-search

Better search for Silverstripe's shop module with interchangeable adapters (currently mysql and solr) and filtering/faceting.
MIT License
5 stars 9 forks source link

ShopSearchSimple: [Notice] Undefined variable: data #3

Closed hex0id closed 9 years ago

hex0id commented 9 years ago

Configuration:

Tour:
  extensions:
    - HasStaticAttributes
    - ProductCategoryHelperMethods
    - VirtualFieldIndex

ShopSearch:
  searchable:
    - Tour
  facets:
    Price:
      Label: Price
      Type: range
      MinValue: 0
      MaxValue: 2000
      RangeMin: 0
      RangeMax: 2000
      LabelFormat: Currency
  sort_options:
    'score desc': 'Relevance'
    'SiteTree_Title asc': 'Alphabetical'

Destination_Controller:
  extensions:
    - FacetedCategory

VirtualFieldIndex:
  vfi_spec:
    Tour:
      Price:
        Type: simple
        Source: getPerPersonPrice
        DependsOn: all
        DBField: Currency
      Categories:
        Type: list
        DependsOn: all
        Source:
          - ParentID
          - ProductCategories.ID

FacetedCategory:
  facets:
    Price:
      Label: Price
      Type: range
      MinValue: 0
      MaxValue: 2000
      RangeMin: 0
      RangeMax: 2000
      LabelFormat: Currency
  auto_facet_attributes: true
  products_method: ToursShowable

Request:

/home/SearchForm?q=fcusa&f%5BParentID%5D=48&action_results=Go&flushtoken=e89b3a365c774966a8296aa4b60fe17b&flush=1

Error:

[Notice] Undefined variable: data
GET /home/SearchForm?q=fcusa&f%5BParentID%5D=48&action_results=Go&flushtoken=e89b3a365c774966a8296aa4b60fe17b&flush=1
Line 27 in /Users/alex/Sites/sporteos.dev/public/shop_search/code/ShopSearchControllerExtension.php
Source
18  }
19 
20 
21  /**
22   * @param array $data
23   * @return mixed
24   */
25  public function results(array $data) {
26      // do the search
27      $results  = ShopSearch::inst()->search($data);
28      $baseLink = $this->owner->getRequest()->getURL(false);
29 
30      // if there was only one category filter, remember it for the category dropdown to retain it's value
31      if (!ShopSearchForm::config()->disable_category_dropdown) {
32          $qs_filters  = (string)Config::inst()->get('ShopSearch', 'qs_filters');
33          $categoryKey = (string)ShopSearchForm::config()->category_field;
Trace
ShopSearchControllerExtension->results() 
call_user_func_array(Array,Array) 
Object.php:729
Object->__call(Results,Array) 
ViewableData.php:363
HomePage_Controller->Results() 
ViewableData.php:363
ViewableData->obj(Results,,,1,) 
ViewableData.php:403
ViewableData->cachedCall(Results,,) 
ViewableData.php:630
ViewableData_Customised->cachedCall(Results,) 
ViewableData.php:416
ViewableData->hasValue(Results,,1) 
call_user_func_array(Array,Array) 
SSViewer.php:179
SSViewer_Scope->__call(hasValue,Array) 
SSViewer.php:535
SSViewer_DataPresenter->__call(hasValue,Array) 
.cache.mysite.templates.Layout.Page_results.ss:29
SSViewer_DataPresenter->hasValue(Results,,1) 
.cache.mysite.templates.Layout.Page_results.ss:29
include(/Users/alex/Sites/sporteos.dev/public/silverstripe-cache/alex/.cache.mysite.templates.Layout.Page_results.ss) 
SSViewer.php:997
SSViewer->includeGeneratedTemplate(/Users/alex/Sites/sporteos.dev/public/silverstripe-cache/alex/.cache.mysite.templates.Layout.Page_results.ss,ViewableData_Customised,,Array,) 
SSViewer.php:1064
SSViewer->process(ViewableData_Customised,) 
SSViewer.php:1060
SSViewer->process(ViewableData_Customised,) 
ViewableData.php:336
ViewableData->renderWith(Array) 
ShopSearchControllerExtension.php:86
ShopSearchControllerExtension->results(Array,ShopSearchForm,SS_HTTPRequest) 
call_user_func_array(Array,Array) 
Object.php:729
Object->__call(results,Array) 
Form.php:374
HomePage_Controller->results(Array,ShopSearchForm,SS_HTTPRequest) 
Form.php:374
Form->httpSubmission(SS_HTTPRequest) 
RequestHandler.php:288
RequestHandler->handleAction(SS_HTTPRequest,httpSubmission) 
RequestHandler.php:200
RequestHandler->handleRequest(SS_HTTPRequest,DataModel) 
RequestHandler.php:222
RequestHandler->handleRequest(SS_HTTPRequest,DataModel) 
Controller.php:153
Controller->handleRequest(SS_HTTPRequest,DataModel) 
ContentController.php:198
ContentController->handleRequest(SS_HTTPRequest,DataModel) 
ModelAsController.php:78
ModelAsController->handleRequest(SS_HTTPRequest,DataModel) 
Director.php:367
Director::handleRequest(SS_HTTPRequest,Session,DataModel) 
Director.php:153
Director::direct(/home/SearchForm,DataModel) 
main.php:176
markguinn commented 9 years ago

Ah, I see what's happening here. $Results in the template is falling through the results() controller method. I think the template just needs some adjustment. Could you post your results template? Or are you just using the default one?

markguinn commented 9 years ago

Ok, I see what's going on here. There actually is no default search template included with the module because I've ended up building out a custom one every time I use it. I'm going tweak the returned format so it matches better with the Page_results.ss templates included in most themes and I'm also going to add some default templates. In the mean time, if you change your Page_results.ss template to use $Matches in the place of $Results it should solve your problem.

markguinn commented 9 years ago

Turns out this was an easy fix. Master branch should now work with the default search template.