From 46cfa2b8f3f3510e721fd38a96baaa15ba9dcd4b Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Mon, 29 May 2017 12:21:32 +0200 Subject: [PATCH 1/3] Configure fidelity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add a new category "Offre de fidélité - Liste de choix" - Move it near "Offre de fidélité" - Copy product between the two category - Configure in admin "Préférences > Produits" --- controllers/front/OffrefideliteController.php | 34 ++- .../admin/AdminPPreferencesController.php | 217 ++++++++++++++++++ themes/default/mobile/offrefidelite.tpl | 10 +- themes/default/offrefidelite.tpl | 10 +- 4 files changed, 255 insertions(+), 16 deletions(-) create mode 100755 override/controllers/admin/AdminPPreferencesController.php diff --git a/controllers/front/OffrefideliteController.php b/controllers/front/OffrefideliteController.php index 65a95e6..cdc94d9 100755 --- a/controllers/front/OffrefideliteController.php +++ b/controllers/front/OffrefideliteController.php @@ -115,21 +115,42 @@ class OffrefideliteControllerCore extends FrontController public function getItemsProducts() { $id_shop = $this->context->shop->id; - $id_lang = $this->context->language->id; - $sql=' + $id_lang = $this->context->language->id; + $id_category = Configuration::get('PS_CATEGORY_FIDELITY'); + $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 = 31 + 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); + $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); return $products; - } + } + + public function getItemsProductsChoice() + { + $id_shop = $this->context->shop->id; + $id_lang = $this->context->language->id; + $id_category = Configuration::get('PS_CATEGORY_FIDELITYCHOICE'); + $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() { @@ -154,7 +175,8 @@ class OffrefideliteControllerCore extends FrontController $this->emailOffreFidelite(); } - $this->context->smarty->assign('generationProduits',$this->getItemsProducts()); + $this->context->smarty->assign('productFidelity',$this->getItemsProducts()); + $this->context->smarty->assign('productChoice', $this->getItemsProductsChoice()); $this->context->smarty->assign('livredorEnAvant',$this->getLivredorEnAvant()); diff --git a/override/controllers/admin/AdminPPreferencesController.php b/override/controllers/admin/AdminPPreferencesController.php new file mode 100755 index 0000000..a1c9c5a --- /dev/null +++ b/override/controllers/admin/AdminPPreferencesController.php @@ -0,0 +1,217 @@ +className = 'Configuration'; + $this->table = 'configuration'; + + parent::__construct(); + + $this->fields_options = array( + 'products' => array( + 'title' => $this->l('Products (general)'), + 'fields' => array( + 'PS_CATALOG_MODE' => array( + 'title' => $this->l('Catalog mode'), + 'desc' => $this->l('When active, all shopping features will be disabled.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' + ), + 'PS_COMPARATOR_MAX_ITEM' => array( + 'title' => $this->l('Product comparison'), + 'desc' => $this->l('Set the maximum number of products that can be selected for comparison.').' '.$this->l('Set to "0" to disable this feature.'), + 'validation' => 'isUnsignedId', + 'required' => true, + 'cast' => 'intval', + 'type' => 'text' + ), + 'PS_NB_DAYS_NEW_PRODUCT' => array( + 'title' => $this->l('Number of days for which the product is considered \'new\''), + 'validation' => 'isUnsignedInt', + 'cast' => 'intval', + 'type' => 'text' + ), + 'PS_CART_REDIRECT' => array( + 'title' => $this->l('Redirect after adding product to cart'), + 'desc' => $this->l('Only for non-AJAX versions of the cart.'), + 'cast' => 'intval', + 'show' => true, + 'required' => false, + 'type' => 'radio', + 'validation' => 'isBool', + 'choices' => array( + 0 => $this->l('Previous page'), + 1 => $this->l('Cart summary') + ) + ), + 'PS_PRODUCT_SHORT_DESC_LIMIT' => array( + 'title' => $this->l('Max size of short description'), + 'desc' => $this->l('Set the maximum size of product short description (in characters).'), + 'validation' => 'isInt', + 'cast' => 'intval', + 'type' => 'text', + 'suffix' => $this->l('characters'), + ), + 'PS_QTY_DISCOUNT_ON_COMBINATION' => array( + 'title' => $this->l('Quantity discounts based on'), + 'desc' => $this->l('How to calculate quantity discounts'), + 'cast' => 'intval', + 'show' => true, + 'required' => false, + 'type' => 'radio', + 'validation' => 'isBool', + 'choices' => array( + 0 => $this->l('Products:'), + 1 => $this->l('Combinations') + ) + ) + ), + ), + 'order_by_pagination' => array( + 'title' => $this->l('Pagination'), + 'fields' => array( + 'PS_PRODUCTS_PER_PAGE' => array( + 'title' => $this->l('Products per page'), + 'desc' => $this->l('Number of products displayed per page. Default is 10.'), + 'validation' => 'isUnsignedInt', + 'cast' => 'intval', + 'type' => 'text' + ), + 'PS_PRODUCTS_ORDER_BY' => array( + 'title' => $this->l('Default order by'), + 'desc' => $this->l('The order in which products are displayed in the product list.'), + 'type' => 'select', + 'list' => array( + array('id' => '0', 'name' => $this->l('Product name')), + array('id' => '1', 'name' => $this->l('Product price')), + array('id' => '2', 'name' => $this->l('Product add date')), + array('id' => '3', 'name' => $this->l('Product modified date')), + array('id' => '4', 'name' => $this->l('Position inside category')), + array('id' => '5', 'name' => $this->l('Manufacturer')), + array('id' => '6', 'name' => $this->l('Product quantity')) + ), + 'identifier' => 'id' + ), + 'PS_PRODUCTS_ORDER_WAY' => array( + 'title' => $this->l('Default order method'), + 'desc' => $this->l('Default order method for product list'), + 'type' => 'select', + 'list' => array( + array( + 'id' => '0', + 'name' => $this->l('Ascending') + ), + array( + 'id' => '1', + 'name' => $this->l('Descending') + ) + ), + 'identifier' => 'id' + ) + ) + ), + 'fo_product_page' => array( + 'title' => $this->l('Product page'), + 'fields' => array( + 'PS_DISPLAY_QTIES' => array( + 'title' => $this->l('Display available quantities on the product page'), + 'desc' => '', + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' + ), + 'PS_LAST_QTIES' => array( + 'title' => $this->l('Display remaining quantities when the qty is lower than'), + 'desc' => $this->l('Set to "0" to disable this feature.'), + 'validation' => 'isUnsignedId', + 'required' => true, + 'cast' => 'intval', + 'type' => 'text' + ), + 'PS_DISPLAY_JQZOOM' => array( + 'title' => $this->l('Enable JqZoom instead of Thickbox on the product page'), + 'desc' => '', + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' + ), + 'PS_DISP_UNAVAILABLE_ATTR' => array( + 'title' => $this->l('Display unavailable product attributes on the product page'), + 'desc' => '', + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' + ), + 'PS_ATTRIBUTE_CATEGORY_DISPLAY' => array( + 'title' => $this->l('Display the "add to cart" button when a product has attributes'), + 'desc' => $this->l('Display or hide the "add to cart" button on category pages for products that have attributes forcing customers to see product details.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool' + ) + ) + ), + 'stock' => array( + 'title' => $this->l('Products stock'), + 'fields' => array( + 'PS_ORDER_OUT_OF_STOCK' => array( + 'title' => $this->l('Allow ordering of out-of-stock products'), + 'desc' => $this->l('Add to cart button is hidden when a product is unavailable'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool' + ), + 'PS_STOCK_MANAGEMENT' => array( + 'title' => $this->l('Enable stock management'), + 'desc' => '', + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool', + 'js' => array( + 'on' => 'onchange="stockManagementActivationAuthorization()"', + 'off' => 'onchange="stockManagementActivationAuthorization()"' + ) + ), + 'PS_ADVANCED_STOCK_MANAGEMENT' => array( + 'title' => $this->l('Enable advanced-stock management'), + 'desc' => $this->l('Allows you to manage physical stock, warehouses and supply orders.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'required' => false, + 'type' => 'bool', + 'visibility' => Shop::CONTEXT_ALL, + ), + ), + 'bottom' => '', + 'submit' => array() + ), + ); + + // Add specific field for fidelity + $this->fields_options['products']['fields']['PS_CATEGORY_FIDELITY'] = array( + 'title' => $this->l('Catégorie offre de fidélité'), + 'desc' => $this->l('Défini l\'id category pour les produits en offre fidélité.'), + 'validation' => 'isUnsignedId', + 'required' => true, + 'cast' => 'intval', + 'type' => 'text' + ); + + $this->fields_options['products']['fields']['PS_CATEGORY_FIDELITYCHOICE'] = array( + 'title' => $this->l('Catégorie liste des choix offre fidélité'), + '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' + ); + } +} diff --git a/themes/default/mobile/offrefidelite.tpl b/themes/default/mobile/offrefidelite.tpl index 4880c60..ad67939 100755 --- a/themes/default/mobile/offrefidelite.tpl +++ b/themes/default/mobile/offrefidelite.tpl @@ -104,7 +104,7 @@ @@ -113,7 +113,7 @@ @@ -121,12 +121,12 @@

{l s='- Cochez votre indice de satisfaction sur les produits que vous avez testés :'}
{l s='1 = Très satisfaite, 2 = Satisfaite, 3 = Assez satisfaite,'}
{l s='4 = Pas du tout satisfaite'}

- {if $generationProduits|@count>0} + {if $productFidelity|@count>0}
{assign var=id_category_default value=false} - {foreach from=$generationProduits item=produit} + {foreach from=$productFidelity item=produit} {if $id_category_default!=$produit.id_category_default} {assign var=id_category_default value=$produit.id_category_default} @@ -145,7 +145,7 @@ {/foreach}
- +
{/if}