addition of img to recognize the product

This commit is contained in:
Marion Muszynski 2016-10-05 16:18:52 +02:00
parent 6475f2140c
commit 047f419b8e
3 changed files with 52 additions and 14 deletions

View File

@ -56,15 +56,22 @@ $enabledOnly = Tools::getValue('enabledOnly', false);
$excludeVirtuals = (bool)Tools::getValue('excludeVirtuals', false);
$items = Db::getInstance()->ExecuteS('
SELECT p.`id_product`, `reference`, pl.name
SELECT p.`id_product`, `reference`, pl.`name`, i.`id_image`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.id_product = p.id_product)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
WHERE (pl.name LIKE \'%'.pSQL($query).'%\' OR p.reference LIKE \'%'.pSQL($query).'%\') AND pl.id_lang = '.(int)($cookie->id_lang).
(!empty($excludeIds) ? ' AND p.id_product NOT IN ('.$excludeIds.') ' : ' ').
($enabledOnly ? ' AND p.`active` = 1 ' : ' ').
($excludeVirtuals ? 'AND p.id_product NOT IN (SELECT pd.id_product FROM `'._DB_PREFIX_.'product_download` pd WHERE (pd.id_product = p.id_product))' : ''));
if ($items)
foreach ($items AS $item)
echo trim($item['name']).(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : '').'|'.(int)($item['id_product'])."\n";
foreach ($items AS $item){
$img_path = '';
if(isset($item['id_image']) && !empty($item['id_image'])){
$image_obj = new Image((int)$item['id_image']);
$img_path = (isset($image_obj)?$image_obj->getExistingImgPath():'');
}
echo trim($item['name']).(!empty($item['reference']) ? ' (ref: '.$item['reference'].')' : '').'|'.(int)($item['id_product']).(!empty($img_path) ?'|'.($img_path):'')."\n";
}

View File

