//// Merge -> revision 8290

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@8295 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
tDidierjean
2011-09-01 09:53:43 +00:00
parent d27c0b3b7d
commit c2258ae8e9
50 changed files with 431 additions and 256 deletions
+22 -86
View File
@@ -52,7 +52,6 @@ class BlockLayered extends Module
if ($result = parent::install() AND $this->registerHook('leftColumn') AND $this->registerHook('header') AND $this->registerHook('footer')
AND $this->registerHook('categoryAddition') AND $this->registerHook('categoryUpdate') AND $this->registerHook('categoryDeletion'))
{
Configuration::updateValue('PS_LAYERED_SHARE', 0);
Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', 0);
Configuration::updateValue('PS_LAYERED_SHOW_QTIES', 1);
@@ -66,11 +65,8 @@ class BlockLayered extends Module
public function uninstall()
{
/* Delete all configurations */
Configuration::deleteByName('PS_LAYERED_SHARE');
Configuration::deleteByName('PS_LAYERED_HIDE_0_VALUES');
Configuration::deleteByName('PS_LAYERED_SHOW_QTIES');
Configuration::deleteByName('PS_LAYERED_BITLY_USERNAME');
Configuration::deleteByName('PS_LAYERED_BITLY_API_KEY');
return parent::uninstall();
}
@@ -165,6 +161,11 @@ class BlockLayered extends Module
if (sizeof($_POST['categoryBox']))
{
/* Clean categoryBox before use */
if (isset($_POST['categoryBox']) AND is_array($_POST['categoryBox']))
foreach ($_POST['categoryBox'] AS &$value)
$value = (int)$value;
Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_category WHERE id_category IN ('.implode(',', $_POST['categoryBox']).')');
$filterValues = array();
@@ -208,20 +209,9 @@ class BlockLayered extends Module
}
}
elseif (Tools::isSubmit('submitLayeredSettings'))
{
if (Tools::getValue('share_url'))
{
if (Tools::getValue('bitly_username') == '')
$errors[] = $this->l('Bit.ly username is empty');
if (Tools::getValue('bitly_api_key') == '')
$errors[] = $this->l('Bit.ly api_key is empty');
}
{
if (!sizeof($errors))
{
Configuration::updateValue('PS_LAYERED_BITLY_USERNAME', Tools::getValue('bitly_username'));
Configuration::updateValue('PS_LAYERED_BITLY_API_KEY', Tools::getValue('bitly_api_key'));
Configuration::updateValue('PS_LAYERED_SHARE', Tools::getValue('share_url'));
Configuration::updateValue('PS_LAYERED_HIDE_0_VALUES', Tools::getValue('ps_layered_hide_0_values'));
Configuration::updateValue('PS_LAYERED_SHOW_QTIES', Tools::getValue('ps_layered_show_qties'));
@@ -268,22 +258,6 @@ class BlockLayered extends Module
}
$html .= '
<script type="text/javascript">
$(document).ready(function()
{
$(\'.share_url\').change(function(){
toggleBitly();
});
toggleBitly();
function toggleBitly(){
if ($(\'#share_url_on\').attr(\'checked\'))
$(\'#bitly\').slideDown();
else
$(\'#bitly\').slideUp();
}
});
</script>
<h2>'.$this->l('Layered navigation').'</h2>
<fieldset class="width4">
<legend><img src="../img/admin/cog.gif" alt="" />'.$this->l('Existing filters templates').'</legend>';
@@ -573,29 +547,8 @@ class BlockLayered extends Module
<img src="../img/admin/disabled.gif" alt="'.$this->l('No').'" title="'.$this->l('No').'" style="margin-left: 10px;" />
'.$this->l('No').' <input type="radio" name="ps_layered_show_qties" value="0" '.(!Configuration::get('PS_LAYERED_SHOW_QTIES') ? 'checked="checked"' : '').' />
</td>
</tr>
<tr>
<td style="text-align: right;">'.$this->l('Allow customers to share URLs').'</td>
<td>
<label class="t" for="share_url_on"><img src="../img/admin/enabled.gif" alt="Yes" title="Yes"></label>
'.$this->l('Yes').' <input type="radio" id="share_url_on" name="share_url" class="share_url" value="1" '.(Configuration::get('PS_LAYERED_SHARE') ? 'checked="checked"' : '').'>
<label class="t" for="share_url_off"><img src="../img/admin/disabled.gif" alt="No" title="No" style="margin-left: 10px;"></label>
'.$this->l('No').' <input type="radio" id="share_url_off" name="share_url" class="share_url" value="0" '.(!Configuration::get('PS_LAYERED_SHARE') ? 'checked="checked"' : '').'>
</td>
</tr>
</tr>
</table>
<div id="bitly">
<p>'.$this->l('To offer your customers short links, create an account on bit.ly, then copy and paste login and API key.').'
<a style="text-decoration:underline" href="http://bit.ly/a/sign_up">'.$this->l('Sign Up').'</a></p>
<label>'.$this->l('Login bit.ly').'</label>
<div class="margin-form">
<input type="text" name="bitly_username" value="'. Tools::getValue('bitly_username', Configuration::get('PS_LAYERED_BITLY_USERNAME')).'">
</div>
<label>'.$this->l('API Key bit.ly').'</label>
<div class="margin-form">
<input type="text" name="bitly_api_key" value="'.Tools::getValue('bitly_api_key', Configuration::get('PS_LAYERED_BITLY_API_KEY')).'">
</div>
</div>
<p style="text-align: center;"><input type="submit" class="button" name="submitLayeredSettings" value="'.$this->l('Save configuration').'" /></p>
</form>
</fieldset>';
@@ -723,7 +676,7 @@ class BlockLayered extends Module
/* Return only the number of products */
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(p.`id_product`) AS total
SELECT COUNT(p.`id_product`) total
FROM `'._DB_PREFIX_.'product` p
WHERE 1 '.$queryFilters);
@@ -739,12 +692,12 @@ class BlockLayered extends Module
'.Product::sqlStock('p', 0).'
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = p.id_product AND i.cover = 1)
LEFT JOIN '._DB_PREFIX_.'image_lang il ON (i.id_image = il.id_image AND il.id_lang = '.(int)$this->context->language->id.')
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
LEFT JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer)
WHERE p.`active` = 1
AND pl.id_lang = '.(int)$this->context->language->id
.$queryFilters.
' ORDER BY '.Tools::getProductsOrder('by', Tools::getValue('orderby')).' '.Tools::getProductsOrder('way', Tools::getValue('orderway')).
' LIMIT '.(((int)(Tools::getValue('p', 1)) - 1) * $n.','.$n);
' LIMIT '.(((int)(Tools::getValue('p', 1)) - 1) * $n.','.$n);
$this->products = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
return $this->products;
@@ -780,12 +733,12 @@ class BlockLayered extends Module
$whereC = rtrim($whereC, 'OR ');
$productsSQL = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT p.`id_product`, p.`condition`, p.`id_manufacturer`, p.`weight`, stock.quantity,
(SELECT GROUP_CONCAT(`id_category`) FROM `'._DB_PREFIX_.'category_product` cp WHERE cp.`id_product` = p.`id_product`) as ids_cat,
(SELECT GROUP_CONCAT(`id_feature_value`) FROM `'._DB_PREFIX_.'feature_product` fp WHERE fp.`id_product` = p.`id_product`) as ids_feat,
(SELECT GROUP_CONCAT(`id_category`) FROM `'._DB_PREFIX_.'category_product` cp WHERE cp.`id_product` = p.`id_product`) ids_cat,
(SELECT GROUP_CONCAT(`id_feature_value`) FROM `'._DB_PREFIX_.'feature_product` fp WHERE fp.`id_product` = p.`id_product`) ids_feat,
(SELECT GROUP_CONCAT(DISTINCT(pac.`id_attribute`))
FROM `'._DB_PREFIX_.'product_attribute_combination` pac
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product_attribute` = pac.`id_product_attribute`)
WHERE pa.`id_product` = p.`id_product` ) as ids_attr
WHERE pa.`id_product` = p.`id_product`) ids_attr
FROM '._DB_PREFIX_.'product p
'.Product::sqlStock('p', 0).'
WHERE p.`active` = 1 AND p.`id_product` IN ( SELECT id_product FROM `'._DB_PREFIX_.'category_product` cp WHERE'.$whereC.')', false);
@@ -818,7 +771,7 @@ class BlockLayered extends Module
/* Get the filters for the current category */
$filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT * FROM '._DB_PREFIX_.'layered_category WHERE id_category = '.(int)$id_parent.' ORDER BY position ASC');
$filterBlocks = $f = $a = array();
foreach ($filters AS $filter)
{
$filterBlocks[(int)$filter['position']]['type_lite'] = $filter['type'];
@@ -878,7 +831,6 @@ class BlockLayered extends Module
}
}
$weight_unit = Configuration::get('PS_WEIGHT_UNIT');
foreach ($filterBlocks AS &$filterBlock)
{
if ($filterBlock['type_lite'] == 'category')
@@ -1067,7 +1019,7 @@ class BlockLayered extends Module
$filterBlock['values'] = array($selectedFilters['weight'][0], $selectedFilters['weight'][1]);
else
$filterBlock['values'] = array(min($weight), max($weight));
$filterBlock['unit'] = $weight_unit;
$filterBlock['unit'] = Configuration::get('PS_WEIGHT_UNIT');
}
else
unset($selectedFilters['weight']);
@@ -1085,15 +1037,13 @@ class BlockLayered extends Module
$share_url = $this->context->link->getCategoryLink((int)$category->id, $category->link_rewrite[(int)$this->context->language->id], $this->context->language->id).rtrim($params, '&');
$this->context->smarty->assign(array(
'display_share' => (int)Configuration::get('PS_LAYERED_SHARE'),
'share_url' => $this->getShortLink($share_url),
'layered_show_qties' => (int)Configuration::get('PS_LAYERED_SHOW_QTIES'),
'id_category_layered' => (int)$id_parent,
'selected_filters' => $selectedFilters,
'n_filters' => (int)$nFilters,
'nbr_filterBlocks' => sizeof($filterBlocks),
'filters' => $filterBlocks));
return $this->display(__FILE__, 'blocklayered.tpl');
}
@@ -1110,6 +1060,11 @@ class BlockLayered extends Module
$categoryBox[] = (int)$id_category;
}
/* Clean categoryBox before use */
if (isset($categoryBox) AND is_array($categoryBox))
foreach ($categoryBox AS &$value)
$value = (int)$value;
$attributeGroups = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT ag.id_attribute_group, ag.is_color_group, agl.name, COUNT(DISTINCT(a.id_attribute)) n
FROM '._DB_PREFIX_.'attribute_group ag
@@ -1215,6 +1170,7 @@ class BlockLayered extends Module
$selectedFilters = $this->getSelectedFilters();
$products = $this->getProductByFilters($selectedFilters);
$products = Product::getProductsProperties($this->context->language->id, $products);
$nbProducts = $this->nbr_products;
$range = 2; /* how many pages around page selected */
@@ -1250,7 +1206,6 @@ class BlockLayered extends Module
$this->context->smarty->assign('comparator_max_item', (int)Configuration::get('PS_COMPARATOR_MAX_ITEM'));
$this->context->smarty->assign('products', $products);
/* We are sending an array in jSon to the .js controller, it will update both the filters and the products zones */
return Tools::jsonEncode(array(
'filtersBlock' => $this->generateFiltersBlock($selectedFilters),
@@ -1473,23 +1428,4 @@ if (!isset($doneCategories[(int)$id_category]['p']))
}
return $products;
}
private function getShortLink($share_url) {
$return = '';
if (extension_loaded('curl'))
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.bitly.com/v3/shorten");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'login='.Configuration::get('PS_LAYERED_BITLY_USERNAME').'&apiKey='.Configuration::get('PS_LAYERED_BITLY_API_KEY').'&longUrl='.urlencode($share_url).'&format=txt');
$return = curl_exec($ch);
}
if ($return != 'INVALID_LOGIN' AND $return != 'INVALID_APIKEY' AND extension_loaded('curl'))
return $return;
else
return $share_url;
}
}