first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
<?php
|
||||
36
modules/leofeature/controllers/front/index.php
Normal file
36
modules/leofeature/controllers/front/index.php
Normal 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;
|
||||
384
modules/leofeature/controllers/front/mywishlist.php
Normal file
384
modules/leofeature/controllers/front/mywishlist.php
Normal 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;
|
||||
}
|
||||
}
|
||||
212
modules/leofeature/controllers/front/productscompare.php
Normal file
212
modules/leofeature/controllers/front/productscompare.php
Normal 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;
|
||||
}
|
||||
}
|
||||
126
modules/leofeature/controllers/front/viewwishlist.php
Normal file
126
modules/leofeature/controllers/front/viewwishlist.php
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user