Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Banner + Correct MPN for feed type 2 & 3 (#35)
Browse files Browse the repository at this point in the history
* DOOF-5

* limit attr groups on query

* Fix pagination problem on newer PrestaShop themes

* Add query_name parameter to facets

* Change layer type to reduce bandwith and conditional filters

* Floor and ceil min-max ranges

* Doofinder PrestaShop 1.7 initial release

* Fix Distinct tags

* Banner + Correct MPN for feed type 2 & 3
  • Loading branch information
danidomen authored and mdogo committed Oct 18, 2017
1 parent 06e3ab7 commit af51646
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 13 deletions.
4 changes: 2 additions & 2 deletions dfTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,8 @@ public static function getAvailableProductsForLanguage($id_lang, $id_shop, $limi
m.name AS manufacturer,
p.__MPN__ AS mpn,
p.ean13 AS ean13,
pa.__MPN__ AS mpn,
pa.ean13 AS ean13,
pl.name,
pl.description,
Expand Down
50 changes: 43 additions & 7 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ class Doofinder extends Module

const GS_SHORT_DESCRIPTION = 1;
const GS_LONG_DESCRIPTION = 2;
const VERSION = "2.3";
const VERSION = "2.2.8";
const YES = 1;
const NO = 0;

var $ps_layered_full_tree = true;
var $searchBanner = false;

public function __construct()
{
Expand Down Expand Up @@ -106,6 +107,7 @@ public function install()

if (!parent::install() ||
!$this->registerHook('header') ||
!$this->registerHook('displayFooter') ||
!$this->registerHook('displayMobileTopSiteMap'))
return false;

Expand All @@ -126,6 +128,10 @@ private function configureHookCommon($params)
'productLinks' => $this->_productLinks,
'self' => dirname(__FILE__),
));
$appendTo = Configuration::get('DF_APPEND_BANNER');
if($appendTo){
$this->smarty->assign('doofinder_banner_append', $appendTo);
}

return true;
}
Expand Down Expand Up @@ -160,16 +166,16 @@ public function hookHeader($params)
$this->context->controller->addJS(($this->_path) . 'js/doofinder_facets.js');
}
$this->context->controller->addJS(($this->_path) . 'js/js.cookie.js');
$this->context->controller->addJS(($this->_path) . 'js/doofinder-links.js');
$this->context->controller->addJQueryUI('ui.slider');
$this->context->controller->addJQueryUI('ui.accordion');
$this->context->controller->addJqueryPlugin('multiaccordion');
$this->context->controller->addJQueryUI('ui.sortable');
$this->context->controller->addJqueryPlugin('jscrollpane');

$this->context->controller->addJQueryPlugin('scrollTo');
}
$this->context->controller->addJS(($this->_path) . 'js/doofinder-links.js');
}

if(version_compare(_PS_VERSION_, '1.7', '<')){
return $this->display(__FILE__, 'views/templates/front/script_16.tpl');
}
Expand Down Expand Up @@ -329,7 +335,8 @@ protected function _updateConfiguration()
$cfgCodeStrValues = array(
'DF_EXTRA_CSS',
'DF_API_KEY',
'DF_CUSTOMEXPLODEATTR'
'DF_CUSTOMEXPLODEATTR',
'DF_APPEND_BANNER'
);

foreach ($cfgCodeStrValues as $optname)
Expand Down Expand Up @@ -486,6 +493,17 @@ protected function _displayForm()
$fields[] = $field;
$helper->fields_value[$optname] = $this->cfg($optname, self::NO);

// DF_APPEND_BANNER
$optname = 'DF_APPEND_BANNER';
$fields[] = array(
'label' => $this->l('"Append after" banner on Overwrite Search Page'),
'desc' => $this->l('Need to write "jQuery" identifier where to append after the banner. If empty or not valid, not banner will show. Example: "#content-wrapper #main h2"'),
'type' => 'text',
'name' => $optname,
'required' => false,
);
$helper->fields_value[$optname] = $this->cfg($optname);

