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

Commit

Permalink
Avoids empty title and description
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoslado committed Dec 3, 2015
1 parent 503ab09 commit a62df56
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 9 deletions.
4 changes: 2 additions & 2 deletions dfTools.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,11 @@ function cb2($matches){
$text = html_entity_decode($text, ENT_QUOTES, "ISO-8859-1");
$text = preg_replace_callback(
'/&#(\d+);/mu',
cb1,
'cb1',
$text); // decimal notation
$text = preg_replace_callback(
'/&#x([a-f0-9]+);/miu',
cb2,
'cb2',
$text); // hex notation
$text = str_replace("><", "> <", $text);
$text = preg_replace('/\<br(\s*)?\/?\>/i', " ", $text);
Expand Down
Binary file modified dist/doofinder-p1.5-latest.zip
Binary file not shown.
46 changes: 41 additions & 5 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Doofinder extends Module

const GS_SHORT_DESCRIPTION = 1;
const GS_LONG_DESCRIPTION = 2;
const VERSION = "2.0.11";
const VERSION = "2.0.13";

const YES = 1;
const NO = 0;
Expand Down Expand Up @@ -150,7 +150,8 @@ protected function _updateConfiguration()
'DF_FEED_FULL_PATH' => $this->l('Export full categories path in the feed'),
'DF_SHOW_PRODUCT_VARIATIONS' => $this->l('Include product variations in feed'),
'DF_SHOW_PRODUCT_FEATURES' => $this->l('Include product features in feed'),
'DF_OWSEARCH' => $this->l('Overwrite Search page with Doofinder results')
'DF_OWSEARCH' => $this->l('Overwrite Search page with Doofinder results'),
'DF_DEBUG' => $this->l('Activate to write debug info in file.')
);

foreach ($cfgIntValues as $optname => $optname_alt)
Expand Down Expand Up @@ -367,6 +368,12 @@ protected function _displayForm()
$fields[] = $field;
$helper->fields_value[$optname] = $this->cfg($optname, self::NO);

// DF_DEBUG
$optname = 'DF_DEBUG';
$field = $this->getYesNoSelectFor($optname, $this->l('Debug Mode. Write info logs in doofinder.log file.'));
$fields[] = $field;
$helper->fields_value[$optname] = $this->cfg($optname, self::NO);

// DF_GS_MPN_FIELD
$optname = 'DF_GS_MPN_FIELD';
$fields[] = array(
Expand Down Expand Up @@ -574,14 +581,22 @@ public function cfg($key, $default=null)
return dfTools::cfg(null, $key, $default);
}
}

private function debug($message){
error_log("$message\n", 3, dirname(__FILE__).'/doofinder.log');
}
public function searchOnApi($string,$page=1,$page_size=12,$timeout=8000){
$debug = Configuration::get('DF_DEBUG', null);
if (isset($debug) && $debug){
$this->debug('Search On API Start');
}

if(!class_exists('DoofinderApi')){
include_once dirname(__FILE__) . '/lib/doofinder_api.php';
}
$hash_id = Configuration::get('DF_HASHID', null);
$api_key = Configuration::get('DF_API_KEY', null);
$show_variations = Configuration::get('DF_SHOW_PRODUCT_VARIATIONS', null);


if($hash_id && $api_key){
$df = new DoofinderApi($hash_id, $api_key);
Expand Down Expand Up @@ -619,13 +634,18 @@ function cb($entry){
}

}
$map = array_map(cb, $dfResultsArray);
$map = array_map('cb', $dfResultsArray);
$product_pool = implode(', ', $map);

// To avoid SQL errors.
if($product_pool == ""){
$product_pool = "0";
}

if (isset($debug) && $debug){
$this->debug("Product Pool: $product_pool");
}

$product_pool_attributes = implode(',', $product_pool_attributes);

if (!isset($context) || !$context)
Expand All @@ -634,6 +654,10 @@ function cb($entry){
if ($product_pool_attributes == ""){
$product_pool_attributes = "0";
}

if (isset($debug) && $debug){
$this->debug("Product Pool Attributes: $product_pool_attributes");
}
$db = Db::getInstance(_PS_USE_SQL_SLAVE_);
$id_lang = $context->language->id;
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity,
Expand Down Expand Up @@ -663,7 +687,19 @@ function cb($entry){
(($show_variations)? ' AND (product_attribute_shop.`id_product_attribute` IS NULL OR product_attribute_shop.`id_product_attribute` IN ('.$product_pool_attributes.')) ':'').
' GROUP BY product_shop.id_product '.(($show_variations)?' , product_attribute_shop.`id_product_attribute` ':'').
' ORDER BY FIELD (p.`id_product`,'.$product_pool.') '.(($show_variations)?' , FIELD (product_attribute_shop.`id_product_attribute`,'.$product_pool_attributes.')':'');
$result = $db->executeS($sql);
if (isset($debug) && $debug){
$this->debug("SQL: $sql");
}
$result = $db->executeS($sql);
if (isset($debug) && $debug && $result){
$out = "";
foreach($result as $elem){
$out .= "ID: ".$elem['id_product']. " ATTRIBUTE: ".$elem['id_product_attribute']."\n";
}

$this->debug("RESULT: $out") ;
}


if (!$result)
return false;
Expand Down
10 changes: 9 additions & 1 deletion feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
$cfg_mod_rewrite = dfTools::cfg($shop->id, 'PS_REWRITING_SETTINGS', Doofinder::YES);
$cfg_product_variations = dfTools::cfg($shop->id, 'DF_SHOW_PRODUCT_VARIATIONS');
$cfg_product_features = dfTools::cfg($shop->id, 'DF_SHOW_PRODUCT_FEATURES');
$cfg_debug = dfTools::cfg($shop->id, 'DF_DEBUG');
$cfg_features_shown = explode(',', dfTools::cfg($shop->id, 'DF_FEATURES_SHOWN'));

$debug = dfTools::getBooleanFromRequest('debug', false);
Expand All @@ -76,6 +77,11 @@
ini_set('display_errors', 1);
}

if ($cfg_debug){
error_log("Starting feed.\n", 3, dirname(__FILE__).'/doofinder.log');
}


// OUTPUT
if (isset($_SERVER['HTTPS']))
header('Strict-Transport-Security: max-age=500');
Expand Down Expand Up @@ -128,7 +134,9 @@
foreach (dfTools::getAvailableProductsForLanguage($lang->id, $shop->id, $limit, $offset) as $row)
{

if(intval($row['id_product']) > 0){
if(intval($row['id_product']) > 0 &&
(isset($row['title']) && $row['title'] != "" ||
isset($row['description']) && $row['description'] != "")){
// ID, TITLE, LINK

if($cfg_product_variations && isset($row['id_product_attribute']) and intval($row['id_product_attribute']) > 0){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "doofinder-for-prestashop",
"version": "2.0.11",
"version": "2.0.13",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-clean": "^0.5.0",
Expand Down

0 comments on commit a62df56

Please sign in to comment.