* @copyright 2007-2015 Leotheme * @license http://leotheme.com - prestashop template provider */ if (!defined('_PS_VERSION_')) { # module validation exit; } require_once(_PS_MODULE_DIR_ . 'leofeature/classes/ProductReviewCriterion.php'); require_once(_PS_MODULE_DIR_ . 'leofeature/classes/ProductReview.php'); require_once(_PS_MODULE_DIR_ . 'leofeature/classes/CompareProduct.php'); require_once(_PS_MODULE_DIR_ . 'leofeature/classes/WishList.php'); use PrestaShop\PrestaShop\Adapter\Cart\CartPresenter; class Leofeature extends Module { protected $config_form = false; private $link; public $link_cart; public $module_path; protected $_postErrors = array(); public $is_gen_rtl; public $html = ''; public function __construct() { $this->name = 'leofeature'; $this->tab = 'front_office_features'; $this->version = '2.2.1'; $this->author = 'Leotheme'; $this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_); $this->need_instance = 0; $this->controllers = array('productscompare', 'mywishlist', 'viewwishlist'); /** * Set $this->bootstrap to true if your module is compliant with bootstrap (PrestaShop 1.6) */ $this->bootstrap = true; parent::__construct(); $this->secure_key = Tools::encrypt($this->name); $this->displayName = $this->l('Leo Feature'); $this->description = $this->l('Leo feature for prestashop 1.7: ajax cart, dropdown cart, fly cart, review, compare, wishlist at product list'); $this->link = $this->context->link; $this->module_path = $this->local_path; if (file_exists(_PS_THEME_DIR_ . 'modules/' . $this->name . '/css/front_rtl.css') || file_exists(_PS_THEME_DIR_ . '/assets/css/modules/' . $this->name . '/css/front_rtl.css')) { $this->is_gen_rtl = true; } else { $this->is_gen_rtl = false; } } /** * Don't forget to create update methods if needed: * http://doc.prestashop.com/display/PS16/Enabling+the+Auto-Update */ public function install() { if (parent::install() && $this->registerLeoHook()) { $this->createConfiguration(); $res = true; /* Creates tables */ $res &= $this->createTables(); Configuration::updateValue('AP_INSTALLED_LEOFEATURE', '1'); $id_parent = Tab::getIdFromClassName('IMPROVE'); $class = 'Admin' . Tools::ucfirst($this->name) . 'Management'; $tab1 = new Tab(); $tab1->class_name = $class; $tab1->module = $this->name; $tab1->id_parent = $id_parent; $langs = Language::getLanguages(false); foreach ($langs as $l) { # validate module $tab1->name[$l['id_lang']] = $this->l('Leo Feature Management'); } $tab1->add(true, false); # insert icon for tab Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'tab` SET `icon` = "star" WHERE `id_tab` = "' . (int) $tab1->id . '"'); $this->installModuleTab('Leo Feature Configuration', 'module', 'AdminLeofeatureManagement'); $this->installModuleTab('Product Review Management', 'reviews', 'AdminLeofeatureManagement'); return (bool) $res; } return false; } public function uninstall() { if (parent::uninstall() && $this->unregisterLeoHook()) { $res = true; $this->uninstallModuleTab('management'); $this->uninstallModuleTab('reviews'); $this->uninstallModuleTab('module'); $res &= $this->deleteTables(); $this->deleteConfiguration(); return (bool) $res; } return false; } public function postProcess() { if (count($this->errors) > 0) { return; } //DONGND:: correct module if (Tools::getValue('correctmodule')) { $this->correctModule(); } /** * If values have been submitted in the form, process. */ if (((bool) Tools::isSubmit('submitLeofeatureConfig')) == true) { $this->postValidation(); if (!count($this->_postErrors)) { $this->_postProcess(); } else { foreach ($this->_postErrors as $err) { $this->html .= $this->displayError($err); } } } } /** * Load the configuration form */ public function getContent() { $this->errors = array(); if (!$this->access('configure')) { $this->errors[] = $this->trans('You do not have permission to configure this.', array(), 'Admin.Notifications.Error'); $this->context->smarty->assign('errors', $this->errors); $this->html .= $this->displayError( $this->trans('You do not have permission to configure this.', array(), 'Admin.Notifications.Error') ); } $this->postProcess(); $this->html .= $this->renderGroupConfig(); return $this->html; } public function renderGroupConfig() { $type_dropdown = array( array( 'id_type' => 'dropdown', 'name_type' => $this->l('Dropdown'), ), array( 'id_type' => 'dropup', 'name_type' => $this->l('Dropup'), ), array( 'id_type' => 'slidebar_left', 'name_type' => $this->l('Slidebar Left'), ), array( 'id_type' => 'slidebar_right', 'name_type' => $this->l('Slidebar Right'), ), array( 'id_type' => 'slidebar_top', 'name_type' => $this->l('Slidebar Top'), ), array( 'id_type' => 'slidebar_bottom', 'name_type' => $this->l('Slidebar Bottom'), ), ); $type_position = array( array( 'id_type' => 'fixed', 'name_type' => $this->l('Fixed'), ), array( 'id_type' => 'absolute', 'name_type' => $this->l('Absolute'), ), ); $type_unit = array( array( 'id_type' => 'percent', 'name_type' => $this->l('Percent'), ), array( 'id_type' => 'pixel', 'name_type' => $this->l('Pixel'), ), ); $type_vertical = array( array( 'id_type' => 'top', 'name_type' => $this->l('Top'), ), array( 'id_type' => 'bottom', 'name_type' => $this->l('Bottom'), ), ); $type_horizontal = array( array( 'id_type' => 'left', 'name_type' => $this->l('Left'), ), array( 'id_type' => 'right', 'name_type' => $this->l('Right'), ), ); $type_effect = array( array( 'id_type' => 'none', 'name_type' => $this->l('None'), ), array( 'id_type' => 'fade', 'name_type' => $this->l('Fade'), ), array( 'id_type' => 'shake', 'name_type' => $this->l('Shake'), ), ); $fields_form = array(); $fields_form[0]['form'] = array( 'input' => array( array( 'type' => 'hidden', 'name' => 'LEOFEATURE_DEFAULT_TAB', 'default' => '', ), array( 'type' => 'switch', 'label' => $this->l('Show Button Cart At Product List'), 'name' => 'LEOFEATURE_ENABLE_AJAXCART', 'is_bool' => true, // 'desc' => $this->l('Show Button Cart At Product List'), 'values' => array( array( 'id' => 'LEOFEATURE_ENABLE_AJAXCART_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_ENABLE_AJAXCART_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), // array( // 'type' => 'switch', // 'label' => $this->l('Show Select Attribute'), // 'name' => 'LEOFEATURE_ENABLE_SELECTATTRIBUTE', // 'is_bool' => true, // // 'desc' => $this->l('Show Select Attribute'), // 'values' => array( // array( // 'id' => 'LEOFEATURE_ENABLE_SELECTATTRIBUTE_on', // 'value' => 1, // 'label' => $this->l('Enabled') // ), // array( // 'id' => 'LEOFEATURE_ENABLE_SELECTATTRIBUTE_off', // 'value' => 0, // 'label' => $this->l('Disabled') // ) // ), // ), array( 'type' => 'select', 'label' => $this->l('Show Attribute at product list'), 'name' => 'LEOFEATURE_PRODUCTATTRIBUTE_TYPE', 'options' => array( 'query' => array( array('id' => '1', 'name' => $this->l('Show Select Attribute')), array('id' => '2', 'name' => $this->l('Show Group Attribute')), array('id' => '0', 'name' => $this->l('None')), ), 'id' => 'id', 'name' => 'name' ), ), array( 'type' => 'switch', 'label' => $this->l('Show Input Quantity'), 'name' => 'LEOFEATURE_ENABLE_INPUTQUANTITY', 'is_bool' => true, // 'desc' => $this->l('Show Input Quantity'), 'values' => array( array( 'id' => 'LEOFEATURE_ENABLE_INPUTQUANTITY_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_ENABLE_INPUTQUANTITY_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'switch', 'label' => $this->l('Show lable'), 'name' => 'LEOFEATURE_PRODUCTATTRIBUTE_SHOW_LABLE', 'is_bool' => true, //'desc' => $this->l('Show Input Quantity'), 'values' => array( array( 'id' => 'LEOFEATURE_PRODUCTATTRIBUTE_SHOW_LABLE_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_PRODUCTATTRIBUTE_SHOW_LABLE_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'switch', 'label' => $this->l('Enable Flycart Effect'), 'name' => 'LEOFEATURE_ENABLE_FLYCART_EFFECT', 'is_bool' => true, 'values' => array( array( 'id' => 'LEOFEATURE_ENABLE_FLYCART_EFFECT_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_ENABLE_FLYCART_EFFECT_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'switch', 'label' => $this->l('Enable Notification'), 'name' => 'LEOFEATURE_ENABLE_NOTIFICATION', 'desc' => $this->l('Show notification when add cart successful'), 'is_bool' => true, 'values' => array( array( 'id' => 'LEOFEATURE_ENABLE_NOTIFICATION_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_ENABLE_NOTIFICATION_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'switch', 'label' => $this->l('Show Popup After Add Cart'), 'name' => 'LEOFEATURE_SHOW_POPUP', 'desc' => $this->l('Default is ON. You can turn OFF and turn ON "Notification" instead'), 'is_bool' => true, 'values' => array( array( 'id' => 'LEOFEATURE_SHOW_POPUP_on', 'value' => 1, 'label' => $this->l('Enabled') ), array( 'id' => 'LEOFEATURE_SHOW_POPUP_off', 'value' => 0, 'label' => $this->l('Disabled') ) ), ), array( 'type' => 'html', 'name' => 'html_data', 'html_content' => '
';
// print_r($params['list_product']);die();
$list_grades = array();
$list_product_grades = array();
$list_product_average = array();
$list_product_review = array();
foreach ($params['list_product'] as $id_product) {
$id_product = (int) $id_product;
$grades = ProductReview::getAveragesByProduct($id_product, $this->context->language->id);
$criterions = ProductReviewCriterion::getByProduct($id_product, $this->context->language->id);
$grade_total = 0;
if (count($grades) > 0) {
foreach ($criterions as $criterion) {
if (isset($grades[$criterion['id_product_review_criterion']])) {
$list_product_grades[$criterion['id_product_review_criterion']][$id_product] = $grades[$criterion['id_product_review_criterion']];
$grade_total += (float) ($grades[$criterion['id_product_review_criterion']]);
} else {
$list_product_grades[$criterion['id_product_review_criterion']][$id_product] = 0;
}
if (!array_key_exists($criterion['id_product_review_criterion'], $list_grades)) {
$list_grades[$criterion['id_product_review_criterion']] = $criterion['name'];
}
}
$list_product_average[$id_product] = $grade_total / count($criterions);
$list_product_review[$id_product] = ProductReview::getByProduct($id_product, 0, 3);
}
}
if (count($list_grades) < 1) {
return false;
}
$this->context->smarty->assign(array(
'grades' => $list_grades,
'product_grades' => $list_product_grades,
'list_ids_product' => $params['list_product'],
'list_product_average' => $list_product_average,
'product_reviews' => $list_product_review,
));
return $this->display(__FILE__, '/leo_product_review_compare.tpl');
}
}
//DONGND:: display wishlist button
public function hookdisplayLeoWishlistButton($params)
{
if (Configuration::get('LEOFEATURE_ENABLE_PRODUCTWISHLIST')) {
$page_name = Dispatcher::getInstance()->getController();
if ((Configuration::get('LEOFEATURE_SHOW_PRODUCTWISHLIST_LISTPRODUCT') && $page_name != 'product') || (Configuration::get('LEOFEATURE_SHOW_PRODUCTWISHLIST_PRODUCTPAGE') && $page_name == 'product')) {
$wishlists = array();
$wishlists_added = array();
$id_wishlist = false;
$added_wishlist = false;
$id_product = $params['product']['id_product'];
$id_product_attribute = $params['product']['id_product_attribute'];
if ($this->context->customer->isLogged()) {
$wishlists = Wishlist::getByIdCustomer($this->context->customer->id);
if (empty($this->context->cookie->id_wishlist) === true ||
WishList::exists($this->context->cookie->id_wishlist, $this->context->customer->id) === false) {
if (!count($wishlists)) {
$id_wishlist = false;
} else {
$id_wishlist = (int) $wishlists[0]['id_wishlist'];
$this->context->cookie->id_wishlist = (int) $id_wishlist;
}
} else {
$id_wishlist = $this->context->cookie->id_wishlist;
}
$wishlist_products = ($id_wishlist == false ? array() : WishList::getSimpleProductByIdCustomer($this->context->customer->id, $this->context->shop->id));
$check_product_added = array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute);
foreach ($wishlist_products as $key => $wishlist_products_val) {
if (in_array($check_product_added, $wishlist_products_val)) {
$added_wishlist = true;
$wishlists_added[] = $key;
}
}
}
$this->smarty->assign(array(
'wishlists_added' => $wishlists_added,
'wishlists' => $wishlists,
'added_wishlist' => $added_wishlist,
'id_wishlist' => $id_wishlist,
'leo_wishlist_id_product' => $id_product,
'leo_wishlist_id_product_attribute' => $id_product_attribute,
));
return $this->display(__FILE__, 'leo_wishlist_button.tpl');
}
}
}
//DONGND:: add mywishlist link to page my account
public function hookdisplayCustomerAccount($params)
{
if (Configuration::get('LEOFEATURE_ENABLE_PRODUCTWISHLIST')) {
$this->context->smarty->assign(array(
'wishlist_link' => $this->link->getModuleLink('leofeature', 'mywishlist'),
));
return $this->display(__FILE__, 'leo_wishlist_link.tpl');
}
}
//DONGND:: create fly cart
public function hookDisplayBeforeBodyClosingTag($params)
{
if (!Configuration::isCatalogMode()) {
// print_r('test');die();
$output = '';
$check_create_slidebar = false;
$page_name = Dispatcher::getInstance()->getController();
if (Configuration::get('LEOFEATURE_ENABLE_DROPDOWN_DEFAULTCART') && (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_left' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_right' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_top' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_bottom') && $page_name != 'order') {
//DONGND:: reverse position with rtl
$type_dropdown_defaultcart = '';
$type_dropdown_defaultcart = Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART');
if ($this->context->language->is_rtl && !$this->is_gen_rtl) {
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_left') {
$type_dropdown_defaultcart = 'slidebar_right';
}
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == 'slidebar_right') {
$type_dropdown_defaultcart = 'slidebar_left';
}
}
$output .= $this->buildFlyCartSlideBar($type_dropdown_defaultcart);
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART') == Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART')) {
$check_create_slidebar = true;
}
}
if (Configuration::get('LEOFEATURE_ENABLE_DROPDOWN_FLYCART') && $page_name != 'order') {
$output .= $this->buildFlyCart();
if (!$check_create_slidebar && (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_left' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_right' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_top' || Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_bottom')) {
//DONGND:: reverse position with rtl
$type_fly_cart = '';
$type_fly_cart = Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART');
if ($this->context->language->is_rtl && !$this->is_gen_rtl) {
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_left') {
$type_fly_cart = 'slidebar_right';
}
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_right') {
$type_fly_cart = 'slidebar_left';
}
}
$output .= $this->buildFlyCartSlideBar($type_fly_cart);
}
}
return $output;
}
}
//DONGND:: build fly cart
public function buildFlyCart()
{
$vertical_position = '';
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_FLYCART') . ':';
if (Configuration::get('LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART') == 'percent') {
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART') . '%';
}
if (Configuration::get('LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART') == 'pixel') {
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART') . 'px';
}
$horizontal_position = '';
//DONGND:: reverse position with rtl
$type_horizontal_position = '';
$type_horizontal_position = Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_FLYCART');
if ($this->context->language->is_rtl) {
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_FLYCART') == 'left') {
$type_horizontal_position = 'right';
}
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_FLYCART') == 'right') {
$type_horizontal_position = 'left';
}
}
$horizontal_position .= $type_horizontal_position . ':';
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART') == 'percent') {
$horizontal_position .= Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART') . '%';
}
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART') == 'pixel') {
$horizontal_position .= Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART') . 'px';
}
//DONGND:: reverse position with rtl
$type_fly_cart = '';
$type_fly_cart = Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART');
if ($this->context->language->is_rtl && !$this->is_gen_rtl) {
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_left') {
$type_fly_cart = 'slidebar_right';
}
if (Configuration::get('LEOFEATURE_TYPE_DROPDOWN_FLYCART') == 'slidebar_right') {
$type_fly_cart = 'slidebar_left';
}
}
$templateVars = array(
'type_fly_cart' => $type_fly_cart,
// 'pusheffect' => (int)Configuration::get('LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART'),
'type_position' => Configuration::get('LEOFEATURE_TYPE_POSITION_FLYCART'),
'vertical_position' => $vertical_position,
'horizontal_position' => $horizontal_position,
);
$this->smarty->assign($templateVars);
return $this->fetch('module:leofeature/views/templates/front/fly_cart.tpl');
}
//DONGND:: build fly cart
public function buildFlyCartSlideBar($type)
{
$templateVars = array(
'type' => $type,
'enable_overlay_background' => (int) Configuration::get('LEOFEATURE_ENABLE_OVERLAYBACKGROUND_ALLCART'),
);
$this->smarty->assign($templateVars);
return $this->fetch('module:leofeature/views/templates/front/fly_cart_slide_bar.tpl');
}
//DONGND:: copy function from base
public function shouldEnableAddToCartButton(array $product)
{
if (($product['customizable'] == 2 || !empty($product['customization_required']))) {
$shouldShowButton = false;
if (isset($product['customizations'])) {
$shouldShowButton = true;
foreach ($product['customizations']['fields'] as $field) {
if ($field['required'] && !$field['is_customized']) {
$shouldShowButton = false;
}
}
}
} else {
$shouldShowButton = true;
}
$shouldShowButton = $shouldShowButton && $this->shouldShowAddToCartButton($product);
if ($product['quantity'] <= 0 && !$product['allow_oosp']) {
$shouldShowButton = false;
}
return $shouldShowButton;
}
//DONGND:: copy function from base
private function shouldShowAddToCartButton($product)
{
return (bool) $product['available_for_order'];
}
//DONGND:: copy function from base
private function getAddToCartURL(array $product)
{
// echo '';
// print_r($this->link);die();
return $this->link->getAddToCartURL($product['id_product'], $product['id_product_attribute']);
}
//DONGND:: render modal cart popup
public function renderModal()
{
$output = $this->fetch('module:leofeature/views/templates/front/modal.tpl');
return $output;
}
//DONGND:: render notification
public function renderNotification()
{
if (!Configuration::isCatalogMode()) {
if ((Configuration::get('LEOFEATURE_ENABLE_AJAXCART') && Configuration::get('LEOFEATURE_ENABLE_NOTIFICATION')) || Configuration::get('LEOFEATURE_ENABLE_DROPDOWN_DEFAULTCART') || Configuration::get('LEOFEATURE_ENABLE_DROPDOWN_FLYCART')) {
$vertical_position = '';
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_NOTIFICATION') . ':';
if (Configuration::get('LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION') == 'percent') {
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION') . '%';
}
if (Configuration::get('LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION') == 'pixel') {
$vertical_position .= Configuration::get('LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION') . 'px';
}
$horizontal_position = '';
//DONGND:: reverse position with rtl
$type_horizontal_position = '';
$type_horizontal_position = Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION');
if ($this->context->language->is_rtl) {
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION') == 'left') {
$type_horizontal_position = 'right';
}
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION') == 'right') {
$type_horizontal_position = 'left';
}
}
$horizontal_position .= $type_horizontal_position . ':';
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION') == 'percent') {
$horizontal_position .= Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION') . '%';
}
if (Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION') == 'pixel') {
$horizontal_position .= Configuration::get('LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION') . 'px';
}
$width_notification = '';
if (Configuration::get('LEOFEATURE_WIDTH_UNIT_NOTIFICATION') == 'percent') {
$width_notification .= Configuration::get('LEOFEATURE_WIDTH_NOTIFICATION') . '%';
}
if (Configuration::get('LEOFEATURE_WIDTH_UNIT_NOTIFICATION') == 'pixel') {
$width_notification .= Configuration::get('LEOFEATURE_WIDTH_NOTIFICATION') . 'px';
}
$templateVars = array(
'vertical_position' => $vertical_position,
'horizontal_position' => $horizontal_position,
'width_notification' => $width_notification,
);
$this->smarty->assign($templateVars);
$output = $this->fetch('module:leofeature/views/templates/front/notification.tpl');
return $output;
}
}
}
//DONGND:: render modal review popup
public function renderModalReview($id_product, $is_logged)
{
$product = new Product((int) $id_product, false, $this->context->language->id, $this->context->shop->id);
// echo '';
// print_r($product);die();
$image = Product::getCover((int) $id_product);
$cover_image = $this->context->link->getImageLink($product->link_rewrite, $image['id_image'], ImageType::getFormattedName('medium'));
// print_r($cover_image);die();
$this->context->smarty->assign(array(
'product_modal_review' => $product,
'criterions' => ProductReviewCriterion::getByProduct((int) $id_product, $this->context->language->id),
'secure_key' => $this->secure_key,
'productcomment_cover_image' => $cover_image,
'allow_guests' => (int) Configuration::get('LEOFEATURE_PRODUCT_REVIEWS_ALLOW_GUESTS'),
'is_logged' => (int) $is_logged,
));
$output = $this->fetch('module:leofeature/views/templates/front/modal_review.tpl');
return $output;
}
//DONGND:: render modal popup
public function renderPriceAttribute($product)
{
$templateVars = array(
'product_price_attribute' => $product,
);
$this->context->smarty->assign($templateVars);
$output = $this->fetch('module:leofeature/views/templates/front/price_attribute.tpl');
return $output;
}
//DONGND:: get list attribute of product
public function getAttributesResume($id_product, $id_lang, $attribute_value_separator = ' - ', $attribute_separator = ', ')
{
if (!Combination::isFeatureActive()) {
return array();
}
$combinations = Db::getInstance()->executeS('SELECT pa.*, product_attribute_shop.*
FROM `' . _DB_PREFIX_ . 'product_attribute` pa
' . Shop::addSqlAssociation('product_attribute', 'pa') . '
WHERE pa.`id_product` = ' . (int) $id_product . '
GROUP BY pa.`id_product_attribute`');
if (!$combinations) {
return false;
}
$product_attributes = array();
foreach ($combinations as $combination) {
$product_attributes[] = (int) $combination['id_product_attribute'];
}
$lang = Db::getInstance()->executeS('SELECT pac.id_product_attribute, GROUP_CONCAT(agl.`name`, \'' . pSQL($attribute_value_separator) . '\',al.`name` ORDER BY agl.`id_attribute_group` SEPARATOR \'' . pSQL($attribute_separator) . '\') as attribute_designation
FROM `' . _DB_PREFIX_ . 'product_attribute_combination` pac
LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON a.`id_attribute` = pac.`id_attribute`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = ' . (int) $id_lang . ')
WHERE pac.id_product_attribute IN (' . implode(',', $product_attributes) . ')
GROUP BY pac.id_product_attribute');
foreach ($lang as $k => $row) {
$combinations[$k]['attribute_designation'] = $row['attribute_designation'];
}
//Get quantity of each variations
foreach ($combinations as $key => $row) {
$cache_key = $row['id_product'] . '_' . $row['id_product_attribute'] . '_quantity';
if (!Cache::isStored($cache_key)) {
$result = StockAvailable::getQuantityAvailableByProduct($row['id_product'], $row['id_product_attribute']);
Cache::store($cache_key, $result);
$combinations[$key]['quantity'] = $result;
} else {
$combinations[$key]['quantity'] = Cache::retrieve($cache_key);
}
}
return $combinations;
}
//DONGND:: get list attribute of product inherit to attribute of its
public function getProductAttributeWhitelist()
{
return array(
"customizable",
"available_for_order",
"customization_required",
"customizations",
"allow_oosp",
);
}
//DONGND:: render dopdown cart
public function renderDropDown($only_total)
{
// echo '';
// print_r((new CartPresenter)->present($this->context->cart));die();
$cart = (new CartPresenter)->present($this->context->cart);
$drop_down_html = '';
if ($cart['products_count'] > 0) {
$templateVars = array(
'only_total' => $only_total,
'cart' => $cart,
'cart_url' => $this->context->link->getPageLink('cart', null, $this->context->language->id, array('action' => 'show'), false, null, true),
'order_url' => $this->context->link->getPageLink('order'),
'enable_update_quantity' => (int) Configuration::get('LEOFEATURE_ENABLE_UPDATE_QUANTITY_ALLCART'),
'enable_button_quantity' => (int) Configuration::get('LEOFEATURE_ENABLE_BUTTON_QUANTITY_ALLCART'),
'show_combination' => (int) Configuration::get('LEOFEATURE_SHOW_COMBINATION_ALLCART'),
'show_customization' => (int) Configuration::get('LEOFEATURE_SHOW_CUSTOMIZATION_ALLCART'),
// 'cart_count' => $cart['products_count'],
'width_cart_item' => Configuration::get('LEOFEATURE_WIDTH_CARTITEM_ALLCART'),
'height_cart_item' => Configuration::get('LEOFEATURE_HEIGHT_CARTITEM_ALLCART')
);
$this->smarty->assign($templateVars);
$drop_down_html = $this->fetch('module:leofeature/views/templates/front/drop_down.tpl');
}
return $drop_down_html;
}
/**
* Common method
* Resgister all hook for module
*/
public function registerLeoHook()
{
$res = true;
$res &= $this->registerHook('header');
$res &= $this->registerHook('displayLeoCartButton');
$res &= $this->registerHook('displayLeoCartQuantity');
$res &= $this->registerHook('displayLeoCartAttribute');
$res &= $this->registerHook('displayBackOfficeHeader');
$res &= $this->registerHook('displayLeoProductReviewExtra');
$res &= $this->registerHook('displayLeoProductTab');
$res &= $this->registerHook('displayLeoProductTabContent');
$res &= $this->registerHook('displayLeoProductListReview');
$res &= $this->registerHook('displayLeoCompareButton');
$res &= $this->registerHook('displayLeoWishlistButton');
$res &= $this->registerHook('displayLeoProducReviewCompare');
$res &= $this->registerHook('displayCustomerAccount');
$res &= $this->registerHook('actionAdminControllerSetMedia');
$res &= $this->registerHook('displayBeforeBodyClosingTag');
$res &= $this->registerHook('actionUpdateLangAfter');
return $res;
}
/**
* Common method
* Unresgister all hook for module
*/
public function unregisterLeoHook()
{
$res = true;
$res &= $this->unregisterHook('header');
$res &= $this->unregisterHook('displayLeoCartButton');
$res &= $this->unregisterHook('displayLeoCartQuantity');
$res &= $this->unregisterHook('displayLeoCartAttribute');
$res &= $this->unregisterHook('displayBackOfficeHeader');
$res &= $this->unregisterHook('displayLeoProductReviewExtra');
$res &= $this->unregisterHook('displayLeoProductTab');
$res &= $this->unregisterHook('displayLeoProductTabContent');
$res &= $this->unregisterHook('displayLeoProductListReview');
$res &= $this->unregisterHook('displayLeoCompareButton');
$res &= $this->unregisterHook('displayLeoWishlistButton');
$res &= $this->unregisterHook('displayLeoProducReviewCompare');
$res &= $this->unregisterHook('displayCustomerAccount');
$res &= $this->unregisterHook('actionAdminControllerSetMedia');
$res &= $this->unregisterHook('displayBeforeBodyClosingTag');
return $res;
}
/**
* Install Module Tabs
*/
private function installModuleTab($title, $class_sfx = '', $parent = '')
{
$class = 'Admin' . Tools::ucfirst($this->name) . Tools::ucfirst($class_sfx);
// @copy(_PS_MODULE_DIR_.$this->name.'/logo.gif', _PS_IMG_DIR_.'t/'.$class.'.gif');
if ($parent == '') {
# validate module
$position = Tab::getCurrentTabId();
} else {
# validate module
$position = Tab::getIdFromClassName($parent);
}
$tab1 = new Tab();
$tab1->class_name = $class;
$tab1->module = $this->name;
$tab1->id_parent = (int) $position;
$langs = Language::getLanguages(false);
foreach ($langs as $l) {
# validate module
$tab1->name[$l['id_lang']] = $title;
}
$tab1->add(true, false);
}
/**
* Uninstall tabs
*/
private function uninstallModuleTab($class_sfx = '')
{
$tab_class = 'Admin' . Tools::ucfirst($this->name) . Tools::ucfirst($class_sfx);
$id_tab = Tab::getIdFromClassName($tab_class);
if ($id_tab != 0) {
$tab = new Tab($id_tab);
$tab->delete();
return true;
}
return false;
}
/**
* Creates tables
*/
protected function createTables()
{
if ($this->_installDataSample()) {
return true;
}
$res = 1;
include_once(dirname(__FILE__) . '/install/install.php');
return $res;
}
public function deleteTables()
{
return Db::getInstance()->execute('
DROP TABLE IF EXISTS
`' . _DB_PREFIX_ . 'leofeature_product_review`,
`' . _DB_PREFIX_ . 'leofeature_product_review_criterion`,
`' . _DB_PREFIX_ . 'leofeature_product_review_criterion_product`,
`' . _DB_PREFIX_ . 'leofeature_product_review_criterion_lang`,
`' . _DB_PREFIX_ . 'leofeature_product_review_criterion_category`,
`' . _DB_PREFIX_ . 'leofeature_product_review_grade`,
`' . _DB_PREFIX_ . 'leofeature_product_review_usefulness`,
`' . _DB_PREFIX_ . 'leofeature_product_review_report`,
`' . _DB_PREFIX_ . 'leofeature_compare`,
`' . _DB_PREFIX_ . 'leofeature_compare_product`,
`' . _DB_PREFIX_ . 'leofeature_wishlist`,
`' . _DB_PREFIX_ . 'leofeature_wishlist_product`
');
}
//DONGND:: create configs
public function createConfiguration()
{
$list_config_create = array(
'LEOFEATURE_ENABLE_AJAXCART' => 1,
'LEOFEATURE_ENABLE_SELECTATTRIBUTE' => 0,
'LEOFEATURE_ENABLE_UPDATELABEL' => 0,
'LEOFEATURE_ENABLE_INPUTQUANTITY' => 1,
'LEOFEATURE_ENABLE_FLYCART_EFFECT' => 1,
'LEOFEATURE_ENABLE_NOTIFICATION' => 0,
'LEOFEATURE_SHOW_POPUP' => 1,
'LEOFEATURE_ENABLE_PRODUCT_REVIEWS' => 1,
'LEOFEATURE_SHOW_PRODUCT_REVIEWS_LISTPRODUCT' => 1,
'LEOFEATURE_SHOW_NUMBER_PRODUCT_REVIEWS_LISTPRODUCT' => 1,
'LEOFEATURE_SHOW_ZERO_PRODUCT_REVIEWS_LISTPRODUCT' => 1,
'LEOFEATURE_PRODUCT_REVIEWS_MINIMAL_TIME' => 30,
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_GUESTS' => 0,
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_USEFULL_BUTTON' => 1,
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_REPORT_BUTTON' => 1,
'LEOFEATURE_PRODUCT_REVIEWS_MODERATE' => 1,
'LEOFEATURE_ENABLE_PRODUCTCOMPARE' => 1,
'LEOFEATURE_SHOW_PRODUCTCOMPARE_PRODUCTPAGE' => 1,
'LEOFEATURE_SHOW_PRODUCTCOMPARE_LISTPRODUCT' => 1,
'LEOFEATURE_COMPARATOR_MAX_ITEM' => 3,
'LEOFEATURE_ENABLE_PRODUCTWISHLIST' => 1,
'LEOFEATURE_SHOW_PRODUCTWISHLIST_PRODUCTPAGE' => 1,
'LEOFEATURE_SHOW_PRODUCTWISHLIST_LISTPRODUCT' => 1,
'LEOFEATURE_DEFAULT_TAB' => '#fieldset_0',
'LEOFEATURE_ENABLE_DROPDOWN_DEFAULTCART' => 1,
'LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART' => 'dropdown',
// 'LEOFEATURE_ENABLE_PUSHEFFECT_DEFAULTCART' => 0,
'LEOFEATURE_ENABLE_DROPDOWN_FLYCART' => 0,
'LEOFEATURE_TYPE_DROPDOWN_FLYCART' => 'slidebar_bottom',
// 'LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART' => 0,
'LEOFEATURE_TYPE_POSITION_FLYCART' => 'fixed',
'LEOFEATURE_POSITION_VERTICAL_FLYCART' => 'bottom',
'LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART' => 20,
'LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART' => 'pixel',
'LEOFEATURE_POSITION_HORIZONTAL_FLYCART' => 'left',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART' => 20,
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART' => 'pixel',
'LEOFEATURE_TYPE_EFFECT_FLYCART' => 'fade',
'LEOFEATURE_ENABLE_OVERLAYBACKGROUND_ALLCART' => 0,
'LEOFEATURE_ENABLE_UPDATE_QUANTITY_ALLCART' => 1,
'LEOFEATURE_ENABLE_BUTTON_QUANTITY_ALLCART' => 1,
'LEOFEATURE_SHOW_COMBINATION_ALLCART' => 1,
'LEOFEATURE_SHOW_CUSTOMIZATION_ALLCART' => 1,
'LEOFEATURE_WIDTH_CARTITEM_ALLCART' => 265,
'LEOFEATURE_HEIGHT_CARTITEM_ALLCART' => 135,
'LEOFEATURE_NUMBER_CARTITEM_DISPLAY_ALLCART' => 3,
// 'LEOFEATURE_WIDTH_NOTIFICATION' => 320,
'LEOFEATURE_WIDTH_NOTIFICATION' => 100,
'LEOFEATURE_WIDTH_UNIT_NOTIFICATION' => 'percent',
'LEOFEATURE_POSITION_VERTICAL_NOTIFICATION' => 'top',
'LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION' => 0,
'LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION' => 'pixel',
'LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION' => 'left',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION' => 0,
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION' => 'pixel',
'LEOFEATURE_PRODUCTATTRIBUTE_TYPE' => 0,
'LEOFEATURE_PRODUCTATTRIBUTE_SHOW_LABLE' => 1,
);
foreach ($list_config_create as $key => $value) {
Configuration::updateValue($key, $value);
}
return true;
}
//DONGND:: delete configs
public function deleteConfiguration()
{
$list_config_delete = array(
'LEOFEATURE_ENABLE_AJAXCART',
'LEOFEATURE_ENABLE_SELECTATTRIBUTE',
'LEOFEATURE_ENABLE_UPDATELABEL',
'LEOFEATURE_ENABLE_INPUTQUANTITY',
'LEOFEATURE_ENABLE_FLYCART_EFFECT',
'LEOFEATURE_ENABLE_NOTIFICATION',
'LEOFEATURE_SHOW_POPUP',
'LEOFEATURE_ENABLE_PRODUCT_REVIEWS',
'LEOFEATURE_SHOW_PRODUCT_REVIEWS_LISTPRODUCT',
'LEOFEATURE_SHOW_NUMBER_PRODUCT_REVIEWS_LISTPRODUCT',
'LEOFEATURE_SHOW_ZERO_PRODUCT_REVIEWS_LISTPRODUCT',
'LEOFEATURE_PRODUCT_REVIEWS_MINIMAL_TIME',
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_GUESTS',
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_USEFULL_BUTTON',
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_REPORT_BUTTON',
'LEOFEATURE_PRODUCT_REVIEWS_MODERATE',
'LEOFEATURE_ENABLE_PRODUCTCOMPARE',
'LEOFEATURE_SHOW_PRODUCTCOMPARE_PRODUCTPAGE',
'LEOFEATURE_SHOW_PRODUCTCOMPARE_LISTPRODUCT',
'LEOFEATURE_COMPARATOR_MAX_ITEM',
'LEOFEATURE_ENABLE_PRODUCTWISHLIST',
'LEOFEATURE_SHOW_PRODUCTWISHLIST_PRODUCTPAGE',
'LEOFEATURE_SHOW_PRODUCTWISHLIST_LISTPRODUCT',
'LEOFEATURE_DEFAULT_TAB',
'LEOFEATURE_ENABLE_DROPDOWN_DEFAULTCART',
'LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART',
// 'LEOFEATURE_ENABLE_PUSHEFFECT_DEFAULTCART',
'LEOFEATURE_ENABLE_DROPDOWN_FLYCART',
'LEOFEATURE_TYPE_DROPDOWN_FLYCART',
// 'LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART',
'LEOFEATURE_TYPE_POSITION_FLYCART',
'LEOFEATURE_POSITION_VERTICAL_FLYCART',
'LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART',
'LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART',
'LEOFEATURE_POSITION_HORIZONTAL_FLYCART',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART',
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART',
'LEOFEATURE_TYPE_EFFECT_FLYCART',
'LEOFEATURE_ENABLE_OVERLAYBACKGROUND_ALLCART',
'LEOFEATURE_ENABLE_UPDATE_QUANTITY_ALLCART',
'LEOFEATURE_ENABLE_BUTTON_QUANTITY_ALLCART',
'LEOFEATURE_SHOW_COMBINATION_ALLCART',
'LEOFEATURE_SHOW_CUSTOMIZATION_ALLCART',
'LEOFEATURE_WIDTH_CARTITEM_ALLCART',
'LEOFEATURE_HEIGHT_CARTITEM_ALLCART',
'LEOFEATURE_NUMBER_CARTITEM_DISPLAY_ALLCART',
'LEOFEATURE_WIDTH_NOTIFICATION',
'LEOFEATURE_WIDTH_UNIT_NOTIFICATION',
'LEOFEATURE_POSITION_VERTICAL_NOTIFICATION',
'LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION',
'LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION',
'LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION',
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION',
'LEOFEATURE_PRODUCTATTRIBUTE_TYPE',
'LEOFEATURE_PRODUCTATTRIBUTE_SHOW_LABLE',
);
foreach ($list_config_delete as $list_config_delete_val) {
Configuration::deleteByName($list_config_delete_val);
}
return true;
}
private function _installDataSample()
{
if (!file_exists(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php')) {
return false;
}
require_once(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php');
$sample = new Datasample(1);
return $sample->processImport($this->name);
}
public function _clearCache($template, $cache_id = null, $compile_id = null)
{
// validate module
unset($cache_id);
unset($compile_id);
parent::_clearCache($template);
}
public function autoUpdateModule()
{
$module = Module::getInstanceByName('leofeature');
if (Configuration::get('LEOFEATURE_CORRECT_MOUDLE') != $module->version) {
Configuration::updateValue('LEOFEATURE_CORRECT_MOUDLE', $module->version);
$this->correctModule();
}
}
public function correctModule()
{
if (Configuration::hasKey('LEOFEATURE_ENABLE_PUSHEFFECT_DEFAULTCART')) {
Configuration::updateValue('LEOFEATURE_ENABLE_PUSHEFFECT_DEFAULTCART', 0);
}
if (Configuration::hasKey('LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART')) {
Configuration::updateValue('LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART', 0);
}
$list_config_check = array(
'LEOFEATURE_WIDTH_CARTITEM_ALLCART' => 265,
'LEOFEATURE_HEIGHT_CARTITEM_ALLCART' => 135,
'LEOFEATURE_NUMBER_CARTITEM_DISPLAY_ALLCART' => 3,
'LEOFEATURE_ENABLE_UPDATE_QUANTITY_ALLCART' => 1,
'LEOFEATURE_ENABLE_BUTTON_QUANTITY_ALLCART' => 1,
'LEOFEATURE_SHOW_COMBINATION_ALLCART' => 1,
'LEOFEATURE_SHOW_CUSTOMIZATION_ALLCART' => 1,
'LEOFEATURE_WIDTH_NOTIFICATION' => 320,
'LEOFEATURE_WIDTH_UNIT_NOTIFICATION' => 'pixel',
'LEOFEATURE_POSITION_VERTICAL_NOTIFICATION' => 'top',
'LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION' => 50,
'LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION' => 'pixel',
'LEOFEATURE_POSITION_HORIZONTAL_NOTIFICATION' => 'right',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION' => 20,
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION' => 'pixel',
'LEOFEATURE_SHOW_POPUP' => 1,
'LEOFEATURE_ENABLE_NOTIFICATION' => 0,
'LEOFEATURE_ENABLE_OVERLAYBACKGROUND_ALLCART' => 0,
'LEOFEATURE_TYPE_POSITION_FLYCART' => 'fixed',
'LEOFEATURE_POSITION_VERTICAL_FLYCART' => 'bottom',
'LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART' => 20,
'LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART' => 'pixel',
'LEOFEATURE_POSITION_HORIZONTAL_FLYCART' => 'left',
'LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART' => 20,
'LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART' => 'pixel',
// 'LEOFEATURE_ENABLE_PUSHEFFECT_FLYCART' => 0,
'LEOFEATURE_TYPE_DROPDOWN_FLYCART' => 'slidebar_bottom',
'LEOFEATURE_ENABLE_DROPDOWN_FLYCART' => 0,
// 'LEOFEATURE_ENABLE_PUSHEFFECT_DEFAULTCART' => 0,
'LEOFEATURE_TYPE_DROPDOWN_DEFAULTCART' => 'dropdown',
'LEOFEATURE_ENABLE_DROPDOWN_DEFAULTCART' => 1,
'LEOFEATURE_SHOW_ZERO_PRODUCT_REVIEWS_LISTPRODUCT' => 1,
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_USEFULL_BUTTON' => 1,
'LEOFEATURE_PRODUCT_REVIEWS_ALLOW_REPORT_BUTTON' => 1,
'LEOFEATURE_ENABLE_UPDATELABEL' => 0,
'LEOFEATURE_ENABLE_FLYCART_EFFECT' => 1,
'LEOFEATURE_TYPE_EFFECT_FLYCART' => 'fade',
);
foreach ($list_config_check as $key => $value) {
if (!Configuration::hasKey($key)) {
Configuration::updateValue($key, $value);
}
};
//DONGND:: add hook for attribute of product
$this->registerHook('displayLeoCartAttribute');
//DONGND:: add hook for quantity of product
$this->registerHook('displayLeoCartQuantity');
//DONGND:: add id field to product_review_grade table
$sql = 'SHOW FIELDS FROM `' . _DB_PREFIX_ . 'leofeature_product_review_grade` LIKE "id_product_review_grade"';
$column = Db::getInstance()->executeS($sql);
if (empty($column)) {
Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'leofeature_product_review_grade DROP PRIMARY KEY');
Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'leofeature_product_review_grade ADD id_product_review_grade INT AUTO_INCREMENT PRIMARY KEY FIRST');
}
//DONGND:: add hook for fly cart
$this->registerHook('displayBeforeBodyClosingTag');
if (Tools::getValue('success')) {
switch (Tools::getValue('success')) {
case 'correct':
$this->html .= $this->displayConfirmation($this->l('Correct Module is successful'));
break;
}
}
if ( Configuration::get('LEOFEATURE_PRODUCTATTRIBUTE_TYPE') === false && Configuration::get('LEOFEATURE_ENABLE_SELECTATTRIBUTE') !== false) {
Configuration::updateValue('LEOFEATURE_PRODUCTATTRIBUTE_TYPE', Configuration::get('LEOFEATURE_ENABLE_SELECTATTRIBUTE'));
}
}
/**
* Run only one when install/change Theme_of_Leo
*/
public function hookActionAdminBefore($params)
{
if (isset($params) && isset($params['controller']) && isset($params['controller']->theme_manager)) {
// Validate : call hook from theme_manager
} else {
// Other module call this hook -> duplicate data
return;
}
$this->unregisterHook('actionAdminBefore');
# FIX : update Prestashop by 1-Click module -> NOT NEED RESTORE DATABASE
$ap_version = Configuration::get('AP_CURRENT_VERSION');
if ($ap_version != false) {
$ps_version = Configuration::get('PS_VERSION_DB');
$versionCompare = version_compare($ap_version, $ps_version);
if ($versionCompare != 0) {
// Just update Prestashop
Configuration::updateValue('AP_CURRENT_VERSION', $ps_version);
return;
}
}
# WHENE INSTALL THEME, INSERT HOOK FROM DATASAMPLE IN THEME
$hook_from_theme = false;
if (file_exists(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php')) {
require_once(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php');
$sample = new Datasample();
if ($sample->processHook($this->name)) {
$hook_from_theme = true;
};
}
# INSERT HOOK FROM MODULE_DATASAMPLE
if ($hook_from_theme == false) {
$this->registerLeoHook();
}
# WHEN INSTALL MODULE, NOT NEED RESTORE DATABASE IN THEME
$install_module = (int) Configuration::get('AP_INSTALLED_LEOFEATURE', 0);
if ($install_module) {
Configuration::updateValue('AP_INSTALLED_LEOFEATURE', '0'); // next : allow restore sample
return;
}
# INSERT DATABASE FROM THEME_DATASAMPLE
if (file_exists(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php')) {
require_once(_PS_MODULE_DIR_ . 'appagebuilder/libs/LeoDataSample.php');
$sample = new Datasample();
$sample->processImport($this->name);
}
}
protected function postValidation()
{
if (Tools::isSubmit('submitLeofeatureConfig')) {
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_COMPARATOR_MAX_ITEM'))) {
$this->_postErrors[] = $this->l('"Number product comparison" is invalid. Must an integer validity (unsigned).');
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_PRODUCT_REVIEWS_MINIMAL_TIME'))) {
$this->_postErrors[] = $this->l('"Minimum time between 2 reviews from the same user" is invalid. Must an integer validity (unsigned).');
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART'))) {
$this->_postErrors[] = $this->l('"Position By Vertical Value (Fly Cart)" is invalid. Must an integer validity (unsigned).');
} else {
if (Tools::getValue('LEOFEATURE_POSITION_VERTICAL_UNIT_FLYCART') == 'percent' && Tools::getValue('LEOFEATURE_POSITION_VERTICAL_VALUE_FLYCART') > 100) {
$this->_postErrors[] = $this->l('"Position By Vertical Value (Fly Cart)" is invalid. Must an integer validity (unsigned). Must has value from 0 to 100 with the unit type is percent');
}
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART'))) {
$this->_postErrors[] = $this->l('"Position By Horizontal Value (Fly Cart)" is invalid. Must an integer validity (unsigned).');
} else {
if (Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_UNIT_FLYCART') == 'percent' && Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_VALUE_FLYCART') > 100) {
$this->_postErrors[] = $this->l('"Position By Horizontal Value (Fly Cart)" is invalid. Must an integer validity (unsigned). Must has value from 0 to 100 with the unit type is percent');
}
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_WIDTH_CARTITEM_ALLCART'))) {
$this->_postErrors[] = $this->l('"Width Of Cart Item (All Cart)" is invalid. Must an integer validity (unsigned).');
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_HEIGHT_CARTITEM_ALLCART'))) {
$this->_postErrors[] = $this->l('"Height Of Cart Item (All Cart)" is invalid. Must an integer validity (unsigned).');
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_NUMBER_CARTITEM_DISPLAY_ALLCART'))) {
$this->_postErrors[] = $this->l('"Number Cart Item To Display (All Cart)" is invalid. Must an integer validity (unsigned).');
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_WIDTH_NOTIFICATION'))) {
$this->_postErrors[] = $this->l('"Width (Notification)" is invalid. Must an integer validity (unsigned).');
} else {
if (Tools::getValue('LEOFEATURE_WIDTH_UNIT_NOTIFICATION') == 'percent' && Tools::getValue('LEOFEATURE_WIDTH_NOTIFICATION') > 100) {
$this->_postErrors[] = $this->l('"Width (Notification)" is invalid. Must an integer validity (unsigned). Must has value from 0 to 100 with the unit width is percent');
}
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION'))) {
$this->_postErrors[] = $this->l('"Position By Vertical Value (Notification)" is invalid. Must an integer validity (unsigned).');
} else {
if (Tools::getValue('LEOFEATURE_POSITION_VERTICAL_UNIT_NOTIFICATION') == 'percent' && Tools::getValue('LEOFEATURE_POSITION_VERTICAL_VALUE_NOTIFICATION') > 100) {
$this->_postErrors[] = $this->l('"Position By Vertical Value (Notification)" is invalid. Must an integer validity (unsigned). Must has value from 0 to 100 with the unit type is percent');
}
}
if (!Validate::isUnsignedInt(Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION'))) {
$this->_postErrors[] = $this->l('"Position By Horizontal Value (Notification)" is invalid. Must an integer validity (unsigned).');
} else {
if (Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_UNIT_NOTIFICATION') == 'percent' && Tools::getValue('LEOFEATURE_POSITION_HORIZONTAL_VALUE_NOTIFICATION') > 100) {
$this->_postErrors[] = $this->l('"Position By Horizontal Value (Notification)" is invalid. Must an integer validity (unsigned). Must has value from 0 to 100 with the unit type is percent');
}
}
}
}
//DONGND:: check token
public function isTokenValid()
{
if (!Configuration::get('PS_TOKEN_ENABLE')) {
return true;
}
return strcasecmp(Tools::getToken(false), Tools::getValue('token')) == 0;
}
// public function isCached($template, $cache_id = null, $compile_id = null)
// {
// if (version_compare(_PS_VERSION_, '1.7.4.0', '>=') || version_compare(Configuration::get('PS_VERSION_DB'), '1.7.4.0', '>=')) {
// return false;
// }
// return parent::isCached($template, $cache_id, $compile_id);
// }
/**
* FIX BUG 1.7.3.3 : install theme lose hook displayHome, displayLeoProfileProduct
* because ajax not run hookActionAdminBefore();
*/
public function autoRestoreSampleData()
{
if(Hook::isModuleRegisteredOnHook($this, 'actionAdminBefore', (int)Context::getContext()->shop->id)) {
$theme_manager = new stdclass();
$theme_manager->theme_manager = 'theme_manager';
$this->hookActionAdminBefore(array(
'controller' => $theme_manager,
));
}
}
//DONGND:: update direction css, js, img for 1.7.4.0
public function getMediaDir()
{
$media_dir = '';
if (version_compare(_PS_VERSION_, '1.7.4.0', '>=') || version_compare(Configuration::get('PS_VERSION_DB'), '1.7.4.0', '>=')) {
$media_dir = 'modules/'.$this->name.'/views/';
}else{
$media_dir = 'modules/'.$this->name.'/';
}
return $media_dir;
}
/**
* PERMISSION ACCOUNT demo@demo.com
*/
public function getPermission($variable, $employee = null)
{
if($variable == 'configure')
{
// Allow see form if permission is : configure, view
$configure = Module::getPermissionStatic($this->id, 'configure', $employee);
$view = Module::getPermissionStatic($this->id, 'view', $employee);
return ($configure || $view);
}
return Module::getPermissionStatic($this->id, $variable, $employee);
}
/**
* PERMISSION ACCOUNT demo@demo.com
*/
public function access($action)
{
$employee = null;
return Module::getPermissionStatic($this->id, $action, $employee);
}
public function hookactionUpdateLangAfter($params)
{
if (isset($params['lang']->id)) {
$id_lang = $params['lang']->id;
$data_langs = Db::getInstance()->executeS(
'SELECT `name`, `id_product_review_criterion`
FROM `'._DB_PREFIX_.'leofeature_product_review_criterion_lang`
WHERE `id_lang` = ' . (int)$this->context->language->id
);
if (!empty($data_langs)) {
foreach ($data_langs as $data_lang) {
Db::getInstance()->execute(
'INSERT INTO `'._DB_PREFIX_.'leofeature_product_review_criterion_lang`
(`id_product_review_criterion`, `id_lang`, `name`) VALUES
("'.(int)$data_lang['id_product_review_criterion'].'","'.(int)$id_lang.'","'.pSQL($data_lang['name']).'")'
);
}
}
}
}
public function hookDisplayBackOfficeHeader()
{
$this->autoUpdateModule();
}
}