Skip to content

Commit

Permalink
PATCH: fixing home page second hand search form
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnysideup committed Jul 19, 2017
1 parent 2fe098f commit ead9ad5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion code/ProductGroup.php
Expand Up @@ -1848,7 +1848,7 @@ public function searchresults($request)
if (!$resultArray || !count($resultArray)) {
$resultArray = array(0 => 0);
}
$title = ProductSearchForm::last_search_phrase();
$title = ProductSearchForm::get_last_search_phrase();
if($title) {
$title = _t('Ecommerce.SEARCH_FOR', 'search for: ').substr($title, 0, 25);
}
Expand Down
34 changes: 32 additions & 2 deletions code/forms/ProductSearchForm.php
Expand Up @@ -10,7 +10,7 @@ class ProductSearchForm extends Form
*
* @return string
*/
public static function last_search_phrase()
public static function get_last_search_phrase()
{
$string = '';
$oldData = Session::get(Config::inst()->get('ProductSearchForm', 'form_data_session_variable'));
Expand All @@ -24,6 +24,20 @@ public static function last_search_phrase()
return trim($string);
}

/**
*
* @param string $phrase
*/
public static function set_last_search_phrase($phrase)
{
$oldData = Session::get(Config::inst()->get('ProductSearchForm', 'form_data_session_variable'));
if ($oldData && (is_array($oldData) || is_object($oldData))) {
$oldData['ShortKeyword'] = $phrase;
$oldData['Keyword'] = $phrase;
}
Session::set(Config::inst()->get('ProductSearchForm', 'form_data_session_variable'), $phrase);
}

/**
* set to TRUE to show the search logic.
*
Expand Down Expand Up @@ -244,6 +258,7 @@ public function __construct($controller, $name, $nameOfProductsBeingSearched = '
$requiredFields = array();
$validator = ProductSearchForm_Validator::create($requiredFields);
parent::__construct($controller, $name, $fields, $actions, $validator);
$this->setFormMethod('get');
//extensions need to be set after __construct
//extension point
$this->extend('updateFields', $fields);
Expand All @@ -265,6 +280,7 @@ public function __construct($controller, $name, $nameOfProductsBeingSearched = '
public function doProductSearchForm($data, $form)
{
$searchHistoryObject = null;
$immediateRedirectLink = '';
if (!$this->maximumNumberOfResults) {
$this->maximumNumberOfResults = EcommerceConfig::get('ProductGroup', 'maximum_number_of_products_to_list');
}
Expand Down Expand Up @@ -293,10 +309,19 @@ public function doProductSearchForm($data, $form)
$limitToCurrentSection = false;
if (isset($data['SearchOnlyFieldsInThisSection']) && $data['SearchOnlyFieldsInThisSection']) {
$limitToCurrentSection = true;
if(! $this->productsToSearch) {
$controller = Controller::curr();
if($controller) {
$this->productsToSearch = $controller->Products();
}
}
if ($this->productsToSearch instanceof DataList) {
$this->productsToSearch = $this->productsToSearch->map('ID', 'ID')->toArray();
}
$baseList = $baseList->filter(array('ID' => $this->productsToSearch));
//last resort
if($this->productsToSearch) {
$baseList = $baseList->filter(array('ID' => $this->productsToSearch));
}
}
if (isset($data['MinimumPrice']) && $data['MinimumPrice']) {
$baseList = $baseList->filter(array('Price:GreaterThanOrEqual' => floatval($data['MinimumPrice'])));
Expand All @@ -307,20 +332,25 @@ public function doProductSearchForm($data, $form)
//defining some variables
$isKeywordSearch = false;
if ($this->debug) {
if($this->productsToSearch) {
$this->debugOutput('<hr /><h3>PRODUCTS TO SEARCH</h3><pre>'.str_replace($this->sqlWords, array_flip($this->sqlWords), $this->productsToSearch->sql()).'</pre>');
}
$this->debugOutput('<hr /><h3>BASE LIST</h3><pre>'.str_replace($this->sqlWords, array_flip($this->sqlWords), $baseList->sql()).'</pre>');
}
//KEYWORD SEARCH - only bother if we have any keywords and results at all ...
if (isset($data['ShortKeyword']) && !isset($data['Keyword'])) {
$data['Keyword'] = $data['ShortKeyword'];
}
if (isset($data['Keyword']) && $keywordPhrase = $data['Keyword']) {
echo 'AAAAAAAAAAA';
if ($baseList->count()) {
if (strlen($keywordPhrase) > 1) {
$isKeywordSearch = true;
$immediateRedirectLink = '';
$this->resultArrayPos = 0;
$this->resultArray = array();

$this->debugOutput('<hr /><h3>Raw Keyword '.$keywordPhrase.'</h3><pre>');
$keywordPhrase = Convert::raw2sql($keywordPhrase);
$keywordPhrase = strtolower($keywordPhrase);

Expand Down

0 comments on commit ead9ad5

Please sign in to comment.