/**
  * @return DataList
  */
 public function AllLists()
 {
     return WishList::get_for_user();
 }
Example #2
0
 public function executeTomy(sfWebRequest $request)
 {
     $request->checkCSRFProtection();
     $this->forward404Unless($location = Doctrine::getTable('Location')->find(array($request->getParameter('id'))), sprintf('Location does not exist (%s).', $request->getParameter('id')));
     if (!$location->isOwner()) {
         $whish = new WishList();
         $whish->profile_id = $this->getUser()->getProfile()->getId();
         $whish->location_id = $location->getId();
         $whish->save();
     }
 }
Example #3
0
*/
require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';
require_once dirname(__FILE__) . '/WishList.php';
$context = Context::getContext();
// Instance of module class for translations
$module = new BlockWishList();
if (Configuration::get('PS_TOKEN_ENABLE') == 1 and strcmp(Tools::getToken(false), Tools::getValue('token')) and $context->customer->isLogged() === true) {
    exit($module->l('invalid token', 'sendwishlist'));
}
if ($context->customer->isLogged()) {
    $id_wishlist = (int) Tools::getValue('id_wishlist');
    if (empty($id_wishlist) === true) {
        exit($module->l('Invalid wishlist', 'sendwishlist'));
    }
    for ($i = 1; empty($_POST['email' . strval($i)]) === false; ++$i) {
        $to = Tools::getValue('email' . $i);
        $wishlist = WishList::exists($id_wishlist, $context->customer->id, true);
        if ($wishlist === false) {
            exit($module->l('Invalid wishlist', 'sendwishlist'));
        }
        if (WishList::addEmail($id_wishlist, $to) === false) {
            exit($module->l('Wishlist send error', 'sendwishlist'));
        }
        $toName = strval(Configuration::get('PS_SHOP_NAME'));
        $customer = $context->customer;
        if (Validate::isLoadedObject($customer)) {
            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}' => Tools::getProtocol() . htmlentities($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/blockwishlist/view.php?token=' . $wishlist['token']), $to, $toName, $customer->email, $customer->firstname . ' ' . $customer->lastname, NULL, NULL, dirname(__FILE__) . '/mails/');
        }
    }
}
 function uninstall()
 {
     global $application;
     $query = new DB_Table_Delete(WishList::getTables());
     $application->db->getDB_Result($query);
 }
Example #5
0
 public function initContent()
 {
     parent::initContent();
     $token = Tools::getValue('token');
     $module = new BlockWishList();
     if ($token) {
         $wishlist = WishList::getByToken($token);
         WishList::refreshWishList($wishlist['id_wishlist']);
         $products = WishList::getProductByIdCustomer((int) $wishlist['id_wishlist'], (int) $wishlist['id_customer'], $this->context->language->id, null, true);
         $nb_products = count($products);
         $priority_names = array(0 => $module->l('High'), 1 => $module->l('Medium'), 2 => $module->l('Low'));
         for ($i = 0; $i < $nb_products; ++$i) {
             $obj = new Product((int) $products[$i]['id_product'], true, $this->context->language->id);
             if (!Validate::isLoadedObject($obj)) {
                 continue;
             } else {
                 $products[$i]['priority_name'] = $priority_names[$products[$i]['priority']];
                 $quantity = Product::getQuantity((int) $products[$i]['id_product'], $products[$i]['id_product_attribute']);
                 $products[$i]['attribute_quantity'] = $quantity;
                 $products[$i]['product_quantity'] = $quantity;
                 $products[$i]['allow_oosp'] = $obj->isAvailableWhenOutOfStock((int) $obj->out_of_stock);
                 if ($products[$i]['id_product_attribute'] != 0) {
                     $combination_imgs = $obj->getCombinationImages($this->context->language->id);
                     if (isset($combination_imgs[$products[$i]['id_product_attribute']][0])) {
                         $products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image'];
                     } else {
                         $cover = Product::getCover($obj->id);
                         $products[$i]['cover'] = $obj->id . '-' . $cover['id_image'];
                     }
                 } else {
                     $images = $obj->getImages($this->context->language->id);
                     foreach ($images as $image) {
                         if ($image['cover']) {
                             $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
                             break;
                         }
                     }
                 }
                 if (!isset($products[$i]['cover'])) {
                     $products[$i]['cover'] = $this->context->language->iso_code . '-default';
                 }
             }
             $products[$i]['bought'] = false;
             /*
             				for ($j = 0, $k = 0; $j < sizeof($bought); ++$j)
             				{
             					if ($bought[$j]['id_product'] == $products[$i]['id_product'] AND
             						$bought[$j]['id_product_attribute'] == $products[$i]['id_product_attribute']
             					)
             						$products[$i]['bought'][$k++] = $bought[$j];
             				}*/
         }
         WishList::incCounter((int) $wishlist['id_wishlist']);
         $ajax = Configuration::get('PS_BLOCK_CART_AJAX');
         $wishlists = WishList::getByIdCustomer((int) $wishlist['id_customer']);
         foreach ($wishlists as $key => $item) {
             if ($item['id_wishlist'] == $wishlist['id_wishlist']) {
                 unset($wishlists[$key]);
                 break;
             }
         }
         $this->context->smarty->assign(array('current_wishlist' => $wishlist, 'token' => $token, 'ajax' => isset($ajax) && (int) $ajax == 1 ? '1' : '0', 'wishlists' => $wishlists, 'products' => $products));
     }
     $this->setTemplate('view.tpl');
 }
