[*] FO: You can now choose the anchor separator for attributes

This commit is contained in:
Rémi Gaillard
2013-10-09 11:01:18 +02:00
parent 623b8c7960
commit 3b677092bf
10 changed files with 40 additions and 21 deletions
+4 -4
View File
@@ -3051,7 +3051,7 @@ class ProductCore extends ObjectModel
return array();
if (!$res = Db::getInstance()->executeS('
SELECT pa.id_product, a.color, a.id_attribute, pac.id_product_attribute
SELECT pa.id_product, a.color, pac.id_product_attribute
FROM '._DB_PREFIX_.'product_attribute pa
'.Shop::addSqlAssociation('product_attribute', 'pa').'
JOIN '._DB_PREFIX_.'product_attribute_combination pac ON (pac.id_product_attribute = product_attribute_shop.id_product_attribute)
@@ -3068,7 +3068,7 @@ class ProductCore extends ObjectModel
if (Tools::isEmpty($row['color']))
continue;
$colors[(int)$row['id_product']][] = array('id_product_attribute' => (int)$row['id_product_attribute'], 'color' => $row['color']);
$colors[(int)$row['id_product']][] = array('id_product_attribute' => (int)$row['id_product_attribute'], 'color' => $row['color'], 'id_product' => $row['id_product']);
}
return $colors;
@@ -5107,8 +5107,8 @@ class ProductCore extends ObjectModel
foreach ($attributes as &$a)
{
foreach ($a as &$b)
$b = str_replace('-', '_', Tools::link_rewrite($b));
$anchor .= '/'.$a['group'].'-'.$a['name'];
$b = str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($b));
$anchor .= '/'.$a['group'].Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').$a['name'];
}
return $anchor;
}
+2 -1
View File
@@ -1171,7 +1171,8 @@ class FrontControllerCore extends Controller
if (isset($colors[$product['id_product']]))
$tpl->assign(array(
'id_product' => $product['id_product'],
'colors_list' => $colors[$product['id_product']]
'colors_list' => $colors[$product['id_product']],
'link' => Context::getContext()->link
));
if (!in_array($product['id_product'], $products_need_cache) || isset($colors[$product['id_product']]))
$product['color_list'] = $tpl->fetch(_PS_THEME_DIR_.'product-list-colors.tpl', $this->getColorsListCacheId($product['id_product']));
@@ -181,6 +181,15 @@ class AdminPPreferencesControllerCore extends AdminController
'validation' => 'isBool',
'cast' => 'intval',
'type' => 'bool'
),
'PS_ATTRIBUTE_ANCHOR_SEPARATOR' => array(
'title' => $this->l('Separator of attribute anchor on the product links'),
'type' => 'select',
'list' => array(
array('id' => '-', 'name' => '-'),
array('id' => ',', 'name' => ','),
),
'identifier' => 'id'
)
)
),
+6 -2
View File
@@ -515,10 +515,14 @@ class ProductControllerCore extends FrontController
if (is_array($attributes_combinations) && count($attributes_combinations))
foreach ($attributes_combinations as &$ac)
foreach ($ac as &$val)
$val = str_replace('-', '_', Tools::link_rewrite(str_replace(array(',', '.'), '-', $val)));
$val = str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite(str_replace(array(',', '.'), '-', $val)));
else
$attributes_combinations = array();
$this->context->smarty->assign('attributesCombinations', $attributes_combinations);
$this->context->smarty->assign(array(
'attributesCombinations' => $attributes_combinations,
'attribute_anchor_separator' => Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR')
)
);
}
/**
+3
View File
@@ -778,5 +778,8 @@ Country</value>
<configuration id="PS_DASHBOARD_USE_PUSH" name="PS_DASHBOARD_USE_PUSH">
<value>0</value>
</configuration>
<configuration id="PS_ATTRIBUTE_ANCHOR_SEPARATOR" name="PS_ATTRIBUTE_ANCHOR_SEPARATOR">
<value>-</value>
</configuration>
</entities>
</entity_configuration>
+2
View File
@@ -29,3 +29,5 @@ CREATE TABLE `PREFIX_configuration_kpi_lang` (
) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8;
/* PHP:ps1600_add_missing_index(); */;
UPDATE `PREFIX_configuration` SET `value`='-' WHERE `name`='PS_ATTRIBUTE_ANCHOR_SEPARATOR';
+10 -10
View File
@@ -419,7 +419,7 @@ class BlockLayered extends Module
foreach ($attribute as $param)
{
$selected_filters = array();
$link = '/'.str_replace('-', '_', Tools::link_rewrite($param['name'])).'-'.str_replace('-', '_', Tools::link_rewrite($param['value']));
$link = '/'.str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($param['name'])).Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($param['value']));
$selected_filters[$param['type']] = array();
if (!isset($param['id_id_value']))
$param['id_id_value'] = $param['id_value'];
@@ -2103,7 +2103,7 @@ class BlockLayered extends Module
{
foreach ($url_attributes as $url_attribute)
{
$url_parameters = explode('-', $url_attribute);
$url_parameters = explode(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), $url_attribute);
$attribute_name = array_shift($url_parameters);
if ($attribute_name == 'page')
$this->page = (int)$url_parameters[0];
@@ -2113,7 +2113,7 @@ class BlockLayered extends Module
{
foreach ($url_parameters as $url_parameter)
{
$data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5('/'.$attribute_name.'-'.$url_parameter).'\'');
$data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5('/'.$attribute_name.Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').$url_parameter).'\'');
if ($data)
foreach (Tools::unSerialize($data) as $key_params => $params)
{
@@ -3029,7 +3029,7 @@ class BlockLayered extends Module
{
$value_name = !empty($value['url_name']) ? $value['url_name'] : $value['name'];
$value_meta = !empty($value['meta_title']) ? $value['meta_title'] : $value['name'];
$param_group_selected .= '-'.str_replace('-', '_', Tools::link_rewrite($value_name));
$param_group_selected .= Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($value_name));
$param_group_selected_array[Tools::link_rewrite($filter_name)][] = Tools::link_rewrite($value_name);
if (!isset($title_values[$filter_name]))
@@ -3044,12 +3044,12 @@ class BlockLayered extends Module
}
if (!empty($param_group_selected))
{
$param_selected .= '/'.str_replace('-', '_', Tools::link_rewrite($filter_name)).$param_group_selected;
$param_selected .= '/'.str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($filter_name)).$param_group_selected;
$option_checked_array[Tools::link_rewrite($filter_name)] = $param_group_selected;
}
// select only attribute and group attribute to display an unique product combination link
if (!empty($param_group_selected) && $type_filter['type'] == 'id_attribute_group')
$param_product_url .= '/'.str_replace('-', '_', Tools::link_rewrite($filter_name)).$param_group_selected;
$param_product_url .= '/'.str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($filter_name)).$param_group_selected;
}
@@ -3089,23 +3089,23 @@ class BlockLayered extends Module
// Update parameter filter checked before
if (array_key_exists(Tools::link_rewrite($filter_name), $option_checked_array))
{
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = $option_checked_clone_array[Tools::link_rewrite($filter_name)].'-'.str_replace('-', '_', Tools::link_rewrite($value_name));
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = $option_checked_clone_array[Tools::link_rewrite($filter_name)].Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($value_name));
$nofollow = true;
}
else
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = '-'.str_replace('-', '_', Tools::link_rewrite($value_name));
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($value_name));
}
else
{
// Remove selected parameters
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = str_replace('-'.str_replace('-', '_', Tools::link_rewrite($value_name)), '', $option_checked_clone_array[Tools::link_rewrite($filter_name)]);
$option_checked_clone_array[Tools::link_rewrite($filter_name)] = str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR').str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::link_rewrite($value_name)), '', $option_checked_clone_array[Tools::link_rewrite($filter_name)]);
if (empty($option_checked_clone_array[Tools::link_rewrite($filter_name)]))
unset($option_checked_clone_array[Tools::link_rewrite($filter_name)]);
}
$parameters = '';
ksort($option_checked_clone_array); // Order parameters
foreach ($option_checked_clone_array as $key_group => $value_group)
$parameters .= '/'.str_replace('-', '_', $key_group).$value_group;
$parameters .= '/'.str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', $key_group).$value_group;
// Check if there is an non indexable attribute or feature in the url
foreach ($non_indexable as $value)
+2 -2
View File
@@ -659,7 +659,7 @@ function getProductAttribute()
for (var i in attributesCombinations)
for (var a in tab_attributes)
if (attributesCombinations[i]['id_attribute'] === tab_attributes[a])
request += '/'+attributesCombinations[i]['group'] + '-' + attributesCombinations[i]['attribute'];
request += '/'+attributesCombinations[i]['group'] + attribute_anchor_separator + attributesCombinations[i]['attribute'];
request = request.replace(request.substring(0, 1), '#/');
url = window.location + '';
@@ -694,7 +694,7 @@ function checkUrl()
if (tabParams[0] == '')
tabParams.shift();
for (var i in tabParams)
tabValues.push(tabParams[i].split('-'));
tabValues.push(tabParams[i].split(attribute_anchor_separator));
product_id = $('#product_page_product_id').val();
// fill html with values
$('.color_pick').removeClass('selected');
+1 -2
View File
@@ -23,9 +23,8 @@
* International Registered Trademark & Property of PrestaShop SA
*}
<ul id="color_to_pick_list" class="clearfix">
{foreach from=$colors_list item='color'}
<li><a id="color_{$color.id_product_attribute|intval}" class="color_pick" style="background: {$color.color};"></a></li>
<li><a href="{$link->getProductLink($color.id_product, null, null, null, null, null, $color.id_product_attribute)|escape:'htmlall':'UTF-8'}" id="color_{$color.id_product_attribute|intval}" class="color_pick" style="background: {$color.color};"></a></li>
{/foreach}
</ul>
+1
View File
@@ -49,6 +49,7 @@ var availableNowValue = '{$product->available_now|escape:'quotes':'UTF-8'}';
var availableLaterValue = '{$product->available_later|escape:'quotes':'UTF-8'}';
var productPriceTaxExcluded = {$product->getPriceWithoutReduct(true)|default:'null'} - {$product->ecotax};
var productBasePriceTaxExcluded = {$product->base_price} - {$product->ecotax};
var attribute_anchor_separator = '{$attribute_anchor_separator|addslashes}';
var reduction_percent = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'percentage'}{$product->specificPrice.reduction*100}{else}0{/if};
var reduction_price = {if $product->specificPrice AND $product->specificPrice.reduction AND $product->specificPrice.reduction_type == 'amount'}{$product->specificPrice.reduction|floatval}{else}0{/if};