// FavoriteProducts module now use ModuleController
This commit is contained in:
@@ -27,45 +27,31 @@
|
|||||||
|
|
||||||
class FavoriteProduct extends ObjectModel
|
class FavoriteProduct extends ObjectModel
|
||||||
{
|
{
|
||||||
public $id;
|
public $id;
|
||||||
|
|
||||||
public $id_product;
|
public $id_product;
|
||||||
|
|
||||||
public $id_customer;
|
public $id_customer;
|
||||||
|
|
||||||
public $id_shop;
|
public $id_shop;
|
||||||
|
|
||||||
public $date_add;
|
public $date_add;
|
||||||
|
|
||||||
public $date_upd;
|
public $date_upd;
|
||||||
|
|
||||||
protected $fieldRequired = array(
|
/**
|
||||||
'id_product',
|
* @see ObjectModel::$definition
|
||||||
'id_customer',
|
*/
|
||||||
'id_shop'
|
public static $definition = array(
|
||||||
|
'table' => 'favorite_product',
|
||||||
|
'primary' => 'id_favorite_product',
|
||||||
|
'fields' => array(
|
||||||
|
'id_product' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||||
|
'id_customer' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||||
|
'id_shop' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt', 'required' => true),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
protected $fieldsValidate = array(
|
|
||||||
'id_product' => 'isUnsignedInt',
|
|
||||||
'id_customer' => 'isUnsignedInt',
|
|
||||||
'id_shop' => 'isUnsignedInt'
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $table = 'favorite_product';
|
|
||||||
|
|
||||||
protected $identifier = 'id_favorite_product';
|
|
||||||
|
|
||||||
public function getFields()
|
|
||||||
{
|
|
||||||
$this->validateFields();
|
|
||||||
|
|
||||||
$fields['id_product'] = (int)$this->id_product;
|
|
||||||
$fields['id_customer'] = (int)$this->id_customer;
|
|
||||||
$fields['id_shop'] = (int)$this->id_shop;
|
|
||||||
|
|
||||||
return $fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getFavoriteProducts($id_customer, $id_lang, Shop $shop = null)
|
public static function getFavoriteProducts($id_customer, $id_lang, Shop $shop = null)
|
||||||
{
|
{
|
||||||
if (!$shop)
|
if (!$shop)
|
||||||
|
|||||||
@@ -25,26 +25,18 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 1.5.0 This file is deprecated, use moduleController instead
|
||||||
|
*/
|
||||||
|
|
||||||
/* SSL Management */
|
/* SSL Management */
|
||||||
$useSSL = true;
|
$useSSL = true;
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
require('../../config/config.inc.php');
|
||||||
require_once(dirname(__FILE__).'/../../init.php');
|
Tools::displayFileAsDeprecated();
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/FavoriteProduct.php');
|
// init front controller in order to use Tools::redirect
|
||||||
require_once(dirname(__FILE__).'/favoriteproducts.php');
|
$controller = new FrontController();
|
||||||
|
$controller->init();
|
||||||
|
|
||||||
if (!Context::getContext()->customer->isLogged())
|
Tools::redirect('index.php?controller=module&module=favoriteproducts&process=account');
|
||||||
Tools::redirect('authentication.php?back=modules/favoriteproducts/favoriteproducts.php');
|
|
||||||
|
|
||||||
include(dirname(__FILE__).'/../../header.php');
|
|
||||||
|
|
||||||
if ((int)Context::getContext()->customer->id)
|
|
||||||
{
|
|
||||||
$smarty->assign('favoriteProducts', FavoriteProduct::getFavoriteProducts((int)Context::getContext()->customer->id, (int)Context::getContext()->language->id));
|
|
||||||
|
|
||||||
$favoriteproducts = new FavoriteProducts();
|
|
||||||
echo $favoriteproducts->display(dirname(__FILE__).'/favoriteproducts.php', 'favoriteproducts-account.tpl');
|
|
||||||
}
|
|
||||||
|
|
||||||
include(dirname(__FILE__).'/../../footer.php');
|
|
||||||
@@ -25,21 +25,25 @@
|
|||||||
*}
|
*}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{literal}
|
$('document').ready(function()
|
||||||
$('documnet').ready(function(){
|
{
|
||||||
$('img[rel^=ajax_id_favoriteproduct_]').click(function(){
|
$('img[rel^=ajax_id_favoriteproduct_]').click(function()
|
||||||
|
{
|
||||||
var idFavoriteProduct = $(this).attr('rel').replace('ajax_id_favoriteproduct_', '');
|
var idFavoriteProduct = $(this).attr('rel').replace('ajax_id_favoriteproduct_', '');
|
||||||
var parent = $(this).parent().parent();
|
var parent = $(this).parent().parent();
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: "favoriteproducts-ajax.php",
|
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||||
post: "POST",
|
type: "POST",
|
||||||
data: "id_product=" + idFavoriteProduct + "&action=remove",
|
data: {
|
||||||
success: function(result){
|
'id_product': idFavoriteProduct
|
||||||
|
},
|
||||||
|
success: function(result)
|
||||||
|
{
|
||||||
if (result == '0')
|
if (result == '0')
|
||||||
{
|
{
|
||||||
parent.fadeOut("normal", function() {
|
parent.fadeOut("normal", function()
|
||||||
|
{
|
||||||
parent.remove();
|
parent.remove();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -47,7 +51,6 @@ $('documnet').ready(function(){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
{/literal}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{capture name=path}<a href="{$link->getPageLink('my-account.php', true)}">{l s='My account' mod='favoriteproducts'}</a><span class="navigation-pipe">{$navigationPipe}</span>{l s='My favorite products' mod='favoriteproducts'}{/capture}
|
{capture name=path}<a href="{$link->getPageLink('my-account.php', true)}">{l s='My account' mod='favoriteproducts'}</a><span class="navigation-pipe">{$navigationPipe}</span>{l s='My favorite products' mod='favoriteproducts'}{/capture}
|
||||||
|
|||||||
@@ -25,6 +25,10 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 1.5.0 This file is deprecated, use moduleController instead
|
||||||
|
*/
|
||||||
|
|
||||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||||
require_once(dirname(__FILE__).'/../../init.php');
|
require_once(dirname(__FILE__).'/../../init.php');
|
||||||
include(dirname(__FILE__).'/FavoriteProduct.php');
|
include(dirname(__FILE__).'/FavoriteProduct.php');
|
||||||
|
|||||||
@@ -25,13 +25,14 @@
|
|||||||
*}
|
*}
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
{literal}
|
|
||||||
$('document').ready(function(){
|
$('document').ready(function(){
|
||||||
$('#favoriteproducts_block_extra_add').click(function(){
|
$('#favoriteproducts_block_extra_add').click(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
url: "{$link->getModuleLink('favoriteproducts', 'add')}",
|
||||||
post: "POST",
|
type: "POST",
|
||||||
{/literal}data: "id_product={$smarty.get.id_product}&action=add",{literal}
|
data: {
|
||||||
|
"id_product": {$smarty.get.id_product}
|
||||||
|
},
|
||||||
success: function(result){
|
success: function(result){
|
||||||
if (result == '0')
|
if (result == '0')
|
||||||
{
|
{
|
||||||
@@ -45,54 +46,59 @@ $('document').ready(function(){
|
|||||||
});
|
});
|
||||||
$('#favoriteproducts_block_extra_remove').click(function(){
|
$('#favoriteproducts_block_extra_remove').click(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||||
post: "POST",
|
type: "POST",
|
||||||
{/literal}data: "id_product={$smarty.get.id_product}&action=remove",{literal}
|
data: {
|
||||||
|
"id_product": {$smarty.get.id_product}
|
||||||
|
},
|
||||||
success: function(result){
|
success: function(result){
|
||||||
if (result == '0')
|
if (result == '0')
|
||||||
{
|
{
|
||||||
$('#favoriteproducts_block_extra_remove').slideUp(function() {
|
$('#favoriteproducts_block_extra_remove').slideUp(function() {
|
||||||
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$('#favoriteproducts_block_extra_added').click(function(){
|
$('#favoriteproducts_block_extra_added').click(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||||
post: "POST",
|
type: "POST",
|
||||||
{/literal}data: "id_product={$smarty.get.id_product}&action=remove",{literal}
|
data: {
|
||||||
|
"id_product": {$smarty.get.id_product}
|
||||||
|
},
|
||||||
success: function(result){
|
success: function(result){
|
||||||
if (result == '0')
|
if (result == '0')
|
||||||
{
|
{
|
||||||
$('#favoriteproducts_block_extra_added').slideUp(function() {
|
$('#favoriteproducts_block_extra_added').slideUp(function() {
|
||||||
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
$('#favoriteproducts_block_extra_removed').click(function(){
|
$('#favoriteproducts_block_extra_removed').click(function(){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
url: "{$link->getModuleLink('favoriteproducts', 'add')}",
|
||||||
post: "POST",
|
type: "POST",
|
||||||
{/literal}data: "id_product={$smarty.get.id_product}&action=add",{literal}
|
data: {
|
||||||
|
"id_product": {$smarty.get.id_product}
|
||||||
|
},
|
||||||
success: function(result){
|
success: function(result){
|
||||||
if (result == '0')
|
if (result == '0')
|
||||||
{
|
{
|
||||||
$('#favoriteproducts_block_extra_removed').slideUp(function() {
|
$('#favoriteproducts_block_extra_removed').slideUp(function() {
|
||||||
$('#favoriteproducts_block_extra_added').slideDown("slow");
|
$('#favoriteproducts_block_extra_added').slideDown("slow");
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
{/literal}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{if !$isCustomerFavoriteProduct AND $isLogged}
|
{if !$isCustomerFavoriteProduct AND $isLogged}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ class FavoriteProducts extends Module
|
|||||||
return $this->hookDisplayCustomerAccount($params);
|
return $this->hookDisplayCustomerAccount($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hookDisplayaLeftColumnProduct($params)
|
public function hookDisplayLeftColumnProduct($params)
|
||||||
{
|
{
|
||||||
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* 2007-2011 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-2011 PrestaShop SA
|
||||||
|
* @version Release: $Revision$
|
||||||
|
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||||
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 1.5.0
|
||||||
|
*/
|
||||||
|
class ModuleFavoriteproductsController extends ModuleController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
public $id_product;
|
||||||
|
|
||||||
|
public function init()
|
||||||
|
{
|
||||||
|
parent::init();
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||||
|
$this->id_product = (int)Tools::getValue('id_product');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function postProcess()
|
||||||
|
{
|
||||||
|
if ($this->process == 'remove')
|
||||||
|
$this->processRemove();
|
||||||
|
else if ($this->process == 'add')
|
||||||
|
$this->processAdd();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a favorite product
|
||||||
|
*/
|
||||||
|
public function processRemove()
|
||||||
|
{
|
||||||
|
// check if product exists
|
||||||
|
$product = new Product($this->id_product);
|
||||||
|
if (!Validate::isLoadedObject($product))
|
||||||
|
die('0');
|
||||||
|
|
||||||
|
$favoriteProduct = FavoriteProduct::getFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id);
|
||||||
|
if ($favoriteProduct && $favoriteProduct->delete())
|
||||||
|
die('0');
|
||||||
|
die(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a favorite product
|
||||||
|
*/
|
||||||
|
public function processAdd()
|
||||||
|
{
|
||||||
|
$product = new Product($this->id_product);
|
||||||
|
// check if product exists
|
||||||
|
if (!Validate::isLoadedObject($product) || FavoriteProduct::isCustomerFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id))
|
||||||
|
die('1');
|
||||||
|
$favoriteProduct = new FavoriteProduct();
|
||||||
|
$favoriteProduct->id_product = $product->id;
|
||||||
|
$favoriteProduct->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||||
|
$favoriteProduct->id_shop = (int)Context::getContext()->shop->getID(true);
|
||||||
|
if ($favoriteProduct->add())
|
||||||
|
die('0');
|
||||||
|
die(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function initContent()
|
||||||
|
{
|
||||||
|
parent::initContent();
|
||||||
|
if ($this->process == 'account')
|
||||||
|
$this->assignAccount();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare account page
|
||||||
|
*/
|
||||||
|
public function assignAccount()
|
||||||
|
{
|
||||||
|
if (!Context::getContext()->customer->isLogged())
|
||||||
|
Tools::redirect('index.php?controller=auth&redirect=module&module=favoriteproducts&action=account');
|
||||||
|
|
||||||
|
if (Context::getContext()->customer->id)
|
||||||
|
{
|
||||||
|
$this->context->smarty->assign('favoriteProducts', FavoriteProduct::getFavoriteProducts((int)Context::getContext()->customer->id, (int)Context::getContext()->language->id));
|
||||||
|
$this->setTemplate('favoriteproducts-account.tpl');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,4 +24,9 @@
|
|||||||
* International Registered Trademark & Property of PrestaShop SA
|
* International Registered Trademark & Property of PrestaShop SA
|
||||||
*}
|
*}
|
||||||
|
|
||||||
<li class="favoriteproducts"><a href="{$base_dir_ssl}modules/favoriteproducts/favoriteproducts-account.php" title="{l s='My favorite products' mod='favoriteproducts'}"><img src="{$module_template_dir}img/favorites.png" class="icon" /> {l s='My favorite products' mod='favoriteproducts'}</a></li>
|
<li class="favoriteproducts">
|
||||||
|
<a href="{$link->getModuleLink('favoriteproducts', 'account')}" title="{l s='My favorite products' mod='favoriteproducts'}">
|
||||||
|
<img src="{$module_template_dir}img/favorites.png" class="icon" />
|
||||||
|
{l s='My favorite products' mod='favoriteproducts'}
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user