本文整理汇总了PHP中Product::idIsOnCategoryId方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::idIsOnCategoryId方法的具体用法?PHP Product::idIsOnCategoryId怎么用?PHP Product::idIsOnCategoryId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Product
的用法示例。
在下文中一共展示了Product::idIsOnCategoryId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hookproductnavs
public function hookproductnavs()
{
$id_product = (int) Tools::getValue('id_product');
if (!$id_product) {
return true;
}
$product = new Product($id_product, false, (int) Context::getContext()->language->id);
$productInLastVisitedCategory = Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => (int) $this->context->cookie->last_visited_category)));
if ((!isset($this->context->cookie->last_visited_category) or !$productInLastVisitedCategory) and Validate::isLoadedObject($product)) {
$this->context->cookie->last_visited_category = (int) $product->id_category_default;
}
$cur_position = $this->getPositionInCategory($id_product, $this->context->cookie->last_visited_category);
$nextProductId = $this->getNextInCategory($cur_position, $this->context->cookie->last_visited_category);
$prevProductId = $this->getPreviousInCategory($cur_position, $this->context->cookie->last_visited_category);
$prevLink = NULL;
$prevName = NULL;
$nextLink = NULL;
$nextName = NULL;
if (isset($prevProductId)) {
$cat_product = new Product($prevProductId, false, (int) Context::getContext()->language->id);
$prevLink = $this->context->link->getProductLink($cat_product);
$prevName = $cat_product->name;
}
if (isset($nextProductId)) {
$cat_product = new Product($nextProductId, false, (int) Context::getContext()->language->id);
$nextLink = $this->context->link->getProductLink($cat_product);
$nextName = $cat_product->name;
}
$this->context->smarty->assign(array('prevLink' => $prevLink, 'prevName' => $prevName, 'nextLink' => $nextLink, 'nextName' => $nextName));
if ($this->context->cookie->last_visited_category == 2) {
$this->context->cookie->last_visited_category = (int) $product->id_category_default;
}
return $this->display(__FILE__, 'productsnavpn.tpl');
}
示例2: setLastVisitedCategory
public function setLastVisitedCategory()
{
$cache_id = 'pspagebuilder::setLastVisitedCategory';
$context = Context::getContext();
if (!Cache::isStored($cache_id)) {
if (method_exists($context->controller, 'getCategory') && ($category = $context->controller->getCategory())) {
$context->cookie->last_visited_category = $category->id;
} elseif (method_exists($context->controller, 'getProduct') && ($product = $context->controller->getProduct())) {
if (!isset($context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $context->cookie->last_visited_category))) || !Category::inShopStatic($context->cookie->last_visited_category, $context->shop)) {
$context->cookie->last_visited_category = (int) $product->id_category_default;
}
}
Cache::store($cache_id, $context->cookie->last_visited_category);
}
return Cache::retrieve($cache_id);
}
示例3: init
public function init()
{
parent::init();
$pagerCat = FALSE;
if (isset($_SERVER['HTTP_REFERER'])) {
$parseQuery = explode('id_category=', $_SERVER['HTTP_REFERER']);
if (count($parseQuery) == 2) {
$parseQuery[1] = (int) $parseQuery[1];
if ($parseQuery[1]) {
$pagerCat = $parseQuery[1];
}
}
}
if ((int) Tools::getValue('pagerCat')) {
$pagerCat = (int) Tools::getValue('pagerCat');
}
if ($pagerCat) {
if (Product::idIsOnCategoryId((int) $this->product->id, array(array('id_category' => $pagerCat)))) {
$this->category = new Category($pagerCat, (int) $this->context->cookie->id_lang);
}
}
}
示例4: process
public function process()
{
global $cart, $currency;
parent::process();
if (!Validate::isLoadedObject($this->product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
} else {
self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
if (!$this->product->active) {
self::$smarty->assign('adminActionDisplay', true);
}
/* Product pictures management */
require_once 'images.inc.php';
if ($this->product->customizable) {
self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
if (Tools::isSubmit('submitCustomizedDatas')) {
$this->pictureUpload($this->product, $cart);
$this->textRecord($this->product, $cart);
$this->formTargetFormat();
} elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
}
$files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
$textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
foreach ($textFields as $key => $textField) {
$textFields[$key] = str_replace('<br />', "\n", $textField);
}
self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
}
/* Features / Values */
$features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
$attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array();
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
}
}
}
if (!$category) {
$category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
}
if (isset($category) and Validate::isLoadedObject($category)) {
self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
} else {
self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
}
self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) {
$this->product->quantity = 0;
}
$group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100;
$id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
// Tax
$tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
self::$smarty->assign('tax_rate', $tax);
$productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
$productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
$ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_));
self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent')));
$images = $this->product->getImages((int) self::$cookie->id_lang);
$productImages = array();
foreach ($images as $k => $image) {
if ($image['cover']) {
self::$smarty->assign('mainImage', $images[0]);
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
$cover['id_image_only'] = (int) $image['id_image'];
}
$productImages[(int) $image['id_image']] = $image;
}
if (!isset($cover)) {
$cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture');
}
$size = Image::getSize('large');
self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang)));
if (count($productImages)) {
self::$smarty->assign('images', $productImages);
//.........这里部分代码省略.........
示例5: hookFooter
public function hookFooter($params)
{
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
if (!$this->isCached('blockcategories_footer.tpl', $this->getCacheId())) {
$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
$groups = implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id));
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `' . _DB_PREFIX_ . 'category` c
' . Shop::addSqlAssociation('category', 'c') . '
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1)
' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . '
AND cg.`id_group` IN (' . pSQL($groups) . ')
ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'category_shop.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) {
return;
}
$resultParents = array();
$resultIds = array();
foreach ($result as &$row) {
$resultParents[$row['id_parent']][] =& $row;
$resultIds[$row['id_category']] =& $row;
}
//$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER');
$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER');
if (!$nbrColumns) {
$nbrColumns = 3;
}
$numberColumn = abs(count($result) / $nbrColumns);
$widthColumn = floor(100 / $nbrColumns);
$this->smarty->assign('numberColumn', $numberColumn);
$this->smarty->assign('widthColumn', $widthColumn);
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents, $resultIds);
$isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false;
$id_category = (int) Tools::getValue('id_category');
$id_product = (int) Tools::getValue('id_product');
if (Tools::isSubmit('id_category')) {
$this->context->cookie->last_visited_category = $id_category;
$this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product')) {
if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category)))) {
$product = new Product($id_product);
if (isset($product) && Validate::isLoadedObject($product)) {
$this->context->cookie->last_visited_category = (int) $product->id_category_default;
}
}
$this->smarty->assign('currentCategoryId', (int) $this->context->cookie->last_visited_category);
}
$this->smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories_footer.tpl')) {
$this->smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl');
} else {
$this->smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl');
}
$this->smarty->assign('isDhtml', $isDhtml);
}
$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $this->getCacheId());
return $display;
}
示例6: hookFooter
public function hookFooter($params)
{
global $smarty, $cookie;
$id_customer = (int) $params['cookie']->id_customer;
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
$groups = $id_customer ? implode(', ', Customer::getGroupsStatic($id_customer)) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_product = (int) Tools::getValue('id_product', 0);
$id_category = (int) Tools::getValue('id_category', 0);
$id_lang = (int) $params['cookie']->id_lang;
$smartyCacheId = 'blockcategories|' . $groups . '_' . $id_lang . '_' . $id_product . '_' . $id_category;
Tools::enableCache();
if (!$this->isCached('blockcategories_footer.tpl', $smartyCacheId)) {
$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `' . _DB_PREFIX_ . 'category` c
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = ' . $id_lang . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON (cg.`id_category` = c.`id_category`)
WHERE (c.`active` = 1 OR c.`id_category` = 1)
' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . '
AND cg.`id_group` IN (' . pSQL($groups) . ')
ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'c.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) {
return;
}
$resultParents = array();
$resultIds = array();
foreach ($result as &$row) {
$resultParents[$row['id_parent']][] =& $row;
$resultIds[$row['id_category']] =& $row;
}
//$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMNS_FOOTER');
$nbrColumns = Configuration::get('BLOCK_CATEG_NBR_COLUMN_FOOTER');
if (!$nbrColumns) {
$nbrColumns = 3;
}
$numberColumn = abs(sizeof($result) / $nbrColumns);
$widthColumn = floor(100 / $nbrColumns);
$smarty->assign('numberColumn', $numberColumn);
$smarty->assign('widthColumn', $widthColumn);
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents);
unset($resultIds);
$isDhtml = Configuration::get('BLOCK_CATEG_DHTML') == 1 ? true : false;
if (Tools::isSubmit('id_category')) {
$cookie->last_visited_category = $id_category;
$smarty->assign('currentCategoryId', $cookie->last_visited_category);
}
if (Tools::isSubmit('id_product')) {
if (!isset($cookie->last_visited_category) or !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $cookie->last_visited_category)))) {
$product = new Product($id_product);
if (isset($product) and Validate::isLoadedObject($product)) {
$cookie->last_visited_category = (int) $product->id_category_default;
}
}
$smarty->assign('currentCategoryId', (int) $cookie->last_visited_category);
}
$smarty->assign('blockCategTree', $blockCategTree);
if (file_exists(_PS_THEME_DIR_ . 'modules/blockcategories/blockcategories_footer.tpl')) {
$smarty->assign('branche_tpl_path', _PS_THEME_DIR_ . 'modules/blockcategories/category-tree-branch.tpl');
} else {
$smarty->assign('branche_tpl_path', _PS_MODULE_DIR_ . 'blockcategories/category-tree-branch.tpl');
}
$smarty->assign('isDhtml', $isDhtml);
}
$smarty->cache_lifetime = 31536000;
// 1 Year
$display = $this->display(__FILE__, 'blockcategories_footer.tpl', $smartyCacheId);
Tools::restoreCacheSettings();
return $display;
}
示例7: getCartNbPoints
public static function getCartNbPoints($cart, $newProduct = NULL)
{
$total = 0;
if (Validate::isLoadedObject($cart)) {
$currentContext = Context::getContext();
$context = clone $currentContext;
$context->cart = $cart;
// if customer is logged we do not recreate it
if (!$context->customer->isLogged(true)) {
$context->customer = new Customer($context->cart->id_customer);
}
$context->language = new Language($context->cart->id_lang);
$context->shop = new Shop($context->cart->id_shop);
$context->currency = new Currency($context->cart->id_currency, null, $context->shop->id);
$categories = Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE');
if ($categories != '' && $categories != 0) {
$categories = explode(',', Configuration::get('PS_LOYALTY_VOUCHER_CATEGORY_SOURCE'));
} else {
die(Tools::displayError());
}
$categories_array = array();
foreach ($categories as $id_category) {
array_push($categories_array, array('id_category' => $id_category));
}
$cartProducts = $cart->getProducts();
$taxesEnabled = Product::getTaxCalculationMethod();
if (isset($newProduct) and !empty($newProduct)) {
$cartProductsNew['id_product'] = (int) $newProduct->id;
if ($taxesEnabled == PS_TAX_EXC) {
$cartProductsNew['price'] = number_format($newProduct->getPrice(false, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
} else {
$cartProductsNew['price_wt'] = number_format($newProduct->getPrice(true, (int) $newProduct->getIdProductAttributeMostExpensive()), 2, '.', '');
}
$cartProductsNew['cart_quantity'] = 1;
$cartProducts[] = $cartProductsNew;
}
foreach ($cartProducts as $product) {
if (!(int) Configuration::get('PS_LOYALTY_NONE_AWARD') and Product::isDiscounted((int) $product['id_product'])) {
if (isset(Context::getContext()->smarty) and is_object($newProduct) and $product['id_product'] == $newProduct->id) {
Context::getContext()->smarty->assign('no_pts_discounted', 1);
}
continue;
}
/* Avoid generate points for product is not in source category */
if (!Product::idIsOnCategoryId((int) $product['id_product'], $categories_array)) {
continue;
}
$total += ($taxesEnabled == PS_TAX_EXC ? $product['price'] : $product['price_wt']) * (int) $product['cart_quantity'];
}
foreach ($cart->getCartRules(false) as $cart_rule) {
if ($taxesEnabled == PS_TAX_EXC) {
$total -= $cart_rule['value_tax_exc'];
} else {
$total -= $cart_rule['value_real'];
}
}
}
return self::getNbPointsByPrice($total);
}
示例8: init
/**
* Initialize product controller
* @see FrontController::init()
*/
public function init()
{
parent::init();
if ($id_product = (int) Tools::getValue('id_product')) {
$this->product = new Product($id_product, true, $this->context->language->id, $this->context->shop->id);
}
if (!Validate::isLoadedObject($this->product)) {
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
} else {
$this->canonicalRedirection();
}
if (!Validate::isLoadedObject($this->product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (Pack::isPack((int) $this->product->id) && !Pack::isInStock((int) $this->product->id)) {
$this->product->quantity = 0;
}
$this->product->description = $this->transformDescriptionWithImg($this->product->description);
/*
* If the product is associated to the shop
* and is active or not active but preview mode (need token + file_exists)
* allow showing the product
* In all the others cases => 404 "Product is no longer available"
*/
if (!$this->product->isAssociatedToShop() || !$this->product->active && (Tools::getValue('adtoken') != Tools::getAdminToken('AdminProducts' . (int) Tab::getIdFromClassName('AdminProducts') . (int) Tools::getValue('id_employee')) || !file_exists(_PS_ROOT_DIR_ . '/' . Tools::getValue('ad') . '/index.php'))) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} else {
if (!$this->product->checkAccess(isset($this->context->customer) ? $this->context->customer->id : 0)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
}
}
// Load category
if (isset($_SERVER['HTTP_REFERER']) && !strstr($_SERVER['HTTP_REFERER'], Tools::getHttpHost()) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs)) {
// If the previous page was a category and is a parent category of the product use this category as parent category
if (isset($regs[2]) && is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$this->category = new Category($regs[2], (int) $this->context->cookie->id_lang);
}
} else {
if (isset($regs[5]) && is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$this->category = new Category($regs[5], (int) $this->context->cookie->id_lang);
}
}
}
} else {
// Set default product category
$this->category = new Category($this->product->id_category_default, (int) $this->context->cookie->id_lang);
}
}
}
示例9: process
public function process()
{
global $cart, $currency;
parent::process();
if (!($id_product = (int) Tools::getValue('id_product')) or !Validate::isUnsignedId($id_product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (!Validate::isLoadedObject($this->product) or !$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
} else {
self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
if (!$this->product->active) {
self::$smarty->assign('adminActionDisplay', true);
}
/* rewrited url set */
$rewrited_url = self::$link->getProductLink($this->product->id, $this->product->link_rewrite);
/* Product pictures management */
require_once 'images.inc.php';
self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
if (Tools::isSubmit('submitCustomizedDatas')) {
$this->pictureUpload($this->product, $cart);
$this->textRecord($this->product, $cart);
$this->formTargetFormat();
} elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
}
$files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
$textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
foreach ($textFields as $key => $textField) {
$textFields[$key] = str_replace('<br />', "\n", $textField);
}
self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
if ((int) Tools::getValue('pp') == 1) {
echo 'here1';
}
$productPriceWithTax = Product::getPriceStatic($id_product, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
if ((int) Tools::getValue('pp') == 1) {
$time2 = time();
echo 'time2: ' . $time2;
}
$productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
$configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES'));
/* Features / Values */
$features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
$attachments = $this->product->getAttachments((int) self::$cookie->id_lang);
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
}
}
}
if (!$category) {
$category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
}
if (isset($category) and Validate::isLoadedObject($category)) {
self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
} else {
self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
}
self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
$lang = Configuration::get('PS_LANG_DEFAULT');
if (Pack::isPack((int) $this->product->id, (int) $lang) and !Pack::isInStock((int) $this->product->id, (int) $lang)) {
$this->product->quantity = 0;
}
$group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100;
$id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
if ((int) Tools::getValue('pp') == 1) {
$time3 = time();
echo 'time3: ' . $time3;
}
// Tax
$tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
self::$smarty->assign('tax_rate', $tax);
$ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
$manufacturer = new Manufacturer((int) $this->product->id_manufacturer, 1);
$sizechart = new Sizechart((int) $this->product->id_sizechart, 1);
//see if the product is already in the wishlist
if ($id_customer) {
$sql = "select id from ps_wishlist where id_customer = " . $id_customer . " and id_product = " . $this->product->id;
$res = Db::getInstance()->ExecuteS($sql);
if ($res) {
//.........这里部分代码省略.........
示例10: date_default_timezone_set
date_default_timezone_set($timezone);
}
/* Category */
$category = false;
$cookie = new Cookie('ps');
if (!defined('PS_ADMIN_DIR')) {
if (!$category && isset($_GET['id_category'])) {
$category = new Category($_GET['id_category'], intval($cookie->id_lang));
}
if (!$category && isset($_SERVER['HTTP_REFERER']) && preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (!isset($_GET['id_product']) || Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => intval($regs[2]))))) {
$category = new Category(intval($regs[2]), intval($cookie->id_lang));
}
} elseif (isset($regs[5]) and is_numeric($regs[5]) && isset($_GET['id_product'])) {
if (!isset($_GET['id_product']) || Product::idIsOnCategoryId(intval($_GET['id_product']), array('0' => array('id_category' => intval($regs[5]))))) {
$category = new Category(intval($regs[5]), intval($cookie->id_lang));
}
}
}
if (!$category && isset($_GET['id_product'])) {
$product = new Product(intval($_GET['id_product']), true, intval($cookie->id_lang));
$category_ids = array();
foreach (Product::getIndexedCategories($product->id) as $row) {
$category_ids[] = $row['id_category'];
}
$category_id = $product->id_category_default;
if (isset($cookie->last_visited_category) && in_array(intval($cookie->last_visited_category), $category_ids)) {
$category_id = intval($cookie->last_visited_category);
}
$category = new Category($category_id, intval($cookie->id_lang));
示例11: floatval
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
$productPriceWithoutEcoTax = floatval($productPriceWithTax - $product->ecotax);
$configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES'));
/* Features / Values */
$features = $product->getFrontFeatures(intval($cookie->id_lang));
$attachments = $product->getAttachments(intval($cookie->id_lang));
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[2]))))) {
$category = new Category(intval($regs[2]), intval($cookie->id_lang));
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId(intval($product->id), array('0' => array('id_category' => intval($regs[5]))))) {
$category = new Category(intval($regs[5]), intval($cookie->id_lang));
}
}
}
if (!$category) {
$category = new Category($product->id_category_default, intval($cookie->id_lang));
}
if (isset($category) and Validate::isLoadedObject($category)) {
$smarty->assign(array('category' => $category, 'subCategories' => $category->getSubCategories(intval($cookie->id_lang), true), 'id_category_current' => intval($category->id), 'id_category_parent' => intval($category->id_parent), 'return_category_name' => Tools::safeOutput(Category::hideCategoryPosition($category->name))));
}
$smarty->assign(array('return_link' => (isset($category->id) and $category->id) ? Tools::safeOutput($link->getCategoryLink($category)) : 'javascript: history.back();', 'path' => (isset($category->id) and $category->id) ? Tools::getFullPath(intval($category->id), $product->name) : Tools::getFullPath(intval($product->id_category_default), $product->name)));
$lang = Configuration::get('PS_LANG_DEFAULT');
if (Pack::isPack(intval($product->id), intval($lang)) and !Pack::isInStock(intval($product->id), intval($lang))) {
$product->quantity = 0;
}
示例12: setLastVisitedCategory
public function setLastVisitedCategory()
{
if (method_exists($this->context->controller, 'getCategory') && ($category = $this->context->controller->getCategory())) {
$this->context->cookie->last_visited_category = $category->id;
} elseif (method_exists($this->context->controller, 'getProduct') && ($product = $this->context->controller->getProduct())) {
if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($product->id, array(array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) {
$this->context->cookie->last_visited_category = (int) $product->id_category_default;
}
}
}
示例13: getblockCategTree
public function getblockCategTree()
{
// Get all groups for this customer and concatenate them as a string: "1,2,3..."
$groups = implode(', ', Customer::getGroupsStatic((int) $this->context->customer->id));
$maxdepth = Configuration::get('BLOCK_CATEG_MAX_DEPTH');
if (!($result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT DISTINCT c.id_parent, c.id_category, cl.name, cl.description, cl.link_rewrite
FROM `' . _DB_PREFIX_ . 'category` c
INNER JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (c.`id_category` = cl.`id_category` AND cl.`id_lang` = ' . (int) $this->context->language->id . Shop::addSqlRestrictionOnLang('cl') . ')
INNER JOIN `' . _DB_PREFIX_ . 'category_shop` cs ON (cs.`id_category` = c.`id_category` AND cs.`id_shop` = ' . (int) $this->context->shop->id . ')
WHERE (c.`active` = 1 OR c.`id_category` = ' . (int) Configuration::get('PS_HOME_CATEGORY') . ')
AND c.`id_category` != ' . (int) Configuration::get('PS_ROOT_CATEGORY') . '
' . ((int) $maxdepth != 0 ? ' AND `level_depth` <= ' . (int) $maxdepth : '') . '
AND c.id_category IN (SELECT id_category FROM `' . _DB_PREFIX_ . 'category_group` WHERE `id_group` IN (' . pSQL($groups) . '))
ORDER BY `level_depth` ASC, ' . (Configuration::get('BLOCK_CATEG_SORT') ? 'cl.`name`' : 'cs.`position`') . ' ' . (Configuration::get('BLOCK_CATEG_SORT_WAY') ? 'DESC' : 'ASC')))) {
return;
}
$resultParents = array();
$resultIds = array();
foreach ($result as &$row) {
$resultParents[$row['id_parent']][] =& $row;
$resultIds[$row['id_category']] =& $row;
}
$blockCategTree = $this->getTree($resultParents, $resultIds, Configuration::get('BLOCK_CATEG_MAX_DEPTH'));
unset($resultParents, $resultIds);
$id_category = (int) Tools::getValue('id_category');
$id_product = (int) Tools::getValue('id_product');
if (Tools::isSubmit('id_category')) {
$this->context->cookie->last_visited_category = $id_category;
$this->smarty->assign('currentCategoryId', $this->context->cookie->last_visited_category);
}
if (Tools::isSubmit('id_product')) {
if (!isset($this->context->cookie->last_visited_category) || !Product::idIsOnCategoryId($id_product, array('0' => array('id_category' => $this->context->cookie->last_visited_category))) || !Category::inShopStatic($this->context->cookie->last_visited_category, $this->context->shop)) {
$product = new Product($id_product);
if (isset($product) && Validate::isLoadedObject($product)) {
$this->context->cookie->last_visited_category = (int) $product->id_category_default;
}
}
$this->smarty->assign('currentCategoryId', (int) $this->context->cookie->last_visited_category);
}
return $blockCategTree;
}
示例14: _getCategoryId
private function _getCategoryId($id_lang)
{
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->_getId(), array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], $id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->_getId(), array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], $id_lang);
}
}
}
if ($category) {
return $category->id;
}
}
示例15: getValue
/**
* Return discount value
*
* @param integer $nb_discounts Number of discount currently in cart
* @param boolean $order_total_products Total cart products amount
* @return mixed Return a float value or '!' if reduction is 'Shipping free'
*/
function getValue($nb_discounts = 0, $order_total_products = 0, $shipping_fees = 0, $idCart = false, $useTax = true)
{
$totalAmount = 0;
if (!$this->cumulable and intval($nb_discounts) > 1) {
return 0;
}
if (!$this->active) {
return 0;
}
if (!$this->quantity) {
return 0;
}
$date_start = strtotime($this->date_from);
$date_end = strtotime($this->date_to);
if (time() < $date_start or time() > $date_end) {
return 0;
}
$cart = new Cart(intval($idCart));
$products = $cart->getProducts();
$categories = Discount::getCategories(intval($this->id));
$in_category = false;
foreach ($products as $product) {
if (count($categories)) {
if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
$totalAmount += $useTax ? $product['total_wt'] : $product['total'];
}
}
}
$totalAmount += floatval($shipping_fees);
if ($this->minimal > 0 and $totalAmount < $this->minimal) {
return 0;
}
switch ($this->id_discount_type) {
case 1:
// % on order
$amount = 0;
$percentage = $this->value / 100;
foreach ($products as $product) {
if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
$amount += ($useTax ? $product['total_wt'] : $product['total']) * $percentage;
}
}
return $amount;
case 2:
// amount
foreach ($products as $product) {
if (Product::idIsOnCategoryId($product['id_product'], $categories)) {
$in_category = true;
break;
}
}
return $in_category ? $this->value : 0;
case 3:
// Shipping is free
return '!';
}
return 0;
}