// DF_ENABLE_HASH
$optname = 'DF_ENABLE_HASH';
$field = $this->getYesNoSelectFor($optname, $this->l('Enable security hash on feed URL'));
Expand Down Expand Up @@ -936,6 +954,7 @@ function cb($entry){
$result_properties = $result;
}
}
$this->searchBanner = $dfResults->getBanner();

if($return_facets){
return array('doofinder_results' => $dfResultsArray, 'total' => $dfResults->getProperty('total'),'result' => $result_properties, 'facets' => $dfResults->getFacets(), 'filters'=> $df->getFilters(),'df_query_name' => $dfResults->getProperty('query_name'));
Expand Down Expand Up @@ -1279,9 +1298,9 @@ function getSQLOnlyProductsWithAttributes(){
__ID_CATEGORY_DEFAULT__,
m.name AS manufacturer,
p.__MPN__ AS mpn,
p.ean13 AS ean13,
IF(isnull(pa.id_product), p.__MPN__ , GROUP_CONCAT(DISTINCT pa.__MPN__ SEPARATOR '/')) AS mpn,
IF(isnull(pa.id_product), p.ean13 , GROUP_CONCAT(DISTINCT pa.ean13 SEPARATOR '/')) AS ean13,
pl.name,
pl.description,
Expand Down Expand Up @@ -1361,5 +1380,22 @@ function slugify($text)

return $text;
}

public function hookDisplayFooter($params=false)
{
if(isset($this->context->controller->php_self) && $this->context->controller->php_self == 'search' ){
$appendTo = Configuration::get('DF_APPEND_BANNER');
if(!empty($this->searchBanner) && !empty($appendTo)){
$this->context->smarty->assign(array(
'doofinder_banner_image' => $this->searchBanner['image'],
'doofinder_banner_blank' => $this->searchBanner['blank'],
'doofinder_banner_id' => $this->searchBanner['id'],
'doofinder_banner_link' => $this->searchBanner['link'],
));
return $this->display(__FILE__, 'views/templates/hook/footer.tpl');
}
}
return false;
}

}
9 changes: 5 additions & 4 deletions js/doofinder-links.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ $(document).on('ready', function() {
});
});
}
});



if(doofinderAppendAfterBanner.length !== undefined && doofinderAppendAfterBanner.length > 0 && $(doofinderAppendAfterBanner).length !== undefined){
$(doofinderAppendAfterBanner).after($('.doofinder_dinamic_banner'));
$('.doofinder_dinamic_banner').show();
}
});
10 changes: 10 additions & 0 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ class DoofinderResults{
private $results = null;
private $facets = null;
private $filter = null;
private $banner = null;
public $status = null;

/**
Expand All @@ -620,6 +621,11 @@ function __construct($jsonString){
{
$this->results = $rawResults['results'];
}

if(isset($rawResults['banner']) && is_array($rawResults['banner']))
{
$this->banner = $rawResults['banner'];
}

// build a friendly filter array
$this->filter = array();
Expand Down Expand Up @@ -807,6 +813,10 @@ public function getAppliedFilters(){
public function isOk(){
return $this->status == self::SUCCESS;
}

public function getBanner(){
return $this->banner;
}
}


Expand Down
1 change: 1 addition & 0 deletions views/templates/front/script.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script>
var dfProductLinks = {$productLinks|json_encode nofilter};
var dfLinks = Object.keys(dfProductLinks);
var doofinderAppendAfterBanner = "{$doofinder_banner_append}";
</script>
{/if}
<!-- END OF TO REGISTER CLICKS -->
1 change: 1 addition & 0 deletions views/templates/front/script_16.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<script>
var dfProductLinks = {$productLinks|json_encode nofilter};
var dfLinks = Object.keys(dfProductLinks);
var doofinderAppendAfterBanner = "{$doofinder_banner_append}";
</script>
{/if}
<!-- END OF TO REGISTER CLICKS -->
4 changes: 4 additions & 0 deletions views/templates/hook/footer.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="doofinder_dinamic_banner" style="display:none" data-doofinder_banner_id="{$doofinder_banner_id}">
<a href="{$doofinder_banner_link}" {if $doofinder_banner_blank}target="_blank"{/if}><img src="{$doofinder_banner_image}" /></a>
</div>

0 comments on commit af51646

Please sign in to comment.