Example #6
0
                $wishlist->name = $name;
                $wishlist->id_customer = $cookie->id_customer;
                list($us, $s) = explode(' ', microtime());
                srand($s * $us);
                $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $cookie->id_customer), 0, 16));
                $wishlist->add();
            }
        }
    } else {
        if ($add) {
            WishList::addCardToWishlist(intval($cookie->id_customer), intval(Tools::getValue('id_wishlist')), intval($cookie->id_lang));
        } else {
            if ($delete and empty($id_wishlist) === false) {
                $wishlist = new WishList(intval($id_wishlist));
                if (Validate::isLoadedObject($wishlist)) {
                    $wishlist->delete();
                } else {
                    $errors[] = Tools::displayError('can`t delete this whislist');
                }
            }
        }
    }
    $smarty->assign('wishlists', WishList::getByIdCustomer(intval($cookie->id_customer)));
    $smarty->assign('nbProducts', WishList::getInfosByIdCustomer(intval($cookie->id_customer)));
} else {
    Tools::redirect('authentication.php?back=/modules/blockwishlist/mywishlist.php');
}
$smarty->assign('id_customer', intval($cookie->id_customer));
$smarty->assign('errors', $errors);
$smarty->display(dirname(__FILE__) . '/mywishlist.tpl');
include dirname(__FILE__) . '/../../footer.php';
Example #7
0
    }
    public function getAllProducts()
    {
        return $this->products;
    }
    public function findProductByName($name)
    {
        $productKey = null;
        foreach ($this->products as $key => $product) {
            if ($product->name == $name) {
                $productKey = $key + 1;
                return $product . ' is number ' . $productKey . ' in the Wish List. <br />';
            } else {
                throw new Exception("No product with given name found in Wish List");
            }
        }
    }
}
$itemDescriber = new ItemDescriber();
$hoodie = new Clothing("Hoodie", "Nike", 19.99, "large", "red", "shirt", "male");
$plasma = new Television("Plasma", "Sony", 1000.0, plasma, "50in");
$wishList = new WishList();
$wishList->addProduct($hoodie);
$wishList->addProduct($plasma);
$shoppingCart = $wishList->createCartFromContainer($wishList);
$wishList->provideDescription();
$shoppingCart->provideDescription();
?>
    </p>
  </body>
</html>
Example #8
0
                $products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image'];
            } else {
                $images = $obj->getImages(intval($cookie->id_lang));
                foreach ($images as $k => $image) {
                    if ($image['cover']) {
                        $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
                        break;
                    }
                }
                if (!isset($products[$i]['cover'])) {
                    $products[$i]['cover'] = Language::getIsoById(intval($cookie->id_lang)) . '-default';
                }
            }
        }
    }
    WishList::incCounter(intval($wishlist['id_wishlist']));
    $ajax = Configuration::get('PS_BLOCK_CART_AJAX');
    $smarty->assign('current_wishlist', $wishlist);
    $smarty->assign('token', $token);
    $smarty->assign('ajax', (isset($ajax) and intval($ajax) == 1) ? '1' : '0');
    $smarty->assign('wishlists', WishList::getByIdCustomer(intval($wishlist['id_customer'])));
    $smarty->assign('products', $products);
}
if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl');
} elseif (Tools::file_exists_cache(dirname(__FILE__) . '/view.tpl')) {
    $smarty->display(dirname(__FILE__) . '/view.tpl');
} else {
    echo Tools::displayError('No template found');
}
require dirname(__FILE__) . '/../../footer.php';
 private function getCommonDate()
 {
     $currCurency = Setup::getCurrCurency();
     $data['currCurency'] = $currCurency;
     $currLang = Setup::getCurrLang();
     $data['currLang'] = $currLang;
     $iP = Yii::$app->session->id;
     $modelWishList = WishList::getListByIp($iP);
     $quantityWishlist = $modelWishList ? count($modelWishList) : '';
     $data['quantityWishlist'] = $quantityWishlist;
     $data['modelWishList'] = $modelWishList;
     $modelCompareList = Compare::getListByIp($iP);
     $quantityCompareList = $modelCompareList ? count($modelCompareList) : '';
     $data['quantityCompareList'] = $quantityCompareList;
     $data['modelCompareList '] = $modelCompareList;
     $quantityInCart = Cart::getQountAllByIp($iP);
     $data['quantityInCart'] = $quantityInCart;
     return $data;
 }
                        $products[$i]['cover'] = $context->language->iso_code . '-default';
                    }
                }
                $products[$i]['bought'] = false;
                for ($j = 0, $k = 0; $j < sizeof($bought); ++$j) {
                    if ($bought[$j]['id_product'] == $products[$i]['id_product'] and $bought[$j]['id_product_attribute'] == $products[$i]['id_product_attribute']) {
                        $products[$i]['bought'][$k++] = $bought[$j];
                    }
                }
            }
            $productBoughts = array();
            foreach ($products as $product) {
                if (sizeof($product['bought'])) {
                    $productBoughts[] = $product;
                }
            }
            $context->smarty->assign(array('products' => $products, 'productsBoughts' => $productBoughts, 'id_wishlist' => $id_wishlist, 'refresh' => $refresh, 'token_wish' => $wishlist->token, 'wishlists' => WishList::getByIdCustomer($cookie->id_customer)));
            // Instance of module class for translations
            $module = new BlockWishList();
            if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/views/templates/front/managewishlist.tpl')) {
                $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/views/templates/front/managewishlist.tpl');
            } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/views/templates/front/managewishlist.tpl')) {
                $context->smarty->display(dirname(__FILE__) . '/views/templates/front/managewishlist.tpl');
            } elseif (Tools::file_exists_cache(dirname(__FILE__) . '/managewishlist.tpl')) {
                $context->smarty->display(dirname(__FILE__) . '/managewishlist.tpl');
            } else {
                echo $module->l('No template found', 'managewishlist');
            }
        }
    }
}
 public function ajaxProcessDeleteList()
 {
     if (!$this->context->customer->isLogged()) {
         die(Tools::jsonEncode(array('success' => false, 'error' => $this->module->l('You aren\'t logged in', 'mywishlist'))));
     }
     $default = Tools::getIsset('default');
     $default = empty($default) === false ? 1 : 0;
     $id_wishlist = Tools::getValue('id_wishlist');
     $wishlist = new WishList((int) $id_wishlist);
     if (Validate::isLoadedObject($wishlist) && $wishlist->id_customer == $this->context->customer->id) {
         $default_change = $wishlist->default ? true : false;
         $id_customer = $wishlist->id_customer;
         $wishlist->delete();
     } else {
         die(Tools::jsonEncode(array('success' => false, 'error' => $this->module->l('Cannot delete this wishlist', 'mywishlist'))));
     }
     if ($default_change) {
         $array = WishList::getDefault($id_customer);
         if (count($array)) {
             die(Tools::jsonEncode(array('success' => true, 'id_default' => $array[0]['id_wishlist'])));
         }
     }
     die(Tools::jsonEncode(array('success' => true)));
 }
