first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
/**
* 2007-2015 Leotheme
*
* NOTICE OF LICENSE
*
* Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list
*
* DISCLAIMER
*
* @author leotheme <leotheme@gmail.com>
* @copyright 2007-2015 Leotheme
* @license http://leotheme.com - prestashop template provider
*/
if (!defined('_PS_VERSION_')) {
# module validation
exit;
}
class AdminLeofeatureModuleController extends ModuleAdminControllerCore
{
public function __construct()
{
parent::__construct();
$url = 'index.php?controller=AdminModules&configure=leofeature&token='.Tools::getAdminTokenLite('AdminModules');
Tools::redirectAdmin($url);
}
}

View File

@@ -0,0 +1,505 @@
<?php
/**
* 2007-2015 Leotheme
*
* NOTICE OF LICENSE
*
* Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list
*
* DISCLAIMER
*
* @author leotheme <leotheme@gmail.com>
* @copyright 2007-2015 Leotheme
* @license http://leotheme.com - prestashop template provider
*/
require_once(_PS_MODULE_DIR_.'leofeature/classes/ProductReviewCriterion.php');
require_once(_PS_MODULE_DIR_.'leofeature/classes/ProductReview.php');
class AdminLeofeatureReviewsController extends ModuleAdminController
{
public function __construct()
{
parent::__construct();
$this->bootstrap = true;
$this->table = 'leofeature_product_review_criterion';
$this->identifier = 'id_product_review_criterion';
$this->className = 'ProductReviewCriterion';
$this->lang = true;
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'), 'icon' => 'icon-trash'));
$this->fields_list = array(
'id_product_review_criterion' => array(
'title' => $this->l('ID'),
'type' => 'text',
'class' => 'fixed-width-sm'
),
'name' => array(
'title' => $this->l('Name'),
'type' => 'text',
),
'type_name' => array(
'title' => $this->l('Type'),
'type' => 'text',
'search' => false,
),
'active' => array(
'title' => $this->l('Status'),
'active' => 'status',
'type' => 'bool',
'class' => 'fixed-width-sm'
),
);
$this->_defaultOrderBy = 'id_product_review_criterion';
$this->_select .= ' CASE
WHEN `id_product_review_criterion_type` = 1 THEN "'.$this->module->l('Valid for the entire catalog').'"
WHEN `id_product_review_criterion_type` = 2 THEN "'.$this->module->l('Restricted to some categories').'"
WHEN `id_product_review_criterion_type` = 3 THEN "'.$this->module->l('Restricted to some products').'"
END as `type_name` ';
}
public function renderForm()
{
if (Validate::isLoadedObject($this->object)) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
$types = ProductReviewCriterion::getTypes();
$query = array();
foreach ($types as $key => $value) {
$query[] = array(
'id' => $key,
'label' => $value,
);
}
if (Tools::getValue('id_product_review_criterion')) {
$id_criterion = Tools::getValue('id_product_review_criterion');
} else {
$id_criterion = 0;
}
$criterion = new ProductReviewCriterion((int) $id_criterion);
$selected_categories = $criterion->getCategories();
$product_table_values = Product::getSimpleProducts($this->context->language->id);
$selected_products = $criterion->getProducts();
foreach ($product_table_values as $key => $product) {
if (false !== array_search($product['id_product'], $selected_products)) {
$product_table_values[$key]['selected'] = 1;
}
}
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$field_category_tree = array(
'type' => 'categories_select',
'name' => 'categoryBox',
'label' => $this->l('Criterion will be restricted to the following categories'),
'category_tree' => $this->initCategoriesAssociation(null, $id_criterion),
);
} else {
$field_category_tree = array(
'type' => 'categories',
'label' => $this->l('Criterion will be restricted to the following categories'),
'name' => 'categoryBox',
'desc' => $this->l('Mark the boxes of categories to which this criterion applies.'),
'tree' => array(
'use_search' => false,
'id' => 'categoryBox',
'use_checkbox' => true,
'selected_categories' => $selected_categories,
),
//retro compat 1.5 for category tree
'values' => array(
'trads' => array(
'Root' => Category::getTopCategory(),
'selected' => $this->l('Selected'),
'Collapse All' => $this->l('Collapse All'),
'Expand All' => $this->l('Expand All'),
'Check All' => $this->l('Check All'),
'Uncheck All' => $this->l('Uncheck All'),
),
'selected_cat' => $selected_categories,
'input_name' => 'categoryBox[]',
'use_radio' => false,
'use_search' => false,
'disabled_categories' => array(),
'top_category' => Category::getTopCategory(),
'use_context' => true,
),
);
}
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Add new criterion'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'hidden',
'name' => 'id_product_review_criterion',
),
array(
'type' => 'text',
'lang' => true,
'label' => $this->l('Criterion name'),
'name' => 'name',
),
array(
'type' => 'select',
'name' => 'id_product_review_criterion_type',
'label' => $this->l('Application scope of the criterion'),
'options' => array(
'query' => $query,
'id' => 'id',
'name' => 'label',
),
),
$field_category_tree,
array(
'type' => 'products',
'label' => $this->l('The criterion will be restricted to the following products'),
'name' => 'ids_product',
'values' => $product_table_values,
),
array(
'type' => 'switch',
'is_bool' => true, //retro compat 1.5
'label' => $this->l('Active'),
'name' => 'active',
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled'),
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled'),
),
),
),
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitEditCriterion',
),
'buttons' => array(
'save_and_preview' => array(
'name' => 'submitEditCriterionAndStay',
'type' => 'submit',
'title' => $this->l('Save and stay'),
'class' => 'btn btn-default pull-right',
'icon' => 'process-icon-save-and-stay'
)
)
);
return parent::renderForm();
}
public function renderList()
{
$this->toolbar_title = $this->l('Review Criteria');
$return = null;
$return .= $this->renderModerateLists();
$return .= parent::renderList();
$return .= $this->renderReviewsList();
return $return;
}
public function postProcess()
{
if (count($this->errors) > 0) {
if ($this->ajax) {
$array = array('hasError' => true, 'errors' => $this->errors[0]);
die(Tools::jsonEncode($array));
}
return;
}
if (Tools::isSubmit('submitEditCriterion') || Tools::isSubmit('submitEditCriterionAndStay')) {
parent::validateRules();
if (count($this->errors)) {
$this->display = 'edit';
return false;
}
if ((int) Tools::getValue('id_product_review_criterion')) {
$mess_id = '4';
} else {
$mess_id = '3';
}
$criterion = new ProductReviewCriterion((int) Tools::getValue('id_product_review_criterion'));
$criterion->id_product_review_criterion_type = Tools::getValue('id_product_review_criterion_type');
$criterion->active = Tools::getValue('active');
$languages = Language::getLanguages();
$name = array();
foreach ($languages as $key => $value) {
$name[$value['id_lang']] = Tools::getValue('name_'.$value['id_lang']);
}
// validate module
unset($key);
$criterion->name = $name;
$criterion->save();
// Clear before reinserting data
$criterion->deleteCategories();
$criterion->deleteProducts();
if ($criterion->id_product_review_criterion_type == 2) {
if ($categories = Tools::getValue('categoryBox')) {
if (count($categories)) {
foreach ($categories as $id_category) {
$criterion->addCategory((int) $id_category);
}
}
}
} elseif ($criterion->id_product_review_criterion_type == 3) {
if ($products = Tools::getValue('ids_product')) {
if (count($products)) {
foreach ($products as $product) {
$criterion->addProduct((int) $product);
}
}
}
}
if ($criterion->save()) {
if (Tools::isSubmit('submitEditCriterionAndStay')) {
# validate module
$this->redirect_after = self::$currentIndex.'&'.$this->identifier.'='.$criterion->id.'&conf='.$mess_id.'&update'.$this->table.'&token='.$this->token;
} else {
# validate module
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
}
} else {
return false;
}
} elseif (Tools::isSubmit('deleteleofeature_product_review') && Tools::getValue('id_product_review')) {
$id_product_review = (int) Tools::getValue('id_product_review');
$review = new ProductReview($id_product_review);
$review->delete();
// var_dump($review->delete());die();
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token;
} elseif (Tools::isSubmit('approveReview') && Tools::getValue('id_product_review')) {
$id_product_review = (int) Tools::getValue('id_product_review');
$review = new ProductReview($id_product_review);
$review->validate();
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
} elseif (Tools::isSubmit('noabuseReview') && Tools::getValue('id_product_review')) {
$id_product_review = (int) Tools::getValue('id_product_review');
ProductReview::deleteReports($id_product_review);
$this->redirect_after = self::$currentIndex.'&conf=4&token='.$this->token;
} else {
parent::postProcess(true);
}
$this->module->_clearcache('leo_list_product_review.tpl');
}
public function initCategoriesAssociation($id_root = null, $id_criterion = 0)
{
if (is_null($id_root)) {
$id_root = Configuration::get('PS_ROOT_CATEGORY');
}
$id_shop = (int) Tools::getValue('id_shop');
$shop = new Shop($id_shop);
if ($id_criterion == 0) {
$selected_cat = array();
} else {
$pdc_object = new ProductReviewCriterion($id_criterion);
$selected_cat = $pdc_object->getCategories();
}
if (Shop::getContext() == Shop::CONTEXT_SHOP && Tools::isSubmit('id_shop')) {
$root_category = new Category($shop->id_category);
} else {
$root_category = new Category($id_root);
}
$root_category = array('id_category' => $root_category->id, 'name' => $root_category->name[$this->context->language->id]);
$helper = new Helper();
return $helper->renderCategoryTree($root_category, $selected_cat, 'categoryBox', false, true);
}
//DONGND:: render list reviews have not approved and reported
public function renderModerateLists()
{
$return = null;
if (Configuration::get('LEOFEATURE_PRODUCT_REVIEWS_MODERATE')) {
$reviews = ProductReview::getByValidate(0, false);
if (count($reviews) > 0) {
$fields_list = $this->getStandardFieldList();
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$return .= $this->l('Reviews waiting for approval');
$actions = array('enable', 'delete');
} else {
$actions = array('approve', 'delete');
}
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
$helper->actions = $actions;
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->listTotal = count($reviews);
$helper->identifier = 'id_product_review';
$helper->title = $this->l('Reviews waiting for approval');
$helper->table = 'leofeature_product_review';
$helper->token = $this->token;
$helper->currentIndex = self::$currentIndex;
$helper->no_link = true;
$return .= $helper->generateList($reviews, $fields_list);
}
}
$reviews = ProductReview::getReportedReviews();
if (count($reviews) > 0) {
$fields_list = $this->getStandardFieldList();
if (version_compare(_PS_VERSION_, '1.6', '<')) {
$return .= $this->l('Reported Reviews');
$actions = array('enable', 'delete');
} else {
$actions = array('delete', 'noabuse');
}
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
$helper->actions = $actions;
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->listTotal = count($reviews);
$helper->identifier = 'id_product_review';
$helper->title = $this->l('Reported Reviews');
$helper->table = 'leofeature_product_review';
$helper->token = $this->token;
$helper->currentIndex = self::$currentIndex;
$helper->no_link = true;
$return .= $helper->generateList($reviews, $fields_list);
}
return $return;
}
//DONGND:: render list reviews have approved
public function renderReviewsList()
{
$reviews = ProductReview::getByValidate(1, false);
$moderate = Configuration::get('LEOFEATURE_PRODUCT_REVIEWS_MODERATE');
if (empty($moderate)) {
$reviews = array_merge($reviews, ProductReview::getByValidate(0, false));
}
$fields_list = $this->getStandardFieldList();
$helper = new HelperList();
$helper->shopLinkType = '';
$helper->simple_header = true;
$helper->actions = array('delete');
$helper->show_toolbar = false;
$helper->module = $this->module;
$helper->listTotal = count($reviews);
$helper->identifier = 'id_product_review';
$helper->title = $this->l('Approved Reviews');
$helper->table = 'leofeature_product_review';
$helper->token = $this->token;
$helper->currentIndex = self::$currentIndex;
$helper->no_link = true;
return $helper->generateList($reviews, $fields_list);
}
public function displayApproveLink($token, $id, $name = null)
{
// validate module
unset($token);
unset($name);
$template = $this->createTemplate('list_action_approve.tpl');
$template->assign(array(
'href' => $this->context->link->getAdminLink('AdminLeofeatureReviews').'&approveReview&id_product_review='.$id,
'action' => $this->l('Approve'),
));
return $template->fetch();
}
public function displayNoabuseLink($token, $id, $name = null)
{
// validate module
unset($token);
unset($name);
$template = $this->createTemplate('list_action_noabuse.tpl');
$template->assign(array(
'href' => $this->context->link->getAdminLink('AdminLeofeatureReviews').'&noabuseReview&id_product_review='.$id,
'action' => $this->l('Not abusive'),
));
return $template->fetch();
}
public function getStandardFieldList()
{
return array(
'id_product_review' => array(
'title' => $this->l('ID'),
'type' => 'text',
),
'title' => array(
'title' => $this->l('Review title'),
'type' => 'text',
),
'content' => array(
'title' => $this->l('Review'),
'type' => 'text',
),
'grade' => array(
'title' => $this->l('Rating'),
'type' => 'text',
'suffix' => '/5',
),
'customer_name' => array(
'title' => $this->l('Author'),
'type' => 'text',
),
'name' => array(
'title' => $this->l('Product'),
'type' => 'text',
),
'date_add' => array(
'title' => $this->l('Time of publication'),
'type' => 'date',
),
);
}
/**
* PERMISSION ACCOUNT demo@demo.com
* OVERRIDE CORE
*/
public function initProcess()
{
parent::initProcess();
if (count($this->errors) <= 0) {
if (!$this->access('delete')){
if (Tools::isSubmit('deleteleofeature_product_review')) {
$this->errors[] = $this->trans('You do not have permission to delete this.', array(), 'Admin.Notifications.Error');
}
}
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 13573 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1 @@
<?php

View File

@@ -0,0 +1,36 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 13573 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,384 @@
<?php
/**
* 2007-2015 Leotheme
*
* NOTICE OF LICENSE
*
* Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list
*
* DISCLAIMER
*
* @author leotheme <leotheme@gmail.com>
* @copyright 2007-2015 Leotheme
* @license http://leotheme.com - prestashop template provider
*/
require_once(_PS_MODULE_DIR_.'leofeature/classes/WishList.php');
require_once(_PS_MODULE_DIR_.'leofeature/classes/LeofeatureProduct.php');
class LeoFeatureMyWishListModuleFrontController extends ModuleFrontController
{
public $php_self;
public function displayAjax()
{
$array_result = array();
$errors = array();
$result = array();
if (!$this->isTokenValid() || !Tools::getValue('action')) {
// Ooops! Token is not valid!
$errors[] = $this->l('An error while processing. Please try again', 'mywishlist');
// die('Token is not valid, hack stop');
$array_result['result'] = $result;
$array_result['errors'] = $errors;
die(Tools::jsonEncode($array_result));
};
// Add or remove product with Ajax
$context = Context::getContext();
$action = Tools::getValue('action');
$id_wishlist = (int)Tools::getValue('id_wishlist');
$id_product = (int)Tools::getValue('id_product');
$quantity = (int)Tools::getValue('quantity');
$id_product_attribute = (int)Tools::getValue('id_product_attribute');
// Instance of module class for translations
if ($context->customer->isLogged()) {
if ($id_wishlist && WishList::exists($id_wishlist, $context->customer->id) === true) {
$context->cookie->id_wishlist = (int)$id_wishlist;
}
if ((int)$context->cookie->id_wishlist > 0 && !WishList::exists($context->cookie->id_wishlist, $context->customer->id)) {
$context->cookie->id_wishlist = '';
}
if (($action == 'add' || $action == 'remove') && empty($id_product) === false) {
if (!isset($context->cookie->id_wishlist) || $context->cookie->id_wishlist == '') {
$wishlist = new WishList();
$wishlist->id_shop = $context->shop->id;
$wishlist->id_shop_group = $context->shop->id_shop_group;
$wishlist->default = 1;
$wishlist->name = $this->l('My wishlist', 'mywishlist');
$wishlist->id_customer = (int)$context->customer->id;
list($us, $s) = explode(' ', microtime());
srand($s * $us);
$wishlist->token = Tools::strtoupper(Tools::substr(sha1(uniqid(rand(), true)._COOKIE_KEY_.$context->customer->id), 0, 16));
$wishlist->add();
$context->cookie->id_wishlist = (int)$wishlist->id;
$result['id_wishlist'] = $context->cookie->id_wishlist;
}
if ($action == 'add') {
WishList::addProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute, $quantity);
} else if ($action == 'remove') {
WishList::removeProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute);
}
$result[] = true;
}
if ($action == 'add-wishlist') {
$name_wishlist = Tools::getValue('name_wishlist');
if (empty($name_wishlist)) {
$errors[] = $this->module->l('You must specify a name.', 'mywishlist');
}
if (WishList::isExistsByNameForUser($name_wishlist)) {
$errors[] = $this->module->l('This name is already used by another list.', 'mywishlist');
}
if (!Validate::isMessage($name_wishlist)) {
$errors[] = $this->module->l('This name is is incorrect', 'mywishlist');
}
if (!count($errors)) {
$wishlist = new WishList();
$wishlist->id_shop = $this->context->shop->id;
$wishlist->id_shop_group = $this->context->shop->id_shop_group;
$wishlist->name = $name_wishlist;
$wishlist->id_customer = (int)$this->context->customer->id;
!$wishlist->isDefault($wishlist->id_customer) ? $wishlist->default = 1 : '';
list($us, $s) = explode(' ', microtime());
srand($s * $us);
$wishlist->token = Tools::strtoupper(Tools::substr(sha1(uniqid(rand(), true)._COOKIE_KEY_.$this->context->customer->id), 0, 16));
$wishlist->add();
$leo_is_rewrite_active = (bool)Configuration::get('PS_REWRITING_SETTINGS');
if ($leo_is_rewrite_active) {
$check_leo_is_rewrite_active = '?';
} else {
$check_leo_is_rewrite_active = '&';
}
$checked = '';
if ($wishlist->default == 1) {
$checked = 'checked="checked"';
}
$this->context->smarty->assign(array(
'wishlist' => $wishlist,
'checked' => $checked,
'url_view_wishlist' => $this->context->link->getModuleLink('leofeature', 'viewwishlist').$check_leo_is_rewrite_active.'token='.$wishlist->token,
));
$result['wishlist'] = $this->module->fetch('module:leofeature/views/templates/front/leo_wishlist_new.tpl');
$result['message'] = $this->module->l('The new wishlist has been created', 'mywishlist');
}
}
if ($action == 'delete-wishlist') {
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist)) {
$errors[] = $this->module->l('Cannot delete this wishlist', 'mywishlist');
}
if (!count($errors)) {
$wishlist->delete();
$result[] = true;
}
}
if ($action == 'default-wishlist') {
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist)) {
$errors[] = $this->module->l('Cannot update this wishlist', 'mywishlist');
}
if (!count($errors)) {
$wishlist->setDefault();
$result[] = true;
}
}
if ($action == 'show-wishlist-product') {
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist)) {
$errors[] = $this->module->l('Cannot show the product(s) of this wishlist', 'mywishlist');
}
if (!count($errors)) {
$products = array();
$show_send_wishlist = 0;
$wishlist_product = WishList::getSimpleProductByIdWishlist($id_wishlist);
$product_object = new LeofeatureProduct();
$product_object->php_self = 'mywishlist';
if (count($wishlist_product) > 0) {
foreach ($wishlist_product as $wishlist_product_item) {
$list_product_tmp = array();
$list_product_tmp['wishlist_info'] = $wishlist_product_item;
$list_product_tmp['product_info'] = $product_object->getTemplateVarProduct2($wishlist_product_item['id_product'], $wishlist_product_item['id_product_attribute']);
$products[] = $list_product_tmp;
}
$show_send_wishlist = 1;
}
$wishlists = WishList::getByIdCustomer($this->context->customer->id);
foreach ($wishlists as $key => $wishlists_item) {
if ($wishlists_item['id_wishlist'] == $id_wishlist) {
unset($wishlists[$key]);
}
}
$this->context->smarty->assign(array(
'products' => $products,
'wishlists' => $wishlists,
));
$result['html'] = $this->module->fetch('module:leofeature/views/templates/front/leo_my_wishlist_product.tpl');
$result['show_send_wishlist'] = $show_send_wishlist;
}
}
if ($action == 'send-wishlist') {
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist)) {
$errors[] = $this->module->l('Invalid wishlist', 'mywishlist');
}
if (!count($errors)) {
$to = Tools::getValue('email');
$toName = Tools::safeOutput(Configuration::get('PS_SHOP_NAME'));
$customer = $context->customer;
if (Validate::isLoadedObject($customer)) {
if (Mail::Send($context->language->id, 'wishlist', sprintf(Mail::l('Message from %1$s %2$s', $context->language->id), $customer->lastname, $customer->firstname), array(
'{lastname}' => $customer->lastname,
'{firstname}' => $customer->firstname,
'{wishlist}' => $wishlist->name,
'{message}' => $context->link->getModuleLink('leofeature', 'viewwishlist', array('token' => $wishlist->token))
), $to, $toName, $customer->email, $customer->firstname.' '.$customer->lastname, null, null, $this->module->module_path.'/mails/')) {
$result[] = true;
} else {
$errors[] = $this->module->l('Wishlist send error', 'mywishlist');
}
} else {
$errors[] = $this->module->l('Invalid customer', 'mywishlist');
}
}
}
if ($action == 'delete-wishlist-product') {
$id_wishlist_product = Tools::getValue('id_wishlist_product');
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist) || !Validate::isUnsignedId($id_wishlist_product)) {
$errors[] = $this->module->l('Invalid wishlist', 'mywishlist');
}
if (!count($errors)) {
if (WishList::removeProductWishlist($id_wishlist, $id_wishlist_product)) {
$result[] = true;
} else {
$errors[] = $this->module->l('Cannot delete', 'mywishlist');
}
}
}
if ($action == 'get-wishlist-info') {
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist)) {
$errors[] = $this->module->l('Invalid wishlist', 'mywishlist');
}
if (!count($errors)) {
$wishlist_product = WishList::getInfosByIdCustomer($this->context->customer->id, $id_wishlist);
if ($wishlist_product['nbProducts'] && $wishlist_product['nbProducts'] > 0) {
$result['number_product'] = $wishlist_product['nbProducts'];
} else {
$result['number_product'] = 0;
}
}
}
if ($action == 'update-wishlist-product') {
$id_wishlist_product = Tools::getValue('id_wishlist_product');
$priority = Tools::getValue('priority');
$wishlist = new WishList((int)$id_wishlist);
if ($this->context->customer->id != $wishlist->id_customer || !Validate::isLoadedObject($wishlist) || !Validate::isUnsignedInt($priority) || !Validate::isUnsignedInt($quantity) || !Validate::isUnsignedId($id_wishlist_product)) {
$errors[] = $this->module->l('Invalid wishlist', 'mywishlist');
}
if (!count($errors)) {
if (WishList::updateProductWishlist($id_wishlist, $id_wishlist_product, $priority, $quantity)) {
$result[] = true;
} else {
$errors[] = $this->module->l('Cannot update', 'mywishlist');
}
}
}
if ($action == 'move-wishlist-product') {
$id_wishlist_product = Tools::getValue('id_wishlist_product');
$priority = (int)Tools::getValue('priority');
$id_old_wishlist = (int)Tools::getValue('id_old_wishlist');
$id_new_wishlist = (int)Tools::getValue('id_new_wishlist');
$new_wishlist = new WishList((int)$id_new_wishlist);
$old_wishlist = new WishList((int)$id_old_wishlist);
if (!Validate::isUnsignedId($id_product) || !Validate::isUnsignedInt($id_product_attribute) || !Validate::isUnsignedInt($quantity) ||
!Validate::isUnsignedInt($priority) || ($priority < 0 && $priority > 2) || !Validate::isUnsignedId($id_old_wishlist) || !Validate::isUnsignedId($id_new_wishlist) || !Validate::isUnsignedId($id_wishlist_product) ||
(Validate::isLoadedObject($new_wishlist) && $new_wishlist->id_customer != $this->context->customer->id) ||
(Validate::isLoadedObject($old_wishlist) && $old_wishlist->id_customer != $this->context->customer->id)) {
$errors[] = $this->module->l('Error while moving product to another list', 'mywishlist');
}
$res = true;
$check = Db::getInstance()->getRow('SELECT quantity, id_wishlist_product FROM '._DB_PREFIX_.'leofeature_wishlist_product
WHERE `id_product` = '.(int)$id_product.' AND `id_product_attribute` = '.(int)$id_product_attribute.' AND `id_wishlist` = '.(int)$id_new_wishlist);
$res &= $old_wishlist->removeProductWishlist($id_old_wishlist, $id_wishlist_product);
if ($check) {
$res &= $new_wishlist->updateProductWishlist($id_new_wishlist, $check['id_wishlist_product'], $priority, $quantity + $check['quantity']);
} else {
$res &= $new_wishlist->addProduct($id_new_wishlist, $this->context->customer->id, $id_product, $id_product_attribute, $quantity);
}
if ($res) {
$result[] = true;
} else {
$errors[] = $this->module->l('Error while moving product to another list', 'mywishlist');
}
}
} else {
$errors[] = $this->l('You must be logged in to manage your wishlist.', 'mywishlist');
}
$array_result['result'] = $result;
$array_result['errors'] = $errors;
die(Tools::jsonEncode($array_result));
}
/**
* @see FrontController::initContent()
*/
public function initContent()
{
$this->php_self = 'mywishlist';
if (Tools::getValue('ajax')) {
return;
}
parent::initContent();
if (!Configuration::get('LEOFEATURE_ENABLE_PRODUCTWISHLIST')) {
return Tools::redirect('index.php?controller=404');
}
if ($this->context->customer->isLogged()) {
$wishlists = WishList::getByIdCustomer($this->context->customer->id);
if (count($wishlists)>0) {
foreach ($wishlists as $key => $wishlists_val) {
$wishlist_product = WishList::getInfosByIdCustomer($this->context->customer->id, $wishlists_val['id_wishlist']);
$wishlists[$key]['number_product'] = $wishlist_product['nbProducts'];
}
}
$this->context->smarty->assign(array(
'wishlists' => $wishlists,
'view_wishlist_url' => $this->context->link->getModuleLink('leofeature', 'viewwishlist'),
'leo_is_rewrite_active' => (bool)Configuration::get('PS_REWRITING_SETTINGS'),
));
} else {
Tools::redirect('index.php?controller=authentication&back='.urlencode($this->context->link->getModuleLink('leofeature', 'mywishlist')));
}
$this->setTemplate('module:leofeature/views/templates/front/leo_my_wishlist.tpl');
}
//DONGND:: add meta title, meta description, meta keywords
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['title'] = Configuration::get('PS_SHOP_NAME').' - '.$this->l('My Wishlist', 'mywishlist');
$page['meta']['keywords'] = $this->l('my-wishlist', 'mywishlist');
$page['meta']['description'] = $this->l('My Wishlist', 'mywishlist');
// echo '<pre>';
// print_r($page);die();
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
// $link = LeoBlogHelper::getInstance()->getFontBlogLink();
// $config = LeoBlogConfig::getInstance();
$breadcrumb['links'][] = array(
'title' => $this->l('My Account', 'mywishlist'),
'url' => $this->context->link->getPageLink('my-account', true),
);
$breadcrumb['links'][] = array(
'title' => $this->l('My Wishlist', 'mywishlist'),
'url' => $this->context->link->getModuleLink('leofeature', 'mywishlist'),
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-leofeature-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec(
'overrideLayoutTemplate',
array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
)
)) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,212 @@
<?php
/**
* 2007-2015 Leotheme
*
* NOTICE OF LICENSE
*
* Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list
*
* DISCLAIMER
*
* @author leotheme <leotheme@gmail.com>
* @copyright 2007-2015 Leotheme
* @license http://leotheme.com - prestashop template provider
*/
require_once(_PS_MODULE_DIR_.'leofeature/classes/CompareProduct.php');
require_once(_PS_MODULE_DIR_.'leofeature/classes/LeofeatureProduct.php');
class LeofeatureProductsCompareModuleFrontController extends ModuleFrontController
{
public $php_self;
/**
* Display ajax content (this function is called instead of classic display, in ajax mode)
*/
public function displayAjax()
{
if (!$this->isTokenValid() || !Tools::getValue('action') || !Tools::getValue('ajax') || !Tools::getValue('id_product')) {
// Ooops! Token is not valid!
die('Token is not valid, hack stop');
};
// Add or remove product with Ajax
if (Tools::getValue('ajax') && Tools::getValue('id_product') && Tools::getValue('action')) {
if (Tools::getValue('action') == 'add') {
$id_compare = isset($this->context->cookie->id_compare) ? $this->context->cookie->id_compare: false;
if (CompareProduct::getNumberProducts($id_compare) < Configuration::get('LEOFEATURE_COMPARATOR_MAX_ITEM')) {
CompareProduct::addCompareProduct($id_compare, (int)Tools::getValue('id_product'));
} else {
$this->ajaxDie('0');
}
} elseif (Tools::getValue('action') == 'remove') {
if (isset($this->context->cookie->id_compare)) {
CompareProduct::removeCompareProduct((int)$this->context->cookie->id_compare, (int)Tools::getValue('id_product'));
} else {
$this->ajaxDie('0');
}
} else {
$this->ajaxDie('0');
}
$this->ajaxDie('1');
}
$this->ajaxDie('0');
}
/**
* Assign template vars related to page content
* @see FrontController::initContent()
*/
public function initContent()
{
$this->php_self = 'productscompare';
if (Tools::getValue('ajax')) {
return;
}
parent::initContent();
CompareProduct::cleanCompareProducts('week');
$hasProduct = false;
if (!Configuration::get('LEOFEATURE_COMPARATOR_MAX_ITEM') || !Configuration::get('LEOFEATURE_ENABLE_PRODUCTCOMPARE')) {
return Tools::redirect('index.php?controller=404');
}
$ids = null;
if (isset($this->context->cookie->id_compare)) {
$ids = CompareProduct::getCompareProducts($this->context->cookie->id_compare);
}
if ($ids) {
if (count($ids) > 0) {
if (count($ids) > Configuration::get('LEOFEATURE_COMPARATOR_MAX_ITEM')) {
$ids = array_slice($ids, 0, Configuration::get('LEOFEATURE_COMPARATOR_MAX_ITEM'));
}
$listProducts = array();
$listFeatures = array();
foreach ($ids as $k => &$id) {
$curProduct = new Product((int)$id, true, $this->context->language->id);
if (!Validate::isLoadedObject($curProduct) || !$curProduct->active || !$curProduct->isAssociatedToShop()) {
if (isset($this->context->cookie->id_compare)) {
CompareProduct::removeCompareProduct($this->context->cookie->id_compare, $id);
}
unset($ids[$k]);
continue;
}
foreach ($curProduct->getFrontFeatures($this->context->language->id) as $feature) {
if (isset($listFeatures[$curProduct->id][$feature['id_feature']])) {
$listFeatures[$curProduct->id][$feature['id_feature']] =
$listFeatures[$curProduct->id][$feature['id_feature']] . '<br>' . $feature['value'];
} else {
$listFeatures[$curProduct->id][$feature['id_feature']] = $feature['value'];
}
}
$product_object = new LeofeatureProduct();
$product_object->php_self = 'productscompare';
$curProduct = $product_object->getTemplateVarProduct1($id);
$listProducts[] = $curProduct;
}
if (count($listProducts) > 0) {
$width = 80 / count($listProducts);
$hasProduct = true;
$ordered_features = $this->getFeaturesForComparison($ids, $this->context->language->id);
$this->context->smarty->assign(array(
'ordered_features' => $ordered_features,
'product_features' => $listFeatures,
'products' => $listProducts,
'width' => $width,
// 'HOOK_COMPARE_EXTRA_INFORMATION' => Hook::exec('displayCompareExtraInformation', array('list_ids_product' => $ids)),
// 'HOOK_EXTRA_PRODUCT_COMPARISON' => Hook::exec('displayProductComparison', array('list_ids_product' => $ids)),
'homeSize' => Image::getSize(ImageType::getFormattedName('home')),
'list_product' => $ids,
));
} elseif (isset($this->context->cookie->id_compare)) {
$object = new CompareProduct((int)$this->context->cookie->id_compare);
if (Validate::isLoadedObject($object)) {
$object->delete();
}
}
}
}
$this->context->smarty->assign('hasProduct', $hasProduct);
$this->setTemplate('module:leofeature/views/templates/front/leo_products_compare.tpl');
}
public function getFeaturesForComparison($list_ids_product, $id_lang)
{
if (!Feature::isFeatureActive()) {
return false;
}
$ids = '';
foreach ($list_ids_product as $id) {
$ids .= (int)$id.',';
}
$ids = rtrim($ids, ',');
if (empty($ids)) {
return false;
}
return Db::getInstance()->executeS('SELECT f.*, fl.*
FROM `'._DB_PREFIX_.'feature` f
LEFT JOIN `'._DB_PREFIX_.'feature_product` fp
ON f.`id_feature` = fp.`id_feature`
LEFT JOIN `'._DB_PREFIX_.'feature_lang` fl
ON f.`id_feature` = fl.`id_feature`
WHERE fp.`id_product` IN ('.$ids.')
AND `id_lang` = '.(int)$id_lang.'
GROUP BY f.`id_feature`
ORDER BY f.`position` ASC');
}
//DONGND:: add meta title, meta description, meta keywords
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['title'] = Configuration::get('PS_SHOP_NAME').' - '.$this->l('Products Comparison', 'productscompare');
$page['meta']['keywords'] = $this->l('products-comparison', 'productscompare');
$page['meta']['description'] = $this->l('Products Comparison', 'productscompare');
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array(
'title' => $this->l('Products Comparison', 'productscompare'),
'url' => $this->context->link->getModuleLink('leofeature', 'productscompare'),
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-leofeature-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec('overrideLayoutTemplate', array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
))) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,126 @@
<?php
/**
* 2007-2015 Leotheme
*
* NOTICE OF LICENSE
*
* Leo feature for prestashop 1.7: ajax cart, review, compare, wishlist at product list
*
* DISCLAIMER
*
* @author leotheme <leotheme@gmail.com>
* @copyright 2007-2015 Leotheme
* @license http://leotheme.com - prestashop template provider
*/
require_once(_PS_MODULE_DIR_.'leofeature/classes/WishList.php');
require_once(_PS_MODULE_DIR_.'leofeature/classes/LeofeatureProduct.php');
class LeoFeatureViewWishlistModuleFrontController extends ModuleFrontController
{
public $php_self;
public function __construct()
{
parent::__construct();
$this->context = Context::getContext();
}
public function initContent()
{
$this->php_self = 'viewwishlist';
parent::initContent();
if (!Configuration::get('LEOFEATURE_ENABLE_PRODUCTWISHLIST')) {
return Tools::redirect('index.php?controller=404');
}
$token = Tools::getValue('token');
if ($token) {
$wishlist = WishList::getByToken($token);
$wishlists = WishList::getByIdCustomer((int)$wishlist['id_customer']);
if (count($wishlists) > 1) {
foreach ($wishlists as $key => $wishlists_item) {
if ($wishlists_item['id_wishlist'] == $wishlist['id_wishlist']) {
unset($wishlists[$key]);
}
}
} else {
$wishlists = array();
}
$products = array();
$wishlist_product = WishList::getSimpleProductByIdWishlist((int)$wishlist['id_wishlist']);
$product_object = new LeofeatureProduct();
if (count($wishlist_product) > 0) {
foreach ($wishlist_product as $wishlist_product_item) {
$list_product_tmp = array();
$list_product_tmp['wishlist_info'] = $wishlist_product_item;
$list_product_tmp['product_info'] = $product_object->getTemplateVarProduct2($wishlist_product_item['id_product'], $wishlist_product_item['id_product_attribute']);
$list_product_tmp['product_info']['wishlist_quantity'] = $wishlist_product_item['quantity'];
$products[] = $list_product_tmp;
}
}
WishList::incCounter((int)$wishlist['id_wishlist']);
$this->context->smarty->assign(
array(
'current_wishlist' => $wishlist,
'wishlists' => $wishlists,
'products' => $products,
'view_wishlist_url' => $this->context->link->getModuleLink('leofeature', 'viewwishlist'),
'show_button_cart' => Configuration::get('LEOFEATURE_ENABLE_AJAXCART'),
'leo_is_rewrite_active' => (bool)Configuration::get('PS_REWRITING_SETTINGS'),
)
);
}
$this->setTemplate('module:leofeature/views/templates/front/leo_wishlist_view.tpl');
}
//DONGND:: add meta title, meta description, meta keywords
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['title'] = Configuration::get('PS_SHOP_NAME').' - '.$this->l('View Wishlist', 'viewwishlist');
$page['meta']['keywords'] = $this->l('view-wishlist', 'viewwishlist');
$page['meta']['description'] = $this->l('view Wishlist', 'viewwishlist');
return $page;
}
//DONGND:: add breadcrumb
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array(
'title' => $this->l('My Account', 'viewwishlist'),
'url' => $this->context->link->getPageLink('my-account', true),
);
$breadcrumb['links'][] = array(
'title' => $this->l('My Wishlist', 'viewwishlist'),
'url' => $this->context->link->getModuleLink('leofeature', 'mywishlist'),
);
return $breadcrumb;
}
//DONGND:: get layout
public function getLayout()
{
$entity = 'module-leofeature-'.$this->php_self;
$layout = $this->context->shop->theme->getLayoutRelativePathForPage($entity);
if ($overridden_layout = Hook::exec('overrideLayoutTemplate', array(
'default_layout' => $layout,
'entity' => $entity,
'locale' => $this->context->language->locale,
'controller' => $this,
))) {
return $overridden_layout;
}
if ((int) Tools::getValue('content_only')) {
$layout = 'layouts/layout-content-only.tpl';
}
return $layout;
}
}

View File

@@ -0,0 +1,36 @@
<?php
/*
* 2007-2012 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2012 PrestaShop SA
* @version Release: $Revision: 13573 $
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;