// FavoriteProducts module now use ModuleController
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11894 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
@@ -27,45 +27,31 @@
|
||||
|
||||
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',
|
||||
'id_customer',
|
||||
'id_shop'
|
||||
/**
|
||||
* @see ObjectModel::$definition
|
||||
*/
|
||||
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)
|
||||
{
|
||||
if (!$shop)
|
||||
|
||||
@@ -25,26 +25,18 @@
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*/
|
||||
|
||||
/**
|
||||
* @deprecated 1.5.0 This file is deprecated, use moduleController instead
|
||||
*/
|
||||
|
||||
/* SSL Management */
|
||||
$useSSL = true;
|
||||
|
||||
require_once(dirname(__FILE__).'/../../config/config.inc.php');
|
||||
require_once(dirname(__FILE__).'/../../init.php');
|
||||
require('../../config/config.inc.php');
|
||||
Tools::displayFileAsDeprecated();
|
||||
|
||||
require_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||
require_once(dirname(__FILE__).'/favoriteproducts.php');
|
||||
// init front controller in order to use Tools::redirect
|
||||
$controller = new FrontController();
|
||||
$controller->init();
|
||||
|
||||
if (!Context::getContext()->customer->isLogged())
|
||||
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');
|
||||
Tools::redirect('index.php?controller=module&module=favoriteproducts&process=account');
|
||||
@@ -25,21 +25,25 @@
|
||||
*}
|
||||
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
$('documnet').ready(function(){
|
||||
$('img[rel^=ajax_id_favoriteproduct_]').click(function(){
|
||||
|
||||
$('document').ready(function()
|
||||
{
|
||||
$('img[rel^=ajax_id_favoriteproduct_]').click(function()
|
||||
{
|
||||
var idFavoriteProduct = $(this).attr('rel').replace('ajax_id_favoriteproduct_', '');
|
||||
var parent = $(this).parent().parent();
|
||||
|
||||
$.ajax({
|
||||
url: "favoriteproducts-ajax.php",
|
||||
post: "POST",
|
||||
data: "id_product=" + idFavoriteProduct + "&action=remove",
|
||||
success: function(result){
|
||||
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||
type: "POST",
|
||||
data: {
|
||||
'id_product': idFavoriteProduct
|
||||
},
|
||||
success: function(result)
|
||||
{
|
||||
if (result == '0')
|
||||
{
|
||||
parent.fadeOut("normal", function() {
|
||||
parent.fadeOut("normal", function()
|
||||
{
|
||||
parent.remove();
|
||||
});
|
||||
}
|
||||
@@ -47,7 +51,6 @@ $('documnet').ready(function(){
|
||||
});
|
||||
});
|
||||
});
|
||||
{/literal}
|
||||
</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}
|
||||
|
||||
@@ -25,6 +25,10 @@
|
||||
* 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__).'/../../init.php');
|
||||
include(dirname(__FILE__).'/FavoriteProduct.php');
|
||||
|
||||
@@ -25,13 +25,14 @@
|
||||
*}
|
||||
|
||||
<script type="text/javascript">
|
||||
{literal}
|
||||
$('document').ready(function(){
|
||||
$('#favoriteproducts_block_extra_add').click(function(){
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
||||
post: "POST",
|
||||
{/literal}data: "id_product={$smarty.get.id_product}&action=add",{literal}
|
||||
url: "{$link->getModuleLink('favoriteproducts', 'add')}",
|
||||
type: "POST",
|
||||
data: {
|
||||
"id_product": {$smarty.get.id_product}
|
||||
},
|
||||
success: function(result){
|
||||
if (result == '0')
|
||||
{
|
||||
@@ -45,54 +46,59 @@ $('document').ready(function(){
|
||||
});
|
||||
$('#favoriteproducts_block_extra_remove').click(function(){
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
||||
post: "POST",
|
||||
{/literal}data: "id_product={$smarty.get.id_product}&action=remove",{literal}
|
||||
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||
type: "POST",
|
||||
data: {
|
||||
"id_product": {$smarty.get.id_product}
|
||||
},
|
||||
success: function(result){
|
||||
if (result == '0')
|
||||
{
|
||||
$('#favoriteproducts_block_extra_remove').slideUp(function() {
|
||||
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#favoriteproducts_block_extra_added').click(function(){
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
||||
post: "POST",
|
||||
{/literal}data: "id_product={$smarty.get.id_product}&action=remove",{literal}
|
||||
url: "{$link->getModuleLink('favoriteproducts', 'remove')}",
|
||||
type: "POST",
|
||||
data: {
|
||||
"id_product": {$smarty.get.id_product}
|
||||
},
|
||||
success: function(result){
|
||||
if (result == '0')
|
||||
{
|
||||
$('#favoriteproducts_block_extra_added').slideUp(function() {
|
||||
$('#favoriteproducts_block_extra_removed').slideDown("slow");
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
$('#favoriteproducts_block_extra_removed').click(function(){
|
||||
$.ajax({
|
||||
{/literal}url: "{$module_dir}favoriteproducts-ajax.php",{literal}
|
||||
post: "POST",
|
||||
{/literal}data: "id_product={$smarty.get.id_product}&action=add",{literal}
|
||||
url: "{$link->getModuleLink('favoriteproducts', 'add')}",
|
||||
type: "POST",
|
||||
data: {
|
||||
"id_product": {$smarty.get.id_product}
|
||||
},
|
||||
success: function(result){
|
||||
if (result == '0')
|
||||
{
|
||||
$('#favoriteproducts_block_extra_removed').slideUp(function() {
|
||||
$('#favoriteproducts_block_extra_added').slideDown("slow");
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
})
|
||||
{/literal}
|
||||
</script>
|
||||
|
||||
{if !$isCustomerFavoriteProduct AND $isLogged}
|
||||
|
||||
@@ -90,7 +90,7 @@ class FavoriteProducts extends Module
|
||||
return $this->hookDisplayCustomerAccount($params);
|
||||
}
|
||||
|
||||
public function hookDisplayaLeftColumnProduct($params)
|
||||
public function hookDisplayLeftColumnProduct($params)
|
||||
{
|
||||
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
|
||||
*}
|
||||
|
||||
<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