Add two categories for list

This commit is contained in:
Michael RICOIS 2017-05-29 12:58:33 +02:00
parent 75c06c7853
commit 1876d12119
3 changed files with 45 additions and 9 deletions

View File

@ -116,11 +116,17 @@ class OffrefideliteControllerCore extends FrontController
return $products;
}
public function getItemsProductsChoice()
public function getItemsProductsChoice($choice)
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE');
if ($choice == 2) {
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE2');
} else {
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE1');
}
$sql = '
SELECT distinct(p.`id_product`), pl.name, pl.link_rewrite,cl.name as categoryName,c.id_category,p.id_category_default
FROM '._DB_PREFIX_.'category_product cp
@ -136,6 +142,26 @@ class OffrefideliteControllerCore extends FrontController
return $products;
}
public function getItemsProductsChoice2()
{
$id_shop = $this->context->shop->id;
$id_lang = $this->context->language->id;
$id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE2');
$sql = '
SELECT distinct(p.`id_product`), pl.name, pl.link_rewrite,cl.name as categoryName,c.id_category,p.id_category_default
FROM '._DB_PREFIX_.'category_product cp
LEFT JOIN '._DB_PREFIX_.'category c ON (cp.id_category = c.id_category)
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_lang = '.(int)$id_lang.' and c.id_category = cl.id_category)
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product)
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_lang = '.(int)$id_lang.' and p.id_product = pl.id_product)
WHERE c.id_category = '.(int)$id_category.'
AND p.active = 1
ORDER BY cl.name desc,cp.position asc,pl.name asc';
$products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
return $products;
}
public function initContent()
{
// $this->context = Context::getContext();
@ -160,7 +186,8 @@ class OffrefideliteControllerCore extends FrontController
}
$this->context->smarty->assign('productFidelity',$this->getItemsProducts());
$this->context->smarty->assign('productChoice', $this->getItemsProductsChoice());
$this->context->smarty->assign('productChoice1', $this->getItemsProductsChoice(1));
$this->context->smarty->assign('productChoice2', $this->getItemsProductsChoice(2));
$this->context->smarty->assign('livredorEnAvant',$this->getLivredorEnAvant());

View File

@ -197,7 +197,7 @@ class AdminPPreferencesControllerCore extends AdminController
// Add specific field for fidelity
$this->fields_options['products']['fields']['PS_CATEGORY_FIDELITY'] = array(
'title' => $this->l('Catégorie offre de fidélité'),
'title' => $this->l('Offre de fidélité - Catégorie'),
'desc' => $this->l('Défini l\'id category pour les produits en offre fidélité.'),
'validation' => 'isUnsignedId',
'required' => true,
@ -205,13 +205,22 @@ class AdminPPreferencesControllerCore extends AdminController
'type' => 'text'
);
$this->fields_options['products']['fields']['PS_CATEGORY_FIDELITYCHOICE'] = array(
'title' => $this->l('Catégorie liste des choix offre fidélité'),
$this->fields_options['products']['fields']['PS_CATEGORY_FIDELITYCHOICE1'] = array(
'title' => $this->l('Offre fidélité - Catégorie Liste 1'),
'desc' => $this->l('Défini l\'id catégory pour la liste des choix des produits offerts'),
'validation' => 'isUnsignedId',
'required' => true,
'cast' => 'intval',
'type' => 'text'
);
);
$this->fields_options['products']['fields']['PS_CATEGORY_FIDELITYCHOICE2'] = array(
'title' => $this->l('Offre fidélité - Catégorie Liste 2'),
'desc' => $this->l('Défini l\'id catégory pour la liste des choix des produits offerts'),
'validation' => 'isUnsignedId',
'required' => true,
'cast' => 'intval',
'type' => 'text'
);
}
}

View File

@ -87,7 +87,7 @@
<option value="">{l s='Choix n°1'}</option>
{assign var=id_category value=false}
{assign var=compteur value=0}
{foreach from=$productFidelity item=produit}
{foreach from=$productChoice1 item=produit}
{if $id_category!=$produit.id_category}
{assign var=id_category value=$produit.id_category}
{if $compteur>0}
@ -104,7 +104,7 @@
<option value="">{l s='Choix n°2'}</option>
{assign var=id_category value=false}
{assign var=compteur value=0}
{foreach from=$productFidelity item=produit}
{foreach from=$productChoice2 item=produit}
{if $id_category!=$produit.id_category}
{assign var=id_category value=$produit.id_category}
{if $compteur>0}