Esempio n. 1
0
 /**
  * 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');
     }
     $favorite_product = new FavoriteProduct();
     $favorite_product->id_product = $product->id;
     $favorite_product->id_customer = (int) Context::getContext()->cookie->id_customer;
     $favorite_product->id_shop = (int) Context::getContext()->shop->id;
     if ($favorite_product->add()) {
         die('0');
     }
     die(1);
 }
Esempio n. 2
0
 public function initContent()
 {
     parent::initContent();
     if (!Context::getContext()->customer->isLogged()) {
         Tools::redirect('index.php?controller=authentication&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');
     }
 }
Esempio n. 3
0
 public function hookDisplayLeftColumnProduct($params)
 {
     include_once dirname(__FILE__) . '/FavoriteProduct.php';
     $this->smarty->assign(array('isCustomerFavoriteProduct' => FavoriteProduct::isCustomerFavoriteProduct($this->context->customer->id, Tools::getValue('id_product')) ? 1 : 0, 'isLogged' => (int) $this->context->customer->logged));
     return $this->display(__FILE__, 'favoriteproducts-extra.tpl');
 }
require_once dirname(__FILE__) . '/../../init.php';
include dirname(__FILE__) . '/FavoriteProduct.php';
if (Tools::getValue('action') && Tools::getValue('id_product') && Context::getContext()->cookie->id_customer) {
    if (Tools::getValue('action') == 'remove') {
        // check if product exists
        $product = new Product((int) Tools::getValue('id_product'));
        if (!Validate::isLoadedObject($product)) {
            die('0');
        }
        $favorite_product = FavoriteProduct::getFavoriteProduct((int) Context::getContext()->cookie->id_customer, (int) $product->id);
        if ($favorite_product) {
            if ($favorite_product->delete()) {
                die('0');
            }
        }
    } elseif (Tools::getValue('action') == 'add') {
        $product = new Product((int) Tools::getValue('id_product'));
        // check if product exists
        if (!Validate::isLoadedObject($product) || FavoriteProduct::isCustomerFavoriteProduct((int) Context::getContext()->cookie->id_customer, (int) $product->id)) {
            die('1');
        }
        $favorite_product = new FavoriteProduct();
        $favorite_product->id_product = $product->id;
        $favorite_product->id_customer = (int) Context::getContext()->cookie->id_customer;
        $favorite_product->id_shop = (int) Context::getContext()->shop->id;
        if ($favorite_product->add()) {
            die('0');
        }
    }
}
die('1');