Example #12
0
        Tools::redirect('modules/wishlist/display.php?id=' . getHashFromCart($wishlist_cart));
    } else {
        if (Tools::isSubmit("addAllToCart")) {
            copyQty($wishlist_cart, $cart);
            Tools::redirect('modules/wishlist/display.php?id=' . getHashFromCart($wishlist_cart));
        }
    }
}
$errors = array();
$smarty->assign('errors', $errors);
$smarty->assign('mdl_dir', dirname(__FILE__) . '/');
$smarty->assign("currency_iso_code", $currency->iso_code);
$smarty->assign("currency_name", $currency->name);
$smarty->assign('cart_hash_id', $_GET['id']);
if (!$wishlist_cart->nbProducts()) {
    $smarty->assign('empty', 1);
}
if (file_exists(_PS_SHIP_IMG_DIR_ . intval($wishlist_cart->id_carrier) . '.jpg')) {
    $smarty->assign('carrierPicture', 1);
}
$summary = $wishlist_cart->getSummaryDetails();
$customizedDatas = Product::getAllCustomizedDatas(intval($wishlist_cart->id));
Product::addCustomizationPrice($summary['products'], $customizedDatas);
$smarty->assign($summary);
$smarty->assign(array('customizedDatas' => $customizedDatas, 'CUSTOMIZE_FILE' => _CUSTOMIZE_FILE_, 'CUSTOMIZE_TEXTFIELD' => _CUSTOMIZE_TEXTFIELD_, 'lastProductAdded' => $wishlist_cart->getLastProduct()));
$smarty->assign('cart', $wishlist_cart);
Tools::safePostVars();
include_once dirname(__FILE__) . '/../../header.php';
$lst = new WishList();
echo $lst->display(dirname(__FILE__) . '/wishlist.php', 'wishlist.tpl');
include dirname(__FILE__) . '/../../footer.php';
 public function testMultipleLists()
 {
     WishList::set_current(null);
     $m1 = $this->objFromFixture('Member', 'm1');
     $m2 = $this->objFromFixture('Member', 'm2');
     $m1->logIn();
     $p1 = $this->objFromFixture('Product', 'p1');
     $p2 = $this->objFromFixture('Product', 'p2');
     $p3 = $this->objFromFixture('Product', 'p3');
     // should be able to retrieve a list of lists
     $allLists = WishList::get_for_user();
     $this->assertNotNull($allLists);
     $this->assertTrue($allLists instanceof DataList);
     // should initially be 0 lists
     $this->assertEquals(0, WishList::get_for_user()->count());
     $this->assertEquals(0, WishList::get_for_user($m2)->count());
     // current method should create one list
     $l1 = WishList::current();
     $l1->write();
     $l1->addBuyable($p1);
     //Debug::dump(array($l1, WishList::get_for_user()->sql(), WishList::get_for_user()->count(), WishList::get_for_user()->getIDList()));
     $this->assertEquals(1, WishList::get_for_user()->count());
     $this->assertEquals(0, WishList::get_for_user($m2)->count());
     // after manually creating a list there should be two lists
     $l2 = new WishList(array('OwnerID' => $m1->ID, 'Title' => 'Christmas'));
     $l2->write();
     $this->assertEquals(2, WishList::get_for_user()->count());
     // after adding a product to one list, it should not be present in the other one
     // but should still report that it is in a list
     $l2->addBuyable($p2);
     $this->assertTrue($p1->IsInWishList());
     $this->assertTrue($l1->hasBuyable($p1));
     $this->assertFalse($l2->hasBuyable($p1));
     $this->assertTrue($p2->IsInWishList());
     $this->assertFalse($l1->hasBuyable($p2));
     $this->assertTrue($l2->hasBuyable($p2));
     $this->assertFalse($p3->IsInWishList());
     $this->assertFalse($l1->hasBuyable($p3));
     $this->assertFalse($l2->hasBuyable($p3));
     // after creating a list for the a different user and adding
     // an item to that list, the item should not report that it is
     // in a list and should not be present in any of the other lists
     $l3 = new WishList(array('OwnerID' => $m2->ID, 'Title' => 'Christmas for someone else'));
     $l3->write();
     $l3->addBuyable($p3);
     $this->assertEquals(2, WishList::get_for_user()->count());
     $this->assertEquals(1, WishList::get_for_user($m2)->count());
     $this->assertFalse($p3->IsInWishList());
     $this->assertFalse($l1->hasBuyable($p3));
     $this->assertFalse($l2->hasBuyable($p3));
     // Buyable should be able to exist in two lists at once
     $l2->addBuyable($p1);
     $this->assertTrue($p1->IsInWishList());
     $this->assertTrue($l1->hasBuyable($p1));
     $this->assertTrue($l2->hasBuyable($p1));
     // removing an item from one list should not remove it from the other
     $l1->removeBuyable($p1);
     $this->assertTrue($p1->IsInWishList());
     $this->assertFalse($l1->hasBuyable($p1));
     $this->assertTrue($l2->hasBuyable($p1));
     // after removing item from both lists it should report as not being in a list
     $l2->removeBuyable($p1);
     $this->assertFalse($p1->IsInWishList());
     $this->assertFalse($l1->hasBuyable($p1));
     $this->assertFalse($l2->hasBuyable($p1));
 }
