[-] FO: Fix PSFV-533 combinations specificprices and blockspecial
This commit is contained in:
+24
-9
@@ -1913,7 +1913,7 @@ class ProductCore extends ObjectModel
|
|||||||
return Product::getProductsProperties((int)$id_lang, $result);
|
return Product::getProductsProperties((int)$id_lang, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function _getProductIdByDate($beginning, $ending, Context $context = null)
|
protected static function _getProductIdByDate($beginning, $ending, Context $context = null, $with_combination = false)
|
||||||
{
|
{
|
||||||
if (!$context)
|
if (!$context)
|
||||||
$context = Context::getContext();
|
$context = Context::getContext();
|
||||||
@@ -1928,7 +1928,9 @@ class ProductCore extends ObjectModel
|
|||||||
$id_country,
|
$id_country,
|
||||||
$context->customer->id_default_group,
|
$context->customer->id_default_group,
|
||||||
$beginning,
|
$beginning,
|
||||||
$ending
|
$ending,
|
||||||
|
0,
|
||||||
|
true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1948,27 +1950,39 @@ class ProductCore extends ObjectModel
|
|||||||
$front = false;
|
$front = false;
|
||||||
|
|
||||||
$current_date = date('Y-m-d H:i:s');
|
$current_date = date('Y-m-d H:i:s');
|
||||||
$ids_product = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context);
|
$product_reductions = Product::_getProductIdByDate((!$beginning ? $current_date : $beginning), (!$ending ? $current_date : $ending), $context, true);
|
||||||
|
|
||||||
|
$ids_product = false;
|
||||||
|
if ($product_reductions)
|
||||||
|
{
|
||||||
|
$ids_product = ' AND (';
|
||||||
|
foreach ($product_reductions as $product_reduction)
|
||||||
|
$ids_product .= '( p.`id_product` = '.(int)$product_reduction['id_product'].($product_reduction['id_product_attribute'] ? ' AND pa.`id_product_attribute`='.(int)$product_reduction['id_product_attribute'] :'').') OR';
|
||||||
|
$ids_product = rtrim($ids_product, 'OR').')';
|
||||||
|
}
|
||||||
|
|
||||||
$groups = FrontController::getCurrentCustomerGroups();
|
$groups = FrontController::getCurrentCustomerGroups();
|
||||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||||
|
|
||||||
// Please keep 2 distinct queries because RAND() is an awful way to achieve this result
|
// Please keep 2 distinct queries because RAND() is an awful way to achieve this result
|
||||||
$sql = 'SELECT p.id_product
|
$sql = 'SELECT p.id_product, pa.id_product_attribute
|
||||||
FROM `'._DB_PREFIX_.'product` p
|
FROM `'._DB_PREFIX_.'product` p
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (p.id_product = pa.id_product)
|
||||||
'.Shop::addSqlAssociation('product', 'p').'
|
'.Shop::addSqlAssociation('product', 'p').'
|
||||||
WHERE p.`active` = 1
|
WHERE p.`active` = 1
|
||||||
'.(($ids_product) ? 'AND p.`id_product` IN ('.implode(', ', $ids_product).')' : '').'
|
'.(($ids_product) ? $ids_product : '').'
|
||||||
AND p.`id_product` IN (
|
AND p.`id_product` IN (
|
||||||
SELECT cp.`id_product`
|
SELECT cp.`id_product`
|
||||||
FROM `'._DB_PREFIX_.'category_group` cg
|
FROM `'._DB_PREFIX_.'category_group` cg
|
||||||
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
|
||||||
WHERE cg.`id_group` '.$sql_groups.'
|
WHERE cg.`id_group` '.$sql_groups.'
|
||||||
)
|
)
|
||||||
|
GROUP BY p.id_product
|
||||||
ORDER BY RAND()';
|
ORDER BY RAND()';
|
||||||
$id_product = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
|
|
||||||
|
|
||||||
if (!$id_product)
|
if (!$id_product = $result['id_product'])
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
$sql = 'SELECT p.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
|
$sql = 'SELECT p.*, stock.`out_of_stock` out_of_stock, pl.`description`, pl.`description_short`,
|
||||||
@@ -1992,7 +2006,8 @@ class ProductCore extends ObjectModel
|
|||||||
WHERE p.id_product = '.(int)$id_product.'
|
WHERE p.id_product = '.(int)$id_product.'
|
||||||
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '');
|
'.($front ? ' AND p.`visibility` IN ("both", "catalog")' : '');
|
||||||
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
$row = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($sql);
|
||||||
|
if ($result['id_product_attribute'])
|
||||||
|
$row['id_product_attribute'] = $result['id_product_attribute'];
|
||||||
return Product::getProductProperties($id_lang, $row);
|
return Product::getProductProperties($id_lang, $row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -341,13 +341,13 @@ class SpecificPriceCore extends ObjectModel
|
|||||||
');
|
');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getProductIdByDate($id_shop, $id_currency, $id_country, $id_group, $beginning, $ending, $id_customer = 0)
|
public static function getProductIdByDate($id_shop, $id_currency, $id_country, $id_group, $beginning, $ending, $id_customer = 0, $with_combination_id = false)
|
||||||
{
|
{
|
||||||
if (!SpecificPrice::isFeatureActive())
|
if (!SpecificPrice::isFeatureActive())
|
||||||
return array();
|
return array();
|
||||||
|
|
||||||
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||||
SELECT `id_product`
|
SELECT `id_product`, `id_product_attribute`
|
||||||
FROM `'._DB_PREFIX_.'specific_price`
|
FROM `'._DB_PREFIX_.'specific_price`
|
||||||
WHERE `id_shop` IN(0, '.(int)$id_shop.') AND
|
WHERE `id_shop` IN(0, '.(int)$id_shop.') AND
|
||||||
`id_currency` IN(0, '.(int)$id_currency.') AND
|
`id_currency` IN(0, '.(int)$id_currency.') AND
|
||||||
@@ -365,7 +365,7 @@ class SpecificPriceCore extends ObjectModel
|
|||||||
');
|
');
|
||||||
$ids_product = array();
|
$ids_product = array();
|
||||||
foreach ($results as $row)
|
foreach ($results as $row)
|
||||||
$ids_product[] = (int)$row['id_product'];
|
$ids_product[] = $with_combination_id ? array('id_product' => (int)$row['id_product'], 'id_product_attribute' => (int)$row['id_product_attribute']) : (int)$row['id_product'];
|
||||||
return $ids_product;
|
return $ids_product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user