Jump to content

Sort accessories by product position


Recommended Posts

Hi,

 

I know that, the solution is the classes\Product.php but can't solve it.

 

My code according to my problem is: (sorry about the format)

 

public function getAccessories($id_lang, $active = true, Context $context = null)
{
if (!$context)
$context = Context::getContext();
 
$sql = 'SELECT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description`, pl.`description_short`, pl.`link_rewrite`,
pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, pl.`available_now`, pl.`available_later`,
MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` as manufacturer_name, cl.`name` AS category_default,
DATEDIFF(
p.`date_add`,
DATE_SUB(
NOW(),
INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY
)
) > 0 AS new
FROM `'._DB_PREFIX_.'accessory`
LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = `id_product_2`
'.Shop::addSqlAssociation('product', 'p').'
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (
p.`id_product` = pl.`id_product`
AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
)
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (
product_shop.`id_category_default` = cl.`id_category`
AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
)
LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product`)'.
Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').'
LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (p.`id_manufacturer`= m.`id_manufacturer`)
'.Product::sqlStock('p', 0).'
WHERE `id_product_1` = '.(int)$this->id.
($active ? ' AND product_shop.`active` = 1 AND product_shop.`visibility` != \'none\'' : '').'
GROUP BY product_shop.id_product';
 
if (!$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql))
return false;
foreach ($result as &$row)
$row['id_product_attribute'] = Product::getDefaultAttribute((int)$row['id_product']);
return $this->getProductsProperties($id_lang, $result);
}
 
Where should I rewrite the code for that, that the accessories appear in the same sort on the product page, like as they are ordered in they own category in the back office .
 
Many thx, Gyula
Link to comment
Share on other sites

  • 2 years later...
×
×
  • Create New...