[*] MO : TM - Blockcart added Layer
This commit is contained in:
@@ -141,13 +141,16 @@ class ProductSaleCore
|
||||
$groups = FrontController::getCurrentCustomerGroups();
|
||||
$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
|
||||
|
||||
$sql = 'SELECT p.id_product, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
|
||||
ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, p.quantity, p.customizable,
|
||||
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, p.out_of_stock
|
||||
$sql = 'SELECT p.id_product, MAX(product_attribute_shop.id_product_attribute) id_product_attribute, pl.`link_rewrite`, pl.`name`, pl.`description_short`, MAX(image_shop.`id_image`) id_image, il.`legend`,
|
||||
ps.`quantity` AS sales, p.`ean13`, p.`upc`, cl.`link_rewrite` AS category, p.show_price, p.available_for_order, IFNULL(stock.quantity, 0) as quantity, p.customizable,
|
||||
IFNULL(pa.minimal_quantity, p.minimal_quantity) as minimal_quantity, stock.out_of_stock
|
||||
FROM `'._DB_PREFIX_.'product_sale` ps
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p ON ps.`id_product` = p.`id_product`
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa ON (ps.`id_product` = pa.`id_product` AND pa.default_on = 1)
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
|
||||
ON (p.`id_product` = pa.`id_product`)
|
||||
'.Shop::addSqlAssociation('product_attribute', 'pa', false, 'product_attribute_shop.`default_on` = 1').'
|
||||
'.Product::sqlStock('p', 'product_attribute_shop', false, $context->shop).'
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
|
||||
ON p.`id_product` = pl.`id_product`
|
||||
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
|
||||
|
||||
@@ -654,4 +654,62 @@ class OrderDetailCore extends ObjectModel
|
||||
$query->where('od.`id_order_detail` = '.(int)$this->id_order_detail);
|
||||
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
|
||||
}
|
||||
}
|
||||
|
||||
public static function getCrossSells($id_product, $id_lang, $limit = 12)
|
||||
{
|
||||
if (!$id_product || !$id_lang)
|
||||
return;
|
||||
|
||||
$front = true;
|
||||
if (!in_array(Context::getContext()->controller->controller_type, array('front', 'modulefront')))
|
||||
$front = false;
|
||||
|
||||
$orders = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT o.id_order
|
||||
FROM '._DB_PREFIX_.'orders o
|
||||
LEFT JOIN '._DB_PREFIX_.'order_detail od ON (od.id_order = o.id_order)
|
||||
WHERE o.valid = 1 AND od.product_id = '.(int)$id_product);
|
||||
|
||||
if (sizeof($orders))
|
||||
{
|
||||
$list = '';
|
||||
foreach ($orders AS $order)
|
||||
$list .= (int)$order['id_order'].',';
|
||||
$list = rtrim($list, ',');
|
||||
|
||||
$orderProducts = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
|
||||
SELECT DISTINCT od.product_id, p.id_product, pl.name, pl.link_rewrite, p.reference, i.id_image, product_shop.show_price, cl.link_rewrite category, p.ean13, p.out_of_stock, p.id_category_default
|
||||
FROM '._DB_PREFIX_.'order_detail od
|
||||
LEFT JOIN '._DB_PREFIX_.'product p ON (p.id_product = od.product_id)
|
||||
'.Shop::addSqlAssociation('product', 'p').'
|
||||
LEFT JOIN '._DB_PREFIX_.'product_lang pl ON (pl.id_product = od.product_id'.Shop::addSqlRestrictionOnLang('pl').')
|
||||
LEFT JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = product_shop.id_category_default'.Shop::addSqlRestrictionOnLang('cl').')
|
||||
LEFT JOIN '._DB_PREFIX_.'image i ON (i.id_product = od.product_id)
|
||||
WHERE od.id_order IN ('.$list.')
|
||||
AND pl.id_lang = '.(int)$id_lang.'
|
||||
AND cl.id_lang = '.(int)$id_lang.'
|
||||
AND od.product_id != '.(int)$id_product.'
|
||||
AND i.cover = 1
|
||||
AND product_shop.active = 1'
|
||||
.($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').'
|
||||
ORDER BY RAND()
|
||||
LIMIT '.(int)$limit.'
|
||||
');
|
||||
|
||||
$taxCalc = Product::getTaxCalculationMethod();
|
||||
if (is_array($orderProducts))
|
||||
{
|
||||
foreach ($orderProducts AS &$orderProduct)
|
||||
{
|
||||
$orderProduct['image'] = Context::getContext()->link->getImageLink($orderProduct['link_rewrite'], (int)$orderProduct['product_id'].'-'.(int)$orderProduct['id_image'], ImageType::getFormatedName('medium'));
|
||||
$orderProduct['link'] = Context::getContext()->link->getProductLink((int)$orderProduct['product_id'], $orderProduct['link_rewrite'], $orderProduct['category'], $orderProduct['ean13']);
|
||||
if ($taxCalc == 0 OR $taxCalc == 2)
|
||||
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], true, NULL);
|
||||
elseif ($taxCalc == 1)
|
||||
$orderProduct['displayed_price'] = Product::getPriceStatic((int)$orderProduct['product_id'], false, NULL);
|
||||
}
|
||||
return Product::getProductsProperties($id_lang, $orderProducts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user