Example #14
0
 public function createNewWishListForUser(User $user, $name = 'New Wish List', $type = WishList::TYPE_PRIVATE)
 {
     if (!$user || !$user->loaded()) {
         throw new \InvalidArgumentException('User is not valid.');
     }
     $wishList = new WishList($this->pixie);
     if (!$wishList->isValidType($type)) {
         $type = WishList::TYPE_PRIVATE;
     }
     $wishList->type = $type;
     $wishList->name = $name;
     $wishList->created = date('Y-m-d H:i:s');
     $wishList->addToUser($user);
     $wishList->save();
     return $wishList;
 }
Example #15
0
            $errors[] = Tools::displayError('invalid token');
        }
        if (!sizeof($errors)) {
            $name = Tools::getValue('name');
            $wishlist = new WishList();
            $wishlist->name = $name;
            $wishlist->id_customer = $cookie->id_customer;
            list($us, $s) = explode(' ', microtime());
            srand($s * $us);
            $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $cookie->id_customer), 0, 16));
            $wishlist->add();
        }
    } else {
        if ($add) {
            WishList::addCardToWishlist(intval($cookie->id_customer), intval(Tools::getValue('id_wishlist')), intval($cookie->id_lang));
        } else {
            if ($delete and empty($id_wishlist) === false) {
                $wishlist = new WishList(intval($id_wishlist));
                $wishlist->delete();
            }
        }
    }
    $smarty->assign('wishlists', WishList::getByIdCustomer(intval($cookie->id_customer)));
    $smarty->assign('nbProducts', WishList::getInfosByIdCustomer(intval($cookie->id_customer)));
} else {
    $errors[] = Tools::displayError('You need to be logged to manage your wishlist');
}
$smarty->assign('id_customer', intval($cookie->id_customer));
$smarty->assign('errors', $errors);
$smarty->display(dirname(__FILE__) . '/mywishlist.tpl');
include dirname(__FILE__) . '/../../footer.php';
Example #16
0
 /**
  * Assign wishlist template
  */
 public function assign()
 {
     $errors = array();
     if ($this->context->customer->isLogged()) {
         $add = Tools::getIsset('add');
         $add = empty($add) === false ? 1 : 0;
         $delete = Tools::getIsset('deleted');
         $delete = empty($delete) === false ? 1 : 0;
         $default = Tools::getIsset('default');
         $default = empty($default) === false ? 1 : 0;
         $id_wishlist = Tools::getValue('id_wishlist');
         if (Tools::isSubmit('submitWishlist')) {
             if (Configuration::get('PS_TOKEN_ACTIVATED') == 1 && strcmp(Tools::getToken(), Tools::getValue('token'))) {
                 $errors[] = $this->module->l('Invalid token', 'mywishlist');
             }
             if (!count($errors)) {
                 $name = Tools::getValue('name');
                 if (empty($name)) {
                     $errors[] = $this->module->l('You must specify a name.', 'mywishlist');
                 }
                 if (WishList::isExistsByNameForUser($name)) {
                     $errors[] = $this->module->l('This name is already used by another list.', '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->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 = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $this->context->customer->id), 0, 16));
                     $wishlist->add();
                     Mail::Send($this->context->language->id, 'wishlink', Mail::l('Your wishlist\'s link', $this->context->language->id), array('{wishlist}' => $wishlist->name, '{message}' => $this->context->link->getModuleLink('blockwishlist', 'view', array('token' => $wishlist->token))), $this->context->customer->email, $this->context->customer->firstname . ' ' . $this->context->customer->lastname, null, strval(Configuration::get('PS_SHOP_NAME')), null, null, $this->module->getLocalPath() . 'mails/');
                     Tools::redirect($this->context->link->getModuleLink('blockwishlist', 'mywishlist'));
                 }
             }
         } else {
             if ($add) {
                 WishList::addCardToWishlist($this->context->customer->id, Tools::getValue('id_wishlist'), $this->context->language->id);
             } elseif ($delete && empty($id_wishlist) === false) {
                 $wishlist = new WishList((int) $id_wishlist);
                 if (Validate::isLoadedObject($wishlist)) {
                     $wishlist->delete();
                 } else {
                     $errors[] = $this->module->l('Cannot delete this wishlist', 'mywishlist');
                 }
             } elseif ($default) {
                 $wishlist = new WishList((int) $id_wishlist);
                 if (Validate::isLoadedObject($wishlist)) {
                     $wishlist->setDefault();
                 }
             }
         }
         $this->context->smarty->assign('wishlists', WishList::getByIdCustomer($this->context->customer->id));
         $this->context->smarty->assign('nbProducts', WishList::getInfosByIdCustomer($this->context->customer->id));
     } else {
         Tools::redirect('index.php?controller=authentication&back=' . urlencode($this->context->link->getModuleLink('blockwishlist', 'mywishlist')));
     }
     $this->context->smarty->assign(array('id_customer' => (int) $this->context->customer->id, 'errors' => $errors, 'form_link' => $errors));
     $this->setTemplate('mywishlist.tpl');
 }
Example #17
0
    /**
     * Add product to ID wishlist
     *
     * @return boolean succeed
     */
    public static function addProduct($id_wishlist, $id_customer, $id_product, $id_product_attribute, $quantity)
    {
        if (!Validate::isUnsignedId($id_wishlist) || !Validate::isUnsignedId($id_customer) || !Validate::isUnsignedId($id_product) || !Validate::isUnsignedFloat($quantity)) {
            die(Tools::displayError());
        }
        $qty_policy_legacy = PP::productQtyPolicyLegacy($id_product);
        $result = Db::getInstance()->getRow('
		SELECT wp.`quantity`, wp.`quantity_fractional`
		  FROM `' . _DB_PREFIX_ . 'wishlist_product` wp
		JOIN `' . _DB_PREFIX_ . 'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`)
		WHERE wp.`id_wishlist` = ' . (int) $id_wishlist . '
		AND w.`id_customer` = ' . (int) $id_customer . '
		AND wp.`id_product` = ' . (int) $id_product . '
		AND wp.`id_product_attribute` = ' . (int) $id_product_attribute);
        if (empty($result) === false && count($result)) {
            $qty = $qty_policy_legacy ? $result['quantity'] : $result['quantity'] * $result['quantity_fractional'];
            if ($qty + $quantity <= 0) {
                return WishList::removeProduct($id_wishlist, $id_customer, $id_product, $id_product_attribute);
            } else {
                return Db::getInstance()->execute('
				UPDATE `' . _DB_PREFIX_ . 'wishlist_product` SET
				`quantity` = ' . ($qty_policy_legacy ? (int) ($quantity + $qty) : 1) . ',
				`quantity_fractional` = ' . ($qty_policy_legacy ? 0 : (double) ($quantity + $qty)) . '
				WHERE `id_wishlist` = ' . (int) $id_wishlist . '
				AND `id_product` = ' . (int) $id_product . '
				AND `id_product_attribute` = ' . (int) $id_product_attribute);
            }
        } else {
            return Db::getInstance()->execute('
			INSERT INTO `' . _DB_PREFIX_ . 'wishlist_product` (`id_wishlist`, `id_product`, `id_product_attribute`, `quantity`, `quantity_fractional`, `priority`) VALUES(
			' . (int) $id_wishlist . ',
			' . (int) $id_product . ',
			' . (int) $id_product_attribute . ',
			' . ($qty_policy_legacy ? (int) $quantity : 1) . ',
			' . ($qty_policy_legacy ? 0 : (double) $quantity) . ',
			 1)');
        }
    }
 /**
  * @param array $data
  */
 public function addtowishlist(array $data)
 {
     if (!class_exists('WishList')) {
         user_error('Wish List module not installed.');
     }
     $groupedProduct = $this->getController()->data();
     if (empty($data) || empty($data['Product']) || !is_array($data['Product'])) {
         $this->sessionMessage(_t('GroupedCartForm.EMPTY', 'Please select at least one product.'), 'bad');
         $this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
         return $response ? $response : $this->controller->redirectBack();
     }
     $list = WishList::current();
     foreach ($data['Product'] as $id => $prodReq) {
         if (!empty($prodReq['Quantity']) && $prodReq['Quantity'] > 0) {
             $prod = Product::get()->byID($id);
             if ($prod && $prod->exists()) {
                 $buyable = $prod;
                 if (isset($prodReq['Attributes'])) {
                     $buyable = $prod->getVariationByAttributes($prodReq['Attributes']);
                     if (!$buyable || !$buyable->exists()) {
                         $this->sessionMessage("{$prod->InternalItemID} is not available with the selected options.", "bad");
                         $this->extend('updateErrorResponse', $this->request, $response, $groupedProduct, $data, $this);
                         return $response ? $response : $this->controller->redirectBack();
                     }
                 }
                 $list->addBuyable($buyable);
             }
         }
     }
     $this->extend('updateGroupWishListResponse', $this->request, $response, $groupedProduct, $data, $this);
     return $response ? $response : $this->controller->redirect(WishListPage::inst()->Link());
 }
Example #19
0
    /**
     * Add product to ID wishlist
     *
     * @return boolean succeed
     */
    public static function addProduct($id_wishlist, $id_customer, $id_product, $id_product_attribute, $quantity)
    {
        if (!Validate::isUnsignedId($id_wishlist) or !Validate::isUnsignedId($id_customer) or !Validate::isUnsignedId($id_product) or !Validate::isUnsignedId($quantity)) {
            die(Tools::displayError());
        }
        $result = Db::getInstance()->getRow('
		SELECT wp.`quantity`
		  FROM `' . _DB_PREFIX_ . 'wishlist_product` wp
		JOIN `' . _DB_PREFIX_ . 'wishlist` w ON (w.`id_wishlist` = wp.`id_wishlist`)
		WHERE wp.`id_wishlist` = ' . (int) $id_wishlist . '
		AND w.`id_customer` = ' . (int) $id_customer . '
		AND wp.`id_product` = ' . (int) $id_product . '
		AND wp.`id_product_attribute` = ' . (int) $id_product_attribute);
        if (empty($result) === false and sizeof($result)) {
            if ($result['quantity'] + $quantity <= 0) {
                return WishList::removeProduct($id_wishlist, $id_customer, $id_product, $id_product_attribute);
            } else {
                return Db::getInstance()->Execute('
				UPDATE `' . _DB_PREFIX_ . 'wishlist_product` SET
				`quantity` = ' . (int) ($quantity + $result['quantity']) . '
				WHERE `id_wishlist` = ' . (int) $id_wishlist . '
				AND `id_product` = ' . (int) $id_product . '
				AND `id_product_attribute` = ' . (int) $id_product_attribute);
            }
        } else {
            return Db::getInstance()->Execute('
			INSERT INTO `' . _DB_PREFIX_ . 'wishlist_product` (`id_wishlist`, `id_product`, `id_product_attribute`, `quantity`, `priority`) VALUES(
			' . (int) $id_wishlist . ',
			' . (int) $id_product . ',
			' . (int) $id_product_attribute . ',
			' . (int) $quantity . ', 1)');
        }
    }
Example #20
0
if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcmp(Tools::getToken(false), Tools::getValue('token')) && $context->customer->isLogged() === true) {
    echo $module->l('Invalid token', 'cart');
}
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 (empty($context->cookie->id_wishlist) === true || $context->cookie->id_wishlist == false) {
        $context->smarty->assign('error', true);
    }
    if (($add || $delete) && 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;
            $mod_wishlist = new BlockWishList();
            $wishlist->name = $mod_wishlist->default_wishlist_name;
            $wishlist->id_customer = (int) $context->customer->id;
            list($us, $s) = explode(' ', microtime());
            srand($s * $us);
            $wishlist->token = strtoupper(substr(sha1(uniqid(rand(), true) . _COOKIE_KEY_ . $context->customer->id), 0, 16));
            $wishlist->add();
            $context->cookie->id_wishlist = (int) $wishlist->id;
        }
        if ($add && $quantity) {
            WishList::addProduct($context->cookie->id_wishlist, $context->customer->id, $id_product, $id_product_attribute, $quantity);
        } else {
Example #21
0
            continue;
        } else {
            if ($products[$i]['id_product_attribute'] != 0 && isset($combination_imgs[$products[$i]['id_product_attribute']][0])) {
                $combination_imgs = $obj->getCombinationImages((int) $cookie->id_lang);
                $products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image'];
            } else {
                $images = $obj->getImages((int) $cookie->id_lang);
                foreach ($images as $k => $image) {
                    if ($image['cover']) {
                        $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
                        break;
                    }
                }
                if (!isset($products[$i]['cover'])) {
                    $products[$i]['cover'] = Language::getIsoById((int) $cookie->id_lang) . '-default';
                }
            }
        }
    }
    WishList::incCounter((int) $wishlist['id_wishlist']);
    $ajax = Configuration::get('PS_BLOCK_CART_AJAX');
    $smarty->assign(array('current_wishlist' => $wishlist, 'token' => $token, 'ajax' => (isset($ajax) and (int) $ajax == 1) ? '1' : '0', 'wishlists' => WishList::getByIdCustomer((int) $wishlist['id_customer']), 'products' => $products));
}
if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl')) {
    $smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/view.tpl');
} elseif (Tools::file_exists_cache(dirname(__FILE__) . '/view.tpl')) {
    $smarty->display(dirname(__FILE__) . '/view.tpl');
} else {
    echo Tools::displayError('No template found');
}
require dirname(__FILE__) . '/../../footer.php';
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <*****@*****.**>
*  @copyright  2007-2012 PrestaShop SA
*  @version  Release: $Revision: 6844 $
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
require_once dirname(__FILE__) . '/../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../init.php';
require_once dirname(__FILE__) . '/WishList.php';
$error = '';
// Instance of module class for translations
$module = new BlockWishList();
$token = Tools::getValue('token');
$id_product = (int) Tools::getValue('id_product');
$id_product_attribute = (int) Tools::getValue('id_product_attribute');
if (Configuration::get('PS_TOKEN_ENABLE') == 1 && strcmp(Tools::getToken(false), Tools::getValue('static_token'))) {
    $error = $module->l('Invalid token', 'buywishlistproduct');
}
if (!strlen($error) && empty($token) === false && empty($id_product) === false) {
    $wishlist = WishList::getByToken($token);
    if ($wishlist !== false) {
        WishList::addBoughtProduct($wishlist['id_wishlist'], $id_product, $id_product_attribute, $cart->id, 1);
    }
} else {
    $error = $module->l('You must log in', 'buywishlistproduct');
}
if (empty($error) === false) {
    echo $error;
}
Example #23
0
                Mail::Send($context->language->id, 'wishlink', Mail::l('Your wishlist\'s link', $context->language->id), array('{wishlist}' => $wishlist->name, '{message}' => Tools::getProtocol() . htmlentities($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/blockwishlist/view.php?token=' . $wishlist->token), $context->customer->email, $context->customer->firstname . ' ' . $context->customer->lastname, NULL, strval(Configuration::get('PS_SHOP_NAME')), NULL, NULL, dirname(__FILE__) . '/mails/');
            }
        }
    } else {
        if ($add) {
            WishList::addCardToWishlist($context->customer->id, Tools::getValue('id_wishlist'), $context->language->id);
        } else {
            if ($delete and empty($id_wishlist) === false) {
                $wishlist = new WishList((int) $id_wishlist);
                if (Validate::isLoadedObject($wishlist)) {
                    $wishlist->delete();
                } else {
                    $errors[] = $module->l('Cannot delete this wishlist', 'mywishlist');
                }
            }
        }
    }
    $context->smarty->assign('wishlists', WishList::getByIdCustomer($context->customer->id));
    $context->smarty->assign('nbProducts', WishList::getInfosByIdCustomer($context->customer->id));
} else {
    Tools::redirect('index.php?controller=authentication&back=modules/blockwishlist/mywishlist.php');
}
$context->smarty->assign(array('id_customer' => (int) $context->customer->id, 'errors' => $errors));
if (Tools::file_exists_cache(_PS_THEME_DIR_ . 'modules/blockwishlist/mywishlist.tpl')) {
    $context->smarty->display(_PS_THEME_DIR_ . 'modules/blockwishlist/mywishlist.tpl');
} elseif (Tools::file_exists_cache(dirname(__FILE__) . '/views/templates/front/mywishlist.tpl')) {
    $context->smarty->display(dirname(__FILE__) . '/views/templates/front/mywishlist.tpl');
} else {
    echo $module->l('No template found', 'mywishlist');
}
include dirname(__FILE__) . '/../../footer.php';
Example #24
0
 public function hookAdminCustomers($params)
 {
     require_once dirname(__FILE__) . '/WishList.php';
     $customer = new Customer((int) $params['id_customer']);
     if (!Validate::isLoadedObject($customer)) {
         die(Tools::displayError());
     }
     $this->_html = '<h2>' . $this->l('Wishlists') . '</h2>';
     $wishlists = WishList::getByIdCustomer((int) $customer->id);
     if (!sizeof($wishlists)) {
         $this->_html .= $customer->lastname . ' ' . $customer->firstname . ' ' . $this->l('No wishlist.');
     } else {
         $this->_html .= '<form action="' . Tools::safeOutput($_SERVER['REQUEST_URI']) . '" method="post" id="listing">';
         $id_wishlist = (int) Tools::getValue('id_wishlist');
         if (!$id_wishlist) {
             $id_wishlist = $wishlists[0]['id_wishlist'];
         }
         $this->_html .= '<span>' . $this->l('Wishlist') . ': </span> <select name="id_wishlist" onchange="$(\'#listing\').submit();">';
         foreach ($wishlists as $wishlist) {
             $this->_html .= '<option value="' . (int) $wishlist['id_wishlist'] . '"';
             if ($wishlist['id_wishlist'] == $id_wishlist) {
                 $this->_html .= ' selected="selected"';
                 $counter = $wishlist['counter'];
             }
             $this->_html .= '>' . htmlentities($wishlist['name'], ENT_COMPAT, 'UTF-8') . '</option>';
         }
         $this->_html .= '</select>';
         $this->_displayProducts((int) $id_wishlist);
         $this->_html .= '</form><br />';
         return $this->_html;
     }
 }
Example #25
0
 public function renderList($id_wishlist)
 {
     $wishlist = new WishList($id_wishlist);
     $products = WishList::getProductByIdCustomer($id_wishlist, $wishlist->id_customer, $this->context->language->id);
     foreach ($products as $key => $val) {
         $image = Image::getCover($val['id_product']);
         $products[$key]['image'] = $this->context->link->getImageLink($val['link_rewrite'], $image['id_image'], ImageType::getFormatedName('small'));
     }
     $fields_list = array('image' => array('title' => $this->l('Image'), 'type' => 'image'), 'name' => array('title' => $this->l('Product'), 'type' => 'text'), 'attributes_small' => array('title' => $this->l('Combination'), 'type' => 'text'), 'quantity' => array('title' => $this->l('Quantity'), 'type' => 'text'), 'priority' => array('title' => $this->l('Priority'), 'type' => 'priority', 'values' => array($this->l('High'), $this->l('Medium'), $this->l('Low'))));
     $helper = new HelperList();
     $helper->shopLinkType = '';
     $helper->simple_header = true;
     $helper->no_link = true;
     $helper->actions = array('view');
     $helper->show_toolbar = false;
     $helper->module = $this;
     $helper->identifier = 'id_product';
     $helper->title = $this->l('Product list');
     $helper->table = $this->name;
     $helper->token = Tools::getAdminTokenLite('AdminModules');
     $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
     $helper->tpl_vars = array('priority' => array($this->l('High'), $this->l('Medium'), $this->l('Low')));
     return $helper->generateList($products, $fields_list);
 }
Example #26
0
 $id_wishlist = (int) Tools::getValue('id_wishlist');
 $id_product = (int) Tools::getValue('id_product');
 $id_product_attribute = (int) Tools::getValue('id_product_attribute');
 $quantity = (int) Tools::getValue('quantity');
 $priority = Tools::getValue('priority');
 $wishlist = new WishList((int) $id_wishlist);
 $refresh = $_GET['refresh'] == 'true' ? 1 : 0;
 if (empty($id_wishlist) === false) {
     if (!strcmp($action, 'update')) {
         WishList::updateProduct($id_wishlist, $id_product, $id_product_attribute, $priority, $quantity);
     } else {
         if (!strcmp($action, 'delete')) {
             WishList::removeProduct($id_wishlist, (int) $context->customer->id, $id_product, $id_product_attribute);
         }
         $products = WishList::getProductByIdCustomer($id_wishlist, $context->customer->id, $context->language->id);
         $bought = WishList::getBoughtProduct($id_wishlist);
         for ($i = 0; $i < sizeof($products); ++$i) {
             $obj = new Product((int) $products[$i]['id_product'], false, $context->language->id);
             if (!Validate::isLoadedObject($obj)) {
                 continue;
             } else {
                 if ($products[$i]['id_product_attribute'] != 0) {
                     $combination_imgs = $obj->getCombinationImages($context->language->id);
                     if (isset($combination_imgs[$products[$i]['id_product_attribute']][0])) {
                         $products[$i]['cover'] = $obj->id . '-' . $combination_imgs[$products[$i]['id_product_attribute']][0]['id_image'];
                     }
                 } else {
                     $images = $obj->getImages($context->language->id);
                     foreach ($images as $k => $image) {
                         if ($image['cover']) {
                             $products[$i]['cover'] = $obj->id . '-' . $image['id_image'];
 /**
  * @param SS_HTTPRequest $request
  * @param AjaxHTTPResponse $response
  * @param GroupedProduct $groupedProduct
  * @param array $data
  * @param GroupedCartForm $form [optional]
  */
 public function updateGroupWishListResponse(&$request, &$response, $groupedProduct, $data, $form = null)
 {
     if ($request->isAjax() && $this->owner->getController()->hasExtension('AjaxControllerExtension')) {
         if (!$response) {
             $response = $this->owner->getController()->getAjaxResponse();
         }
         $this->setupRenderContexts($response, $groupedProduct, $form);
         $response->triggerEvent('wishlistadd');
         $response->triggerEvent('wishlistchange', array('action' => 'add'));
         $n = 0;
         foreach ($data['Product'] as $info) {
             if ($info['Quantity'] > 0) {
                 $n++;
             }
         }
         $s = $n == 1 ? '' : 's';
         $response->triggerEvent('statusmessage', "{$n} item{$s} added to " . WishList::current()->getTitle());
     }
 }
Example #28
-10
    {
        return $this->items;
    }
    public function findProductByName($name)
    {
        $itemKey = null;
        foreach ($this->items as $key => $item) {
            if ($name == $item->getName()) {
                $itemKey = $key + 1;
                echo "{$name} is number {$itemKey} in the array";
                break;
            }
        }
        if ($itemKey == null) {
            throw new Exception("Item was not found in cart");
        }
    }
}
$describer = new ItemDescriber();
$kramericaTV = new Television("Giant TV", "Kramerica", 3900.9, "LED", "100in");
$shirt = new Clothing("Button Down Shirt", "J Peterman", '29.88', "shirt", "medium", "red", "male");
$Wishlist = new WishList();
$Wishlist->addProduct($kramericaTV);
$Wishlist->addProduct($shirt);
$ShoppingCart = $Wishlist->createCartFromContainer($Wishlist);
$Wishlist->provideDescription();
$ShoppingCart->provideDescription();
?>
    </p>
  </body>
</html>
Example #29
-14
 /**
  * @param Member $member [optional] - defaults to current user
  * @return DataList
  */
 public static function get_for_user(Member $member = null)
 {
     if (!$member) {
         $member = Member::currentUser();
     }
     if (!$member) {
         return null;
     }
     return WishList::get()->filter('OwnerID', $member->ID);
 }