本文整理汇总了PHP中StockAvailable::addSqlShopRestriction方法的典型用法代码示例。如果您正苦于以下问题:PHP StockAvailable::addSqlShopRestriction方法的具体用法?PHP StockAvailable::addSqlShopRestriction怎么用?PHP StockAvailable::addSqlShopRestriction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StockAvailable
的用法示例。
在下文中一共展示了StockAvailable::addSqlShopRestriction方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct()
{
$this->bootstrap = true;
$this->table = 'product';
$this->className = 'Product';
$this->lang = true;
$this->explicitSelect = true;
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'icon' => 'icon-trash', 'confirm' => $this->l('Delete selected items?')));
if (!Tools::getValue('id_product')) {
$this->multishop_context_group = false;
}
parent::__construct();
$this->imageType = 'jpg';
$this->_defaultOrderBy = 'position';
$this->max_file_size = (int) (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
$this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
$this->allow_export = true;
// @since 1.5 : translations for tabs
$this->available_tabs_lang = array('Informations' => $this->l('Information'), 'Pack' => $this->l('Pack'), 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), 'Associations' => $this->l('Associations'), 'Shipping' => $this->l('Shipping'), 'Combinations' => $this->l('Combinations'), 'Features' => $this->l('Features'), 'Customization' => $this->l('Customization'), 'Attachments' => $this->l('Attachments'), 'Quantities' => $this->l('Quantities'), 'Suppliers' => $this->l('Suppliers'), 'Warehouses' => $this->l('Warehouses'));
$this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
$this->available_tabs = array_merge($this->available_tabs, array('Informations' => 0, 'Pack' => 7, 'VirtualProduct' => 8, 'Prices' => 1, 'Seo' => 2, 'Associations' => 3, 'Images' => 9, 'Shipping' => 4, 'Combinations' => 5, 'Features' => 10, 'Customization' => 11, 'Attachments' => 12, 'Suppliers' => 13));
}
// Sort the tabs that need to be preloaded by their priority number
asort($this->available_tabs, SORT_NUMERIC);
/* Adding tab if modules are hooked */
$modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
if (is_array($modules_list) && count($modules_list) > 0) {
foreach ($modules_list as $m) {
$this->available_tabs['Module' . ucfirst($m['module'])] = 23;
$this->available_tabs_lang['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']);
}
}
if (Tools::getValue('reset_filter_category')) {
$this->context->cookie->id_category_products_filter = false;
}
if (Shop::isFeatureActive() && $this->context->cookie->id_category_products_filter) {
$category = new Category((int) $this->context->cookie->id_category_products_filter);
if (!$category->inShop()) {
$this->context->cookie->id_category_products_filter = false;
Tools::redirectAdmin($this->context->link->getAdminLink('AdminProducts'));
}
}
/* Join categories table */
if ($id_category = (int) Tools::getValue('productFilter_cl!name')) {
$this->_category = new Category((int) $id_category);
$_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
} else {
if ($id_category = (int) Tools::getValue('id_category')) {
$this->id_current_category = $id_category;
$this->context->cookie->id_category_products_filter = $id_category;
} elseif ($id_category = $this->context->cookie->id_category_products_filter) {
$this->id_current_category = $id_category;
}
if ($this->id_current_category) {
$this->_category = new Category((int) $this->id_current_category);
} else {
$this->_category = new Category();
}
}
$join_category = false;
if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) {
$join_category = true;
}
$this->_join .= '
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = a.`id_product`)
LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ') ';
$alias = 'sa';
$alias_image = 'image_shop';
$id_shop = Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP ? (int) $this->context->shop->id : 'a.id_shop_default';
$this->_join .= ' JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = ' . $id_shop . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = ' . $id_shop . ')
LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = ' . $id_shop . ')
LEFT JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (image_shop.`id_image` = i.`id_image` AND image_shop.`cover` = 1 AND image_shop.id_shop = ' . $id_shop . ')
LEFT JOIN `' . _DB_PREFIX_ . 'product_download` pd ON (pd.`id_product` = a.`id_product`)';
$this->_select .= 'shop.name as shopname, a.id_shop_default, ';
$this->_select .= 'MAX(' . $alias_image . '.id_image) id_image, cl.name `name_category`, ' . $alias . '.`price`, 0 AS price_final, a.`is_virtual`, pd.`nb_downloadable`, sav.`quantity` as sav_quantity, ' . $alias . '.`active`, IF(sav.`quantity`<=0, 1, 0) badge_danger';
if ($join_category) {
$this->_join .= ' INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = ' . (int) $this->_category->id . ') ';
$this->_select .= ' , cp.`position`, ';
}
$this->_group = 'GROUP BY ' . $alias . '.id_product';
$this->fields_list = array();
$this->fields_list['id_product'] = array('title' => $this->l('ID'), 'align' => 'center', 'class' => 'fixed-width-xs', 'type' => 'int');
$this->fields_list['image'] = array('title' => $this->l('Image'), 'align' => 'center', 'image' => 'p', 'orderby' => false, 'filter' => false, 'search' => false);
$this->fields_list['name'] = array('title' => $this->l('Name'), 'filter_key' => 'b!name');
$this->fields_list['reference'] = array('title' => $this->l('Reference'), 'align' => 'left');
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
$this->fields_list['shopname'] = array('title' => $this->l('Default shop'), 'filter_key' => 'shop!name');
} else {
$this->fields_list['name_category'] = array('title' => $this->l('Category'), 'filter_key' => 'cl!name');
}
$this->fields_list['price'] = array('title' => $this->l('Base price'), 'type' => 'price', 'align' => 'text-right', 'filter_key' => 'a!price');
$this->fields_list['price_final'] = array('title' => $this->l('Final price'), 'type' => 'price', 'align' => 'text-right', 'havingFilter' => true, 'orderby' => false, 'search' => false);
if (Configuration::get('PS_STOCK_MANAGEMENT')) {
$this->fields_list['sav_quantity'] = array('title' => $this->l('Quantity'), 'type' => 'int', 'align' => 'text-right', 'filter_key' => 'sav!quantity', 'orderby' => true, 'badge_danger' => true);
}
$this->fields_list['active'] = array('title' => $this->l('Status'), 'active' => 'status', 'filter_key' => $alias . '!active', 'align' => 'text-center', 'type' => 'bool', 'class' => 'fixed-width-sm', 'orderby' => false);
if ($join_category && (int) $this->id_current_category) {
//.........这里部分代码省略.........
示例2: outOfStock
/**
* For a given product, get its "out of stock" flag
*
* @param int $id_product
* @param int $id_shop Optional : gets context if null @see Context::getContext()
* @return bool : depends on stock @see $depends_on_stock
*/
public static function outOfStock($id_product, $id_shop = null)
{
if (!Validate::isUnsignedId($id_product)) {
return false;
}
$query = new DbQuery();
$query->select('out_of_stock');
$query->from('stock_available');
$query->where('id_product = ' . (int) $id_product);
$query->where('id_product_attribute = 0');
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
示例3: isColorUnavailable
public function isColorUnavailable($id_attribute, $id_shop)
{
return Db::getInstance()->getValue('
SELECT sa.id_product_attribute
FROM ' . _DB_PREFIX_ . 'stock_available sa
WHERE id_product=' . (int) $this->id . ' AND quantity <= 0
' . StockAvailable::addSqlShopRestriction(null, $id_shop, 'sa') . '
AND EXISTS (
SELECT 1
FROM ' . _DB_PREFIX_ . 'product_attribute pa
JOIN ' . _DB_PREFIX_ . 'product_attribute_shop product_attribute_shop
ON (product_attribute_shop.id_product_attribute = pa.id_product_attribute AND product_attribute_shop.id_shop=' . (int) $id_shop . ')
JOIN ' . _DB_PREFIX_ . 'product_attribute_combination pac
ON (pac.id_product_attribute AND product_attribute_shop.id_product_attribute)
WHERE sa.id_product_attribute = pa.id_product_attribute AND pa.id_product=' . (int) $this->id . ' AND pac.id_attribute=' . (int) $id_attribute . '
)');
}
示例4: sqlStock
/**
* Create JOIN query with 'stock_available' table
*
* @param string $productAlias Alias of product table
* @param string|int $productAttribute If string : alias of PA table ; if int : value of PA ; if null : nothing about PA
* @param bool $innerJoin LEFT JOIN or INNER JOIN
* @param Shop $shop
* @return string
*/
public static function sqlStock($product_alias, $product_attribute = 0, $inner_join = false, Shop $shop = null)
{
$id_shop = $shop !== null ? (int) $shop->id : null;
$sql = ($inner_join ? ' INNER ' : ' LEFT ') . '
JOIN ' . _DB_PREFIX_ . 'stock_available stock
ON (stock.id_product = ' . pSQL($product_alias) . '.id_product';
if (!is_null($product_attribute)) {
if (!Combination::isFeatureActive()) {
$sql .= ' AND stock.id_product_attribute = 0';
} elseif (is_numeric($product_attribute)) {
$sql .= ' AND stock.id_product_attribute = ' . $product_attribute;
} elseif (is_string($product_attribute)) {
$sql .= ' AND stock.id_product_attribute = IFNULL(`' . bqSQL($product_attribute) . '`.id_product_attribute, 0)';
}
}
$sql .= StockAvailable::addSqlShopRestriction(null, $id_shop, 'stock') . ' )';
return $sql;
}
示例5: getFilterBlock
public function getFilterBlock($selected_filters = array())
{
global $cookie;
static $cache = null;
$context = Context::getContext();
$id_lang = $context->language->id;
$currency = $context->currency;
$id_shop = (int) $context->shop->id;
$alias = 'product_shop';
if (is_array($cache)) {
return $cache;
}
$home_category = Configuration::get('PS_HOME_CATEGORY');
$id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', $home_category));
if ($id_parent == $home_category) {
return;
}
$parent = new Category((int) $id_parent, $id_lang);
/* Get the filters for the current category */
$filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT type, id_value, filter_show_limit, filter_type FROM ' . _DB_PREFIX_ . 'layered_category
WHERE id_category = ' . (int) $id_parent . '
AND id_shop = ' . $id_shop . '
GROUP BY `type`, id_value ORDER BY position ASC');
/* Create the table which contains all the id_product in a cat or a tree */
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('DROP TEMPORARY TABLE IF EXISTS ' . _DB_PREFIX_ . 'cat_restriction', false);
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('CREATE TEMPORARY TABLE ' . _DB_PREFIX_ . 'cat_restriction ENGINE=MEMORY
SELECT DISTINCT cp.id_product, p.id_manufacturer, product_shop.condition, p.weight FROM ' . _DB_PREFIX_ . 'category_product cp
INNER JOIN ' . _DB_PREFIX_ . 'category c ON (c.id_category = cp.id_category AND
' . (Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= ' . (int) $parent->nleft . '
AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
AND c.active = 1)
INNER JOIN ' . _DB_PREFIX_ . 'product_shop product_shop ON (product_shop.id_product = cp.id_product
AND product_shop.id_shop = ' . (int) $context->shop->id . ')
INNER JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product=cp.id_product)
WHERE product_shop.`active` = 1 AND product_shop.`visibility` IN ("both", "catalog")', false);
Db::getInstance(_PS_USE_SQL_SLAVE_)->execute('ALTER TABLE ' . _DB_PREFIX_ . 'cat_restriction ADD PRIMARY KEY (id_product),
ADD KEY `id_manufacturer` (`id_manufacturer`,`id_product`) USING BTREE,
ADD KEY `condition` (`condition`,`id_product`) USING BTREE,
ADD KEY `weight` (`weight`,`id_product`) USING BTREE', false);
// Remove all empty selected filters
foreach ($selected_filters as $key => $value) {
switch ($key) {
case 'price':
case 'weight':
if ($value[0] === '' && $value[1] === '') {
unset($selected_filters[$key]);
}
break;
default:
if ($value == '') {
unset($selected_filters[$key]);
}
break;
}
}
$filter_blocks = array();
foreach ($filters as $filter) {
$sql_query = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '', 'second_query' => '');
switch ($filter['type']) {
case 'price':
$sql_query['select'] = 'SELECT p.`id_product`, psi.price_min, psi.price_max ';
// price slider is not filter dependent
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['join'] = 'INNER JOIN `' . _DB_PREFIX_ . 'layered_price_index` psi
ON (psi.id_product = p.id_product AND psi.id_currency = ' . (int) $context->currency->id . ' AND psi.id_shop=' . (int) $context->shop->id . ')';
$sql_query['where'] = 'WHERE 1';
break;
case 'weight':
$sql_query['select'] = 'SELECT p.`id_product`, p.`weight` ';
// price slider is not filter dependent
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['where'] = 'WHERE 1';
break;
case 'condition':
$sql_query['select'] = 'SELECT p.`id_product`, product_shop.`condition` ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['where'] = 'WHERE 1';
$sql_query['from'] .= Shop::addSqlAssociation('product', 'p');
break;
case 'quantity':
$sql_query['select'] = 'SELECT p.`id_product`, sa.`quantity`, sa.`out_of_stock` ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['join'] .= 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa
ON (sa.id_product = p.id_product AND sa.id_product_attribute=0 ' . StockAvailable::addSqlShopRestriction(null, null, 'sa') . ') ';
$sql_query['where'] = 'WHERE 1';
break;
case 'manufacturer':
$sql_query['select'] = 'SELECT COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer, m.name ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p
INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) ';
$sql_query['where'] = 'WHERE 1';
$sql_query['group'] = ' GROUP BY p.id_manufacturer ORDER BY m.name';
if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) {
$sql_query['second_query'] = '
//.........这里部分代码省略.........
示例6: getWsStockAvailables
public function getWsStockAvailables()
{
return Db::getInstance()->executeS('SELECT `id_stock_available` id, `id_product_attribute`
FROM `' . _DB_PREFIX_ . 'stock_available`
WHERE `id_product`=' . $this->id . StockAvailable::addSqlShopRestriction());
}
示例7: getProductsByCategory
public function getProductsByCategory($id_category, $count = false, $orderBy = '', $orderWay = '', $filter = '', $start = '', $pagination = '')
{
if ($orderBy && $orderWay) {
$_GET['productsListOrderby'] = pSQL($orderBy);
$_GET['productsListOrderway'] = pSQL($orderWay);
} else {
$orderBy = 'id_product';
$orderWay = 'ASC';
}
$filtering = '';
$filter_array = array();
if ($filter) {
$filtering = 'HAVING';
foreach ($filter as $row => $item) {
if ($filtering == 'HAVING') {
$filtering .= ' `' . pSQL($row) . '` LIKE \'%' . pSQL($item) . '%\'';
} else {
$filtering .= ' AND `' . pSQL($row) . '` LIKE \'%' . pSQL($item) . '%\'';
}
$this->context->cookie->__set('productsListFilter_' . pSQL($row), pSQL($item));
array_push($filter_array, pSQL($row));
}
}
if (!$count && (!$orderBy && !$orderWay)) {
$keys_array = array('id_product', 'reference', 'price', 'category', 'quantity', 'active', 'name', 'final_price');
foreach ($keys_array as $key => $value) {
if ($this->context->cookie->__isset('productsListFilter_' . $value) && !in_array($value, $filter_array)) {
$this->context->cookie->__unset('productsListFilter_' . $value);
}
}
}
$id_shop = $this->context->shop->id;
if (version_compare(_PS_VERSION_, '1.5', '<')) {
$products = DB::getInstance()->executeS("\n\t\t\t\tSELECT\n\t\t\t\t\tp.`id_product` \t\tAS `id_product`,\n\t\t\t\t\tIFNULL((SELECT SUM(`at`.`quantity`) FROM `ps_product_attribute` `at` WHERE `at`.`id_product` = `cp`.`id_product`), p.`quantity`) AS `quantity`,\n\t\t\t\t\tp.`reference` \t\tAS `reference`,\n\t\t\t\t\tp.`price` \t\t\tAS `price`,\n\t\t\t\t\tcl.`name` \t\t\tAS `category`,\n\t\t\t\t\tp.`active` \t\t\tAS `active`,\n\t\t\t\t\tpl.`name` \t\t\tAS `name`,\n\t\t\t\t\tpl.`link_rewrite` \tAS `link_rewrite`,\n\t\t\t\t\ti.`id_image` \t\tAS `id_image`,\n\t\t\t\t\tp.`price` \t\t\tAS `final_price`\n\t\t\t\tFROM `" . _DB_PREFIX_ . "category_product` cp\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "product` p ON (p.`id_product` = cp.`id_product`)\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "image` i ON (i.`id_product` = cp.`id_product` AND i.`cover` = '1')\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "category_lang` cl ON (cl.`id_category` = cp.`id_category` AND cl.`id_lang` = '" . (int) $this->context->language->id . "')\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "product_lang` pl ON (pl.`id_product` = cp.`id_product` AND pl.`id_lang` = '" . (int) $this->context->language->id . "')\n\n\t\t\t\tWHERE cp.`id_category` = '" . (int) $id_category . "' " . pSQL($filtering) . "\n ORDER BY `" . pSQL($orderBy) . "` " . pSQL($orderWay) . ($start && $pagination ? " LIMIT " . (int) $start . ", " . (int) $pagination : ''));
} else {
$products = DB::getInstance()->executeS("\n\t\t\t\tSELECT\n\t\t\t\t\tp.`id_product` \t\tAS `id_product`,\n\t\t\t\t\tp.`reference` \t\tAS `reference`,\n\t\t\t\t\tp.`price` \t\t\tAS `price`,\n\t\t\t\t\tpsh.`id_shop` \tAS `id_shop`,\n\t\t\t\t\tcl.`name` \t\t\tAS `category`,\n\t\t\t\t\tsav.`quantity` \t\tAS `quantity`,\n\t\t\t\t\tp.`active` \t\t\tAS `active`,\n\t\t\t\t\tpl.`name` \t\t\tAS `name`,\n\t\t\t\t\tpl.`link_rewrite` \tAS `link_rewrite`,\n\t\t\t\t\ti.`id_image` \t\tAS `id_image`,\n\t\t\t\t\tp.`price` \t\t\tAS `final_price`\n\t\t\t\tFROM `" . _DB_PREFIX_ . "category_product` cp\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "product` p ON (p.`id_product` = cp.`id_product`)\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "product_shop` psh ON (psh.`id_product` = p.`id_product`)\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "image` i ON (i.`id_product` = cp.`id_product` AND i.`cover` = '1')\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "category_lang` cl ON (cl.`id_category` = cp.`id_category` AND cl.`id_lang` = '" . (int) $this->context->language->id . "' AND cl.`id_shop` = '" . (int) $this->context->shop->id . "')\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "product_lang` pl ON (pl.`id_product` = cp.`id_product` AND pl.`id_lang` = '" . (int) $this->context->language->id . "' AND pl.`id_shop` = '" . (int) $this->context->shop->id . "')\n\t\t\t\tLEFT JOIN `" . _DB_PREFIX_ . "stock_available` sav ON (sav.`id_product` = cp.`id_product` AND sav.`id_product_attribute` = 0 " . StockAvailable::addSqlShopRestriction(null, null, "sav") . ")\n\t\t\t\tWHERE cp.`id_category` = '" . (int) $id_category . "' " . pSQL($filtering) . " AND psh.`id_shop` = " . (int) $id_shop . "\n\t\t\t\tORDER BY `" . pSQL($orderBy) . "` " . pSQL($orderWay) . ($start && $pagination ? " LIMIT " . (int) $start . ", " . (int) $pagination : ''));
}
if (!$products) {
$products = array();
}
foreach ($products as $row => &$product) {
$product['price'] = Tools::displayPrice($product['price']);
$product['image'] = $this->getImage($product['id_product'], $product['id_image'], $product['link_rewrite']);
$product['final_price'] = Tools::displayPrice(Product::getPriceStatic($product['id_product'], true, null, 2, null, false, true, 1, true));
}
return $products;
}
示例8: getFilterBlock
public function getFilterBlock($selected_filters = array(), $compute_range_filters = true)
{
global $cookie;
// Remove all empty selected filters
foreach ($selected_filters as $key => $value) {
switch ($key) {
case 'price':
case 'weight':
if ($value[0] === '' && $value[1] === '') {
unset($selected_filters[$key]);
}
break;
default:
if ($value == '' || $value == array()) {
unset($selected_filters[$key]);
}
break;
}
}
static $latest_selected_filters = null;
static $latest_cat_restriction = null;
static $productCache = array();
$context = Context::getContext();
$id_lang = $context->language->id;
$currency = $context->currency;
$id_shop = (int) $context->shop->id;
$alias = 'product_shop';
$id_parent = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', Configuration::get('PS_HOME_CATEGORY')));
$parent = new Category((int) $id_parent, $id_lang);
/* Get the filters for the current category */
$filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT type, id_value, filter_show_limit, filter_type FROM ' . _DB_PREFIX_ . 'layered_category
WHERE id_category = ' . (int) $id_parent . '
AND id_shop = ' . $id_shop . '
GROUP BY `type`, id_value ORDER BY position ASC');
/* Create the table which contains all the id_product in a cat or a tree */
$current_cat_restriction = 'parent_' . ($this->ps_layered_full_tree ? (int) $parent->nleft . '_' . (int) $parent->nright : (int) $id_parent . '_context_' . (int) $context->shop->id);
if ($current_cat_restriction != $latest_cat_restriction) {
Db::getInstance()->execute('DROP TEMPORARY TABLE IF EXISTS ' . _DB_PREFIX_ . 'cat_restriction', false);
Db::getInstance()->execute('CREATE TEMPORARY TABLE ' . _DB_PREFIX_ . 'cat_restriction ENGINE=MEMORY
SELECT DISTINCT cp.id_product, p.id_manufacturer, product_shop.condition, p.weight FROM ' . _DB_PREFIX_ . 'category c
STRAIGHT_JOIN ' . _DB_PREFIX_ . 'category_product cp ON (c.id_category = cp.id_category AND
' . ($this->ps_layered_full_tree ? 'c.nleft >= ' . (int) $parent->nleft . '
AND c.nright <= ' . (int) $parent->nright : 'c.id_category = ' . (int) $id_parent) . '
AND c.active = 1)
STRAIGHT_JOIN ' . _DB_PREFIX_ . 'product_shop product_shop ON (product_shop.id_product = cp.id_product
AND product_shop.id_shop = ' . (int) $context->shop->id . ')
STRAIGHT_JOIN ' . _DB_PREFIX_ . 'product p ON (p.id_product=cp.id_product)
WHERE product_shop.`active` = 1 AND product_shop.`visibility` IN ("both", "catalog")', false);
Db::getInstance()->execute('ALTER TABLE ' . _DB_PREFIX_ . 'cat_restriction ADD PRIMARY KEY (id_product),
ADD KEY `id_manufacturer` (`id_manufacturer`,`id_product`) USING BTREE,
ADD KEY `condition` (`condition`,`id_product`) USING BTREE,
ADD KEY `weight` (`weight`,`id_product`) USING BTREE', false);
$latest_cat_restriction = $current_cat_restriction;
}
$filter_blocks = array();
foreach ($filters as $filter) {
$cacheKey = $filter['type'] . '-' . $filter['id_value'];
if ($current_cat_restriction == $latest_cat_restriction && $latest_selected_filters == $selected_filters && isset($productCache[$cacheKey])) {
$products = $productCache[$cacheKey];
} else {
$sql_query = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '');
switch ($filter['type']) {
case 'price':
$sql_query['select'] = 'SELECT p.`id_product`, psi.price_min, psi.price_max ';
// price slider is not filter dependent
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['join'] = 'INNER JOIN `' . _DB_PREFIX_ . 'layered_price_index` psi
ON (psi.id_product = p.id_product AND psi.id_currency = ' . (int) $context->currency->id . ' AND psi.id_shop=' . (int) $context->shop->id . ')';
$sql_query['where'] = 'WHERE 1';
break;
case 'weight':
$sql_query['select'] = 'SELECT p.`id_product`, p.`weight` ';
// price slider is not filter dependent
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['where'] = 'WHERE 1';
break;
case 'condition':
$sql_query['select'] = 'SELECT DISTINCT p.`id_product`, product_shop.`condition` ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['where'] = 'WHERE 1';
$sql_query['from'] .= Shop::addSqlAssociation('product', 'p');
break;
case 'quantity':
$sql_query['select'] = 'SELECT DISTINCT p.`id_product`, sa.`quantity`, sa.`out_of_stock` ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p';
$sql_query['join'] .= 'LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sa
ON (sa.id_product = p.id_product AND sa.id_product_attribute=0 ' . StockAvailable::addSqlShopRestriction(null, null, 'sa') . ') ';
$sql_query['where'] = 'WHERE 1';
break;
case 'manufacturer':
$sql_query['select'] = 'SELECT COUNT(DISTINCT p.id_product) nbr, m.id_manufacturer, m.name ';
$sql_query['from'] = '
FROM ' . _DB_PREFIX_ . 'cat_restriction p
INNER JOIN ' . _DB_PREFIX_ . 'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) ';
$sql_query['where'] = 'WHERE 1';
//.........这里部分代码省略.........
示例9: __construct
public function __construct()
{
$this->table = 'product';
$this->className = 'Product';
$this->lang = true;
$this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
if (!Tools::getValue('id_product')) {
$this->multishop_context_group = false;
}
parent::__construct();
$this->imageType = 'jpg';
$this->_defaultOrderBy = 'position';
$this->max_file_size = (int) (Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1000000);
$this->max_image_size = (int) Configuration::get('PS_PRODUCT_PICTURE_MAX_SIZE');
$this->fields_list = array();
$this->fields_list['id_product'] = array('title' => $this->l('ID'), 'align' => 'center', 'width' => 20);
$this->fields_list['image'] = array('title' => $this->l('Photo'), 'align' => 'center', 'image' => 'p', 'width' => 70, 'orderby' => false, 'filter' => false, 'search' => false);
$this->fields_list['name'] = array('title' => $this->l('Name'), 'filter_key' => 'b!name');
$this->fields_list['reference'] = array('title' => $this->l('Reference'), 'align' => 'left', 'width' => 80);
if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_SHOP) {
$this->fields_list['shopname'] = array('title' => $this->l('Default Shop'), 'width' => 230, 'filter_key' => 'shop!name');
} else {
$this->fields_list['name_category'] = array('title' => $this->l('Category'), 'width' => 230, 'filter_key' => 'cl!name');
}
$this->fields_list['price'] = array('title' => $this->l('Base price'), 'width' => 90, 'type' => 'price', 'align' => 'right', 'filter_key' => 'a!price');
$this->fields_list['price_final'] = array('title' => $this->l('Final price'), 'width' => 90, 'type' => 'price', 'align' => 'right', 'havingFilter' => true, 'orderby' => false);
$this->fields_list['sav_quantity'] = array('title' => $this->l('Quantity'), 'width' => 90, 'align' => 'right', 'filter_key' => 'sav!quantity', 'orderby' => true, 'hint' => $this->l('This is the quantity available in the current shop/group'));
$this->fields_list['active'] = array('title' => $this->l('Displayed'), 'width' => 70, 'active' => 'status', 'filter_key' => 'sa!active', 'align' => 'center', 'type' => 'bool', 'orderby' => false);
if ((int) Tools::getValue('id_category')) {
$this->fields_list['position'] = array('title' => $this->l('Position'), 'width' => 70, 'filter_key' => 'cp!position', 'align' => 'center', 'position' => 'position');
}
// @since 1.5 : translations for tabs
$this->available_tabs_lang = array('Informations' => $this->l('Information'), 'Pack' => $this->l('Pack'), 'VirtualProduct' => $this->l('Virtual Product'), 'Prices' => $this->l('Prices'), 'Seo' => $this->l('SEO'), 'Images' => $this->l('Images'), 'Associations' => $this->l('Associations'), 'Shipping' => $this->l('Shipping'), 'Combinations' => $this->l('Combinations'), 'Features' => $this->l('Features'), 'Customization' => $this->l('Customization'), 'Attachments' => $this->l('Attachments'), 'Quantities' => $this->l('Quantities'), 'Suppliers' => $this->l('Suppliers'), 'Warehouses' => $this->l('Warehouses'));
$this->available_tabs = array('Quantities' => 6, 'Warehouses' => 14);
if ($this->context->shop->getContext() != Shop::CONTEXT_GROUP) {
$this->available_tabs = array_merge($this->available_tabs, array('Informations' => 0, 'Pack' => 7, 'VirtualProduct' => 8, 'Prices' => 1, 'Seo' => 2, 'Associations' => 3, 'Images' => 9, 'Shipping' => 4, 'Combinations' => 5, 'Features' => 10, 'Customization' => 11, 'Attachments' => 12, 'Suppliers' => 13));
}
// Sort the tabs that need to be preloaded by their priority number
asort($this->available_tabs, SORT_NUMERIC);
/* Adding tab if modules are hooked */
$modules_list = Hook::getHookModuleExecList('displayAdminProductsExtra');
if (is_array($modules_list) && count($modules_list) > 0) {
foreach ($modules_list as $m) {
$this->available_tabs['Module' . ucfirst($m['module'])] = 23;
$this->available_tabs_lang['Module' . ucfirst($m['module'])] = Module::getModuleName($m['module']);
}
}
/* Join categories table */
if ($id_category = (int) Tools::getValue('productFilter_cl!name')) {
$this->_category = new Category((int) $id_category);
$_POST['productFilter_cl!name'] = $this->_category->name[$this->context->language->id];
} elseif ($id_category = Tools::getvalue('id_category')) {
$this->_category = new Category((int) $id_category);
} else {
$this->_category = new Category();
}
$join_category = false;
if (Validate::isLoadedObject($this->_category) && empty($this->_filter)) {
$join_category = true;
}
if (Shop::isFeatureActive()) {
$alias = 'sa';
if (Shop::getContext() == Shop::CONTEXT_SHOP) {
$this->_join .= ' JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = ' . (int) $this->context->shop->id . ')
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = ' . (int) $this->context->shop->id . ')
LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = ' . (int) $this->context->shop->id . ') ';
} else {
$this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_shop` sa ON (a.`id_product` = sa.`id_product` AND sa.id_shop = a.id_shop_default)
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = a.id_shop_default)
LEFT JOIN `' . _DB_PREFIX_ . 'shop` shop ON (shop.id_shop = a.id_shop_default) ';
}
$this->_select .= 'shop.name as shopname, ';
} else {
$alias = 'a';
$this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl ON (' . $alias . '.`id_category_default` = cl.`id_category` AND b.`id_lang` = cl.`id_lang` AND cl.id_shop = 1)';
}
$this->_join .= '
LEFT JOIN `' . _DB_PREFIX_ . 'image` i ON (i.`id_product` = a.`id_product` AND i.`cover` = 1)
' . ($join_category ? 'INNER JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = ' . (int) $this->_category->id . ')' : '') . '
LEFT JOIN `' . _DB_PREFIX_ . 'tax_rule` tr ON (' . $alias . '.`id_tax_rules_group` = tr.`id_tax_rules_group` AND tr.`id_country` = ' . (int) $this->context->country->id . ' AND tr.`id_state` = 0)
LEFT JOIN `' . _DB_PREFIX_ . 'tax` t ON (t.`id_tax` = tr.`id_tax`)
LEFT JOIN `' . _DB_PREFIX_ . 'stock_available` sav ON (sav.`id_product` = a.`id_product` AND sav.`id_product_attribute` = 0
' . StockAvailable::addSqlShopRestriction(null, null, 'sav') . ') ';
$this->_select .= 'cl.name `name_category` ' . ($join_category ? ', cp.`position`' : '') . ', i.`id_image`, ' . $alias . '.`price`, (' . $alias . '.`price` * ((100 + (t.`rate`))/100)) AS price_final, sav.`quantity` as sav_quantity, ' . $alias . '.`active`';
}
示例10: synchronize
/**
* For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity
*
* @param int $product_id
* @param int $order_shop_id
* @return bool
*/
public static function synchronize($product_id, $order_shop_id = null)
{
if (!JeproshopTools::isUnsignedInt($product_id)) {
return false;
}
$db = JFactory::getDBO();
// gets warehouse ids grouped by shops
$warehouse_ids = JeproshopWarehouseModelWarehouse::getWarehousesGroupedByShops();
if ($order_shop_id !== null) {
$order_warehouses = array();
$warehouses = JeproshopWarehouseModelWarehouse::getWarehouses(false, (int) $order_shop_id);
foreach ($warehouses as $warehouse) {
$order_warehouses[] = $warehouse->warehouse_id;
}
}
// gets all product attributes ids
$product_attribute_ids = array();
foreach (JeproshopProductModelProduct::getProductAttributesIds($product_id) as $product_attribute_id) {
$product_attribute_ids[] = $product_attribute_id->product_attribute_id;
}
// Allow to order the product when out of stock?
$out_of_stock = JeproshopStockAvailableModelStockAvailable::outOfStock($product_id);
$manager = JeproshopStockManagerFactory::getManager();
// loops on $ids_warehouse to synchronize quantities
foreach ($warehouse_ids as $shop_id => $warehouses) {
// first, checks if the product depends on stock for the given shop $id_shop
if (JeproshopStockAvailableModelStockAvailable::dependsOnStock($product_id, $shop_id)) {
// init quantity
$product_quantity = 0;
// if it's a simple product
if (empty($product_attribute_ids)) {
$allowed_warehouse_for_product = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, 0, (int) $shop_id);
$allowed_warehouse_for_product_clean = array();
foreach ($allowed_warehouse_for_product as $warehouse) {
$allowed_warehouse_for_product_clean[] = (int) $warehouse->warehouse_id;
}
$allowed_warehouse_for_product_clean = array_intersect($allowed_warehouse_for_product_clean, $warehouses);
if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_product_clean, $order_warehouses))) {
continue;
}
$product_quantity = $manager->getProductRealQuantities($product_id, null, $allowed_warehouse_for_product_clean, true);
/*Hook::exec('actionUpdateQuantity',
array(
'id_product' => $id_product,
'id_product_attribute' => 0,
'quantity' => $product_quantity
)
);*/
} else {
// else this product has attributes, hence loops on $ids_product_attribute
foreach ($product_attribute_ids as $product_attribute_id) {
$allowed_warehouse_for_combination = JeproshopWarehouseModelWarehouse::getProductWarehouseList((int) $product_id, (int) $product_attribute_id, (int) $shop_id);
$allowed_warehouse_for_combination_clean = array();
foreach ($allowed_warehouse_for_combination as $warehouse) {
$allowed_warehouse_for_combination_clean[] = (int) $warehouse->warehouse_id;
}
$allowed_warehouse_for_combination_clean = array_intersect($allowed_warehouse_for_combination_clean, $warehouses);
if ($order_shop_id != null && !count(array_intersect($allowed_warehouse_for_combination_clean, $order_warehouses))) {
continue;
}
$quantity = $manager->getProductRealQuantities($product_id, $product_attribute_id, $allowed_warehouse_for_combination_clean, true);
$query = new DbQuery();
$query->select('COUNT(*)');
$query->from('stock_available');
$query->where('id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id));
if ((int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query)) {
$query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity), 'where' => 'id_product = ' . (int) $product_id . ' AND id_product_attribute = ' . (int) $product_attribute_id . StockAvailable::addSqlShopRestriction(null, $shop_id));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
} else {
$query = array('table' => 'stock_available', 'data' => array('quantity' => $quantity, 'depends_on_stock' => 1, 'out_of_stock' => $out_of_stock, 'id_product' => (int) $id_product, 'id_product_attribute' => (int) $id_product_attribute));
StockAvailable::addSqlShopParams($query['data']);
Db::getInstance()->insert($query['table'], $query['data']);
}
$product_quantity += $quantity;
Hook::exec('actionUpdateQuantity', array('id_product' => $id_product, 'id_product_attribute' => $id_product_attribute, 'quantity' => $quantity));
}
}
// updates
// if $id_product has attributes, it also updates the sum for all attributes
$query = array('table' => 'stock_available', 'data' => array('quantity' => $product_quantity), 'where' => 'id_product = ' . (int) $id_product . ' AND id_product_attribute = 0' . StockAvailable::addSqlShopRestriction(null, $shop_id));
Db::getInstance()->update($query['table'], $query['data'], $query['where']);
}
}
// In case there are no warehouses, removes product from StockAvailable
if (count($warehouse_ids) == 0 && JeproshopStockAvailableModelStockAvailable::dependsOnStock((int) $product_id)) {
$query = "UPDATE " . $db->quoteName('#__jeproshop_stock_available') . " SET " . $db->quoteName('quantity') . " = 0 ";
$query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id;
$db->setQuery($query);
$db->query();
}
JeproshopCache::clean('jeproshop_stock_available_get_quantity_available_by_product_' . (int) $product_id . '_*');
}
示例11: postSave
public function postSave()
{
if ($this->id_product_attribute == 0) {
return true;
}
$id_shop = Shop::getContext() != Shop::CONTEXT_GROUP && $this->id_shop ? $this->id_shop : null;
if (!Configuration::get('PS_DISP_UNAVAILABLE_ATTR')) {
$combination = new Combination((int) $this->id_product_attribute);
if ($colors = $combination->getColorsAttributes()) {
$product = new Product((int) $this->id_product);
foreach ($colors as $color) {
if ($product->isColorUnavailable((int) $color['id_attribute'], (int) $this->id_shop)) {
Tools::clearColorListCache($product->id);
break;
}
}
}
}
$total_quantity = (double) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
SELECT SUM(quantity) + SUM(quantity_remainder) as quantity
FROM ' . _DB_PREFIX_ . 'stock_available
WHERE id_product = ' . (int) $this->id_product . '
AND id_product_attribute <> 0 ' . StockAvailable::addSqlShopRestriction(null, $id_shop));
$this->setQuantity($this->id_product, 0, $total_quantity, $id_shop);
return true;
}