// Fix Product::sqlStock() (use restrictions in left join instead of restrictions in where)
This commit is contained in:
+1
-1
@@ -453,7 +453,7 @@ class CartCore extends ObjectModel
|
|||||||
);
|
);
|
||||||
|
|
||||||
// @todo test if everything is ok, then refactorise call of this method
|
// @todo test if everything is ok, then refactorise call of this method
|
||||||
Product::sqlStock('cp', 'cp', false, null, $sql);
|
$sql->join(Product::sqlStock('cp', 'cp'));
|
||||||
|
|
||||||
// Build WHERE clauses
|
// Build WHERE clauses
|
||||||
$sql->where('cp.`id_cart` = '.(int)$this->id);
|
$sql->where('cp.`id_cart` = '.(int)$this->id);
|
||||||
|
|||||||
+17
-36
@@ -1813,7 +1813,7 @@ class ProductCore extends ObjectModel
|
|||||||
);
|
);
|
||||||
$sql->leftJoin('tax', 't', 't.`id_tax` = tr.`id_tax`');
|
$sql->leftJoin('tax', 't', 't.`id_tax` = tr.`id_tax`');
|
||||||
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
|
$sql->leftJoin('manufacturer', 'm', 'm.`id_manufacturer` = p.`id_manufacturer`');
|
||||||
Product::sqlStock('p', 0, false, null, $sql);
|
$sql->join(Product::sqlStock('p', 0));
|
||||||
|
|
||||||
$sql->where('product_shop.`active` = 1');
|
$sql->where('product_shop.`active` = 1');
|
||||||
if ($front)
|
if ($front)
|
||||||
@@ -2672,49 +2672,30 @@ class ProductCore extends ObjectModel
|
|||||||
* @param string $productAlias Alias of product 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 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 bool $innerJoin LEFT JOIN or INNER JOIN
|
||||||
* @param Context $context
|
* @param Shop $shop
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function sqlStock($product_alias, $product_attribute = 0, $inner_join = false, Shop $shop = null, DbQuery $sql = null)
|
public static function sqlStock($product_alias, $product_attribute = 0, $inner_join = false, Shop $shop = null)
|
||||||
{
|
{
|
||||||
if (!$shop)
|
if (!$shop)
|
||||||
$shop = Context::getContext()->shop;
|
$shop = Context::getContext()->shop;
|
||||||
|
|
||||||
if ($sql)
|
$sql = (($inner_join) ? ' INNER ' : ' LEFT ').'
|
||||||
{
|
JOIN '._DB_PREFIX_.'stock_available stock
|
||||||
// @todo remove this code when query builder is accepted or removed
|
ON (stock.id_product = '.pSQL($product_alias).'.id_product';
|
||||||
$method = ($inner_join) ? 'innerJoin' : 'leftJoin';
|
|
||||||
$sql->$method('stock_available', 'stock', 'stock.id_product = '.pSQL($product_alias).'.id_product');
|
|
||||||
if (!is_null($product_attribute))
|
|
||||||
{
|
|
||||||
if (!Combination::isFeatureActive())
|
|
||||||
$sql->where('stock.id_product_attribute = 0');
|
|
||||||
else if (is_numeric($product_attribute))
|
|
||||||
$sql->where('stock.id_product_attribute = '.$product_attribute);
|
|
||||||
else if (is_string($product_attribute))
|
|
||||||
$sql->where('stock.id_product_attribute = IFNULL('.pSQL($product_attribute).'.id_product_attribute, 0)');
|
|
||||||
}
|
|
||||||
$sql = StockAvailable::addSqlShopRestriction($sql, $shop->id, 'stock');
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$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 (!is_null($product_attribute))
|
||||||
{
|
{
|
||||||
if (!Combination::isFeatureActive())
|
if (!Combination::isFeatureActive())
|
||||||
$sql .= ' AND stock.id_product_attribute = 0';
|
$sql .= ' AND stock.id_product_attribute = 0';
|
||||||
else if (is_numeric($product_attribute))
|
else if (is_numeric($product_attribute))
|
||||||
$sql .= ' AND stock.id_product_attribute = '.$product_attribute;
|
$sql .= ' AND stock.id_product_attribute = '.$product_attribute;
|
||||||
else if (is_string($product_attribute))
|
else if (is_string($product_attribute))
|
||||||
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($product_attribute).'.id_product_attribute, 0)';
|
$sql .= ' AND stock.id_product_attribute = IFNULL('.pSQL($product_attribute).'.id_product_attribute, 0)';
|
||||||
}
|
|
||||||
|
|
||||||
$sql .= StockAvailable::addSqlShopRestriction(null, $shop->id, 'stock').' )';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql .= StockAvailable::addSqlShopRestriction(null, $shop->id, 'stock').' )';
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3098,7 +3079,7 @@ class ProductCore extends ObjectModel
|
|||||||
$where .= ' OR pa.`reference` LIKE \'%'.pSQL($query).'%\'';
|
$where .= ' OR pa.`reference` LIKE \'%'.pSQL($query).'%\'';
|
||||||
}
|
}
|
||||||
$sql->where($where);
|
$sql->where($where);
|
||||||
Product::sqlStock('p', 'pa', false, $context->shop, $sql);
|
$sql->join(Product::sqlStock('p', 'pa', false, $context->shop));
|
||||||
|
|
||||||
$result = Db::getInstance()->executeS($sql);
|
$result = Db::getInstance()->executeS($sql);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user