我在prestashop之下开发了一个站点,并且在一件事情上受阻。我在prestashop中添加了为供应商选择组的可能性。每个用户都吸引1个或多个组,而我尝试仅显示他们在同一组中共有的供应商。
我已经创建了一个vendor_group表,所以到目前为止,我必须将每个提供程序修补到一个或多个组。但是,当我与要加入A组的用户在一起时,我只需要看到同时也是A组的拉手的提供商,这就是我遇到的问题。
我想修改此显示,我想我可以通过以下功能来做到这一点:
public static function getSuppliers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_groups = false)
{
if (!$id_lang) {
$id_lang = Configuration::get('PS_LANG_DEFAULT');
}
if (!Group::isFeatureActive()) {
$all_groups = true;
}
$query = new DbQuery();
$query->select('s.*, sl.`description`');
$query->from('supplier', 's');
$query->leftJoin('supplier_lang', 'sl', 's.`id_supplier` = sl.`id_supplier` AND sl.`id_lang` = '.(int)$id_lang);
$query->join(Shop::addSqlAssociation('supplier', 's'));
if ($active) {
$query->where('s.`active` = 1');
}
$query->orderBy(' s.`name` ASC');
$query->limit($n, ($p - 1) * $n);
$query->groupBy('s.id_supplier');
$suppliers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
if ($suppliers === false) {
return false;
}
if ($get_nb_products) {
$sql_groups = '';
if (!$all_groups) {
$groups = FrontController::getCurrentCustomerGroups();
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
}
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
SELECT ps.`id_supplier`, COUNT(DISTINCT ps.`id_product`) as nb_products
FROM `'._DB_PREFIX_.'product_supplier` ps
JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product`= p.`id_product`)
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'supplier` as m ON (m.`id_supplier`= p.`id_supplier`)
WHERE ps.id_product_attribute = 0'.
($active ? ' AND product_shop.`active` = 1' : '').
' AND product_shop.`visibility` NOT IN ("none")'.
($all_groups ? '' :'
AND ps.`id_product` IN (
SELECT cp.`id_product`
FROM `'._DB_PREFIX_.'category_group` cg
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
WHERE cg.`id_group` '.$sql_groups.'
)').'
GROUP BY ps.`id_supplier`'
);
$counts = array();
foreach ($results as $result) {
$counts[(int)$result['id_supplier']] = (int)$result['nb_products'];
}
if (count($counts) && is_array($suppliers)) {
foreach ($suppliers as $key => $supplier) {
if (isset($counts[(int)$supplier['id_supplier']])) {
$suppliers[$key]['nb_products'] = $counts[(int)$supplier['id_supplier']];
} else {
$suppliers[$key]['nb_products'] = 0;
}
}
}
}
$nb_suppliers = count($suppliers);
$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
for ($i = 0; $i < $nb_suppliers; $i++) {
$suppliers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($suppliers[$i]['name']) : 0);
}
return $suppliers;
}
但是我不知道该怎么做。你有主意吗?
感谢您的帮助。