// Normalize FavoriteProducts
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@13217 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
9d7a798a4c
commit
92987a0ce3
5 files changed
+41
-42
No files matched your search
@@ -60,14 +60,19 @@ class FavoriteProduct extends ObjectModel
|
|||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
|
|
||||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT fp.`id_shop`, p.`id_product`, pl.`description_short`, pl.`link_rewrite`, pl.`name`, i.`id_image`, CONCAT(p.`id_product`, \'-\', i.`id_image`) as image
|
SELECT fp.`id_shop`, p.`id_product`, pl.`description_short`, pl.`link_rewrite`,
|
||||||
|
pl.`name`, i.`id_image`, CONCAT(p.`id_product`, \'-\', i.`id_image`) as image
|
||||||
FROM `'._DB_PREFIX_.'favorite_product` fp
|
FROM `'._DB_PREFIX_.'favorite_product` fp
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = fp.`id_product`)
|
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = fp.`id_product`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.$shop->addSqlRestrictionOnLang('pl').')
|
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||||
|
ON p.`id_product` = pl.`id_product`
|
||||||
|
AND pl.`id_lang` = '.(int)$id_lang
|
||||||
|
.$shop->addSqlRestrictionOnLang('pl').'
|
||||||
LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1)
|
LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.`id_product` = pa.`id_product` AND `default_on` = 1)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)($id_lang).')
|
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
|
||||||
WHERE p.`active` = 1
|
WHERE p.`active` = 1
|
||||||
|
'.($id_customer ? ' AND fp.id_customer = '.(int)$id_customer : '').'
|
||||||
'.$shop->addSqlRestriction(false, 'fp')
|
'.$shop->addSqlRestriction(false, 'fp')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -77,12 +82,13 @@ class FavoriteProduct extends ObjectModel
|
|||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
|
|
||||||
$id_favorite_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
$id_favorite_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
SELECT `id_favorite_product`
|
SELECT `id_favorite_product`
|
||||||
FROM `'._DB_PREFIX_.'favorite_product`
|
FROM `'._DB_PREFIX_.'favorite_product`
|
||||||
WHERE `id_customer` = '.(int)($id_customer).'
|
WHERE `id_customer` = '.(int)$id_customer.'
|
||||||
AND `id_product` = '.(int)($id_product).'
|
AND `id_product` = '.(int)$id_product.'
|
||||||
AND `id_shop` = '.(int)($shop->getID()));
|
AND `id_shop` = '.(int)$shop->getID(true)
|
||||||
|
);
|
||||||
|
|
||||||
if ($id_favorite_product)
|
if ($id_favorite_product)
|
||||||
return new FavoriteProduct($id_favorite_product);
|
return new FavoriteProduct($id_favorite_product);
|
||||||
@@ -97,8 +103,8 @@ class FavoriteProduct extends ObjectModel
|
|||||||
return (bool)Db::getInstance()->getValue('
|
return (bool)Db::getInstance()->getValue('
|
||||||
SELECT COUNT(*)
|
SELECT COUNT(*)
|
||||||
FROM `'._DB_PREFIX_.'favorite_product`
|
FROM `'._DB_PREFIX_.'favorite_product`
|
||||||
WHERE `id_customer` = '.(int)($id_customer).'
|
WHERE `id_customer` = '.(int)$id_customer.'
|
||||||
AND `id_product` = '.(int)($id_product).'
|
AND `id_product` = '.(int)$id_product.'
|
||||||
AND `id_shop` = '.(int)($shop->getID()));
|
AND `id_shop` = '.(int)$shop->getID(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +62,8 @@ class FavoriteproductsActionsModuleFrontController extends ModuleFrontController
|
|||||||
if (!Validate::isLoadedObject($product))
|
if (!Validate::isLoadedObject($product))
|
||||||
die('0');
|
die('0');
|
||||||
|
|
||||||
$favoriteProduct = FavoriteProduct::getFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id);
|
$favorite_product = FavoriteProduct::getFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id);
|
||||||
if ($favoriteProduct && $favoriteProduct->delete())
|
if ($favorite_product && $favorite_product->delete())
|
||||||
die('0');
|
die('0');
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
@@ -77,11 +77,11 @@ class FavoriteproductsActionsModuleFrontController extends ModuleFrontController
|
|||||||
// check if product exists
|
// check if product exists
|
||||||
if (!Validate::isLoadedObject($product) || FavoriteProduct::isCustomerFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id))
|
if (!Validate::isLoadedObject($product) || FavoriteProduct::isCustomerFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id))
|
||||||
die('1');
|
die('1');
|
||||||
$favoriteProduct = new FavoriteProduct();
|
$favorite_product = new FavoriteProduct();
|
||||||
$favoriteProduct->id_product = $product->id;
|
$favorite_product->id_product = $product->id;
|
||||||
$favoriteProduct->id_customer = (int)Context::getContext()->cookie->id_customer;
|
$favorite_product->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||||
$favoriteProduct->id_shop = (int)Context::getContext()->shop->getID(true);
|
$favorite_product->id_shop = (int)Context::getContext()->shop->getID(true);
|
||||||
if ($favoriteProduct->add())
|
if ($favorite_product->add())
|
||||||
die('0');
|
die('0');
|
||||||
die(1);
|
die(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
require_once dirname(__FILE__).'/../../config/config.inc.php';
|
|
||||||
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
|
||||||
|
|
||||||
if(FavoriteProduct::isCustomerFavoriteProduct(2,2))
|
|
||||||
echo 'yes';
|
|
||||||
else
|
|
||||||
echo 'non';
|
|
||||||
?>
|
|
||||||
@@ -33,7 +33,7 @@ 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');
|
||||||
|
|
||||||
if (Tools::getValue('action') AND Tools::getValue('id_product') AND Context::getContext()->cookie->id_customer)
|
if (Tools::getValue('action') && Tools::getValue('id_product') && Context::getContext()->cookie->id_customer)
|
||||||
{
|
{
|
||||||
if (Tools::getValue('action') == 'remove')
|
if (Tools::getValue('action') == 'remove')
|
||||||
{
|
{
|
||||||
@@ -41,22 +41,23 @@ if (Tools::getValue('action') AND Tools::getValue('id_product') AND Context::get
|
|||||||
$product = new Product((int)Tools::getValue('id_product'));
|
$product = new Product((int)Tools::getValue('id_product'));
|
||||||
if (!Validate::isLoadedObject($product))
|
if (!Validate::isLoadedObject($product))
|
||||||
die('0');
|
die('0');
|
||||||
$favoriteProduct = FavoriteProduct::getFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id);
|
$favorite_product = FavoriteProduct::getFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id);
|
||||||
if ($favoriteProduct)
|
if ($favorite_product)
|
||||||
if ($favoriteProduct->delete())
|
if ($favorite_product->delete())
|
||||||
die('0');
|
die('0');
|
||||||
}
|
}
|
||||||
elseif (Tools::getValue('action') == 'add')
|
elseif (Tools::getValue('action') == 'add')
|
||||||
{
|
{
|
||||||
$product = new Product((int)Tools::getValue('id_product'));
|
$product = new Product((int)Tools::getValue('id_product'));
|
||||||
// check if product exists
|
// check if product exists
|
||||||
if (!Validate::isLoadedObject($product) || FavoriteProduct::isCustomerFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id))
|
if (!Validate::isLoadedObject($product)
|
||||||
|
|| FavoriteProduct::isCustomerFavoriteProduct((int)Context::getContext()->cookie->id_customer, (int)$product->id))
|
||||||
die('1');
|
die('1');
|
||||||
$favoriteProduct = new FavoriteProduct();
|
$favorite_product = new FavoriteProduct();
|
||||||
$favoriteProduct->id_product = $product->id;
|
$favorite_product->id_product = $product->id;
|
||||||
$favoriteProduct->id_customer = (int)Context::getContext()->cookie->id_customer;
|
$favorite_product->id_customer = (int)Context::getContext()->cookie->id_customer;
|
||||||
$favoriteProduct->id_shop = (int)Context::getContext()->shop->getID();
|
$favorite_product->id_shop = (int)Context::getContext()->shop->getID();
|
||||||
if ($favoriteProduct->add())
|
if ($favorite_product->add())
|
||||||
die('0');
|
die('0');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class FavoriteProducts extends Module
|
|||||||
|
|
||||||
public function uninstall()
|
public function uninstall()
|
||||||
{
|
{
|
||||||
if (!parent::uninstall() OR !Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'favorite_product`'))
|
if (!parent::uninstall() || !Db::getInstance()->execute('DROP TABLE `'._DB_PREFIX_.'favorite_product`'))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -79,9 +79,10 @@ class FavoriteProducts extends Module
|
|||||||
{
|
{
|
||||||
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
include_once(dirname(__FILE__).'/FavoriteProduct.php');
|
||||||
|
|
||||||
$favoriteProducts = FavoriteProduct::getFavoriteProducts($this->context->customer->id, $this->context->language->id);
|
$products = FavoriteProduct::getFavoriteProducts($this->context->customer->id, $this->context->language->id);
|
||||||
|
$this->smarty->assign(array(
|
||||||
$this->smarty->assign(array('favorite_products' => $favoriteProducts));
|
'favorite_products' => $products,
|
||||||
|
));
|
||||||
|
|
||||||
return $this->display(__FILE__, 'my-account.tpl');
|
return $this->display(__FILE__, 'my-account.tpl');
|
||||||
}
|
}
|
||||||
@@ -97,7 +98,8 @@ class FavoriteProducts extends Module
|
|||||||
|
|
||||||
$this->smarty->assign(array(
|
$this->smarty->assign(array(
|
||||||
'isCustomerFavoriteProduct' => (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0),
|
'isCustomerFavoriteProduct' => (FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0),
|
||||||
'isLogged' => (int)$this->context->customer->logged));
|
'isLogged' => (int)$this->context->customer->logged,
|
||||||
|
));
|
||||||
return $this->display(__FILE__, 'favoriteproducts-extra.tpl');
|
return $this->display(__FILE__, 'favoriteproducts-extra.tpl');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user