@ -3534,8 +3534,20 @@ class AdminProducts extends AdminTab
<td class="col-left">'.$this->l('Accessories:').'<br /><br /><i>'.$this->l('(Do not forget to Save the product afterward)').'</i></td>
<td style="padding-bottom:5px;">
<div id="divAccessories">';
foreach ($accessories as $accessory)
echo htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8').(!empty($accessory['reference']) ? ' ('.$accessory['reference'].')' : '').' <span onclick="delAccessory('.$accessory['id_product'].');" style="cursor: pointer;"><img src="../img/admin/delete.gif" class="middle" alt="" /></span><br />';
foreach ($accessories as $accessory){
$accesorie_img_path = '';
$img = Db::getInstance()->getRow('
SELECT id_image
FROM `'._DB_PREFIX_.'image` i
WHERE i.`id_product` = '.(int)$accessory['id_product'].'
AND i.`cover` = 1'
);
if (isset($img['id_image']) && !empty($img['id_image'])) {
$image_obj = new Image((int)$img['id_image']);
$accesorie_img_path = (isset($image_obj)?$image_obj->getExistingImgPath():'');
}
echo (!empty($accesorie_img_path)?'<img src="'._THEME_PROD_DIR_.$accesorie_img_path.'-small.jpg" /> ':'').htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8').(!empty($accessory['reference']) ? ' ('.$accessory['reference'].')' : '').' <span onclick="delAccessory('.$accessory['id_product'].');" style="cursor: pointer;"><img src="../img/admin/delete.gif" class="middle" alt="" /></span><br />';
}
echo '</div>
<input type="hidden" name="inputAccessories" id="inputAccessories" value="';
foreach ($accessories as $accessory)
@ -3544,7 +3556,19 @@ class AdminProducts extends AdminTab
<input type="hidden" name="nameAccessories" id="nameAccessories" value="';
foreach ($accessories as $accessory)
echo htmlentities($accessory['name'], ENT_COMPAT, 'UTF-8').'¤';
echo '" />
<input type="hidden" name="imgAccessories" id="imgAccessories" value="';
foreach ($accessories as $accessory) {
$img = Db::getInstance()->getRow('
SELECT id_image
FROM `'._DB_PREFIX_.'image` i
WHERE i.`id_product` = '.(int)$accessory['id_product'].'
AND i.`cover` = 1'
);
$image_obj = new Image((int)$img['id_image']);
$accesorie_img_path = (isset($image_obj)?$image_obj->getExistingImgPath():'');
echo $accesorie_img_path.',';
}
echo '" />
<script type="text/javascript">
var formProduct;
@ -3555,7 +3579,7 @@ class AdminProducts extends AdminTab
<script type="text/javascript" src="'.__PS_BASE_URI__.'js/jquery/jquery.autocomplete.js"></script>
<div id="ajax_choose_product" style="padding:6px; padding-top:2px; width:600px;">
<p class="clear">'.$this->l('Begin typing the first letters of the product name, then select the product from the drop-down list:').'</p>
<input type="text" value="" id="product_autocomplete_input" />
<input type="text" style="width:400px;" value="" id="product_autocomplete_input" />
<img onclick="$(this).prev().search();" style="cursor: pointer;" src="../img/admin/add.gif" alt="'.$this->l('Add an accessory').'" title="'.$this->l('Add an accessory').'" />
</div>
<script type="text/javascript">
@ -3572,8 +3596,8 @@ class AdminProducts extends AdminTab
scroll:false,
cacheLength:0,
formatItem: function(item) {
return item[1]+\' - \'+item[0];
}
return \'<img src="'._THEME_PROD_DIR_.'\'+item[2]+\'-small.jpg" /> \'+item[1]+\' - \'+item[0];
},
}).result(addAccessory);
$(\'#product_autocomplete_input\').setOptions({
extraParams: {excludeIds : getAccessorieIds(), enabledOnly : 1}

View File

@ -326,18 +326,21 @@ function addAccessory(event, data, formatted)
return false;
var productId = data[1];
var productName = data[0];
var productImg = data[2];
var $divAccessories = $('#divAccessories');
var $inputAccessories = $('#inputAccessories');
var $nameAccessories = $('#nameAccessories');
var $imgAccessories = $('#imgAccessories');
/* delete product from select + add product line to the div, input_name, input_ids elements */
$divAccessories.html($divAccessories.html() + productName + ' <span onclick="delAccessory(' + productId + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />');
$divAccessories.html($divAccessories.html() + '<img src="/img/p/'+productImg+'-small.jpg" /> ' + productName + ' <span onclick="delAccessory(' + productId + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />');
$nameAccessories.val($nameAccessories.val() + productName + '¤');
$inputAccessories.val($inputAccessories.val() + productId + '-');
$imgAccessories.val($imgAccessories.val() + productImg + ',');
$('#product_autocomplete_input').val('');
$('#product_autocomplete_input').setOptions({
extraParams: {excludeIds : getAccessorieIds()}
extraParams: {excludeIds : getAccessorieIds(), enabledOnly : 1}
});
}
@ -347,10 +350,12 @@ function delAccessory(id)
var div = getE('divAccessories');
var input = getE('inputAccessories');
var name = getE('nameAccessories');
var img = getE('imgAccessories');
// Cut hidden fields in array
var inputCut = input.value.split('-');
var nameCut = name.value.split('¤');
var imgCut = img.value.split(',');
if (inputCut.length != nameCut.length)
return alert('Bad size');
@ -358,6 +363,7 @@ function delAccessory(id)
// Reset all hidden fields
input.value = '';
name.value = '';
img.value = '';
div.innerHTML = '';
for (i in inputCut)
{
@ -370,14 +376,15 @@ function delAccessory(id)
{
input.value += inputCut[i] + '-';
name.value += nameCut[i] + '¤';
div.innerHTML += nameCut[i] + ' <span onclick="delAccessory(' + inputCut[i] + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
img.value += imgCut[i] + ';';
div.innerHTML += '<img src="/img/p/'+imgCut[i]+'-small.jpg" /> '+nameCut[i] + ' <span onclick="delAccessory(' + inputCut[i] + ');" style="cursor: pointer;"><img src="../img/admin/delete.gif" /></span><br />';
}
else
$('#selectAccessories').append('<option selected="selected" value="' + inputCut[i] + '-' + nameCut[i] + '">' + inputCut[i] + ' - ' + nameCut[i] + '</option>');
}
$('#product_autocomplete_input').setOptions({
extraParams: {excludeIds : getAccessorieIds()}
extraParams: {excludeIds : getAccessorieIds(), enabledOnly : 1}
});
}
@ -455,7 +462,7 @@ if (helpboxes)
/**
* Deprecated
*
*
* @param id_product
* @param id_image
*/