Jump to content

Modify getProducts


AndyLaci

Recommended Posts

Hi everyone,

 

I would need help with modifying this function. I would like to display products in product-list which are not out of stock (all of their attributes have quantity 0), but would be seen if user somehow get to old product by old link.

 

Easier: old products stay, but are not wisible in product list.

 

 

 

public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,

$only_active = false, Context $context = null)

{

if (!$context)

$context = Context::getContext();

 

$front = true;

if (!in_array($context->controller->controller_type, array('front', 'modulefront')))

$front = false;

 

if (!Validate::isOrderBy($order_by) || !Validate::isOrderWay($order_way))

die (Tools::displayError());

if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd')

$order_by_prefix = 'p';

else if ($order_by == 'name')

$order_by_prefix = 'pl';

else if ($order_by == 'position')

$order_by_prefix = 'c';

 

if (strpos($order_by, '.') > 0)

{

$order_by = explode('.', $order_by);

$order_by_prefix = $order_by[0];

$order_by = $order_by[1];

}

$sql = 'SELECT p.*, product_shop.*, pl.* , m.`name` AS manufacturer_name, s.`name` AS supplier_name

FROM `'._DB_PREFIX_.'product` p

'.Shop::addSqlAssociation('product', 'p').'

LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` '.Shop::addSqlRestrictionOnLang('pl').')

LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`)

LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'.

($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').'

WHERE pl.`id_lang` = '.(int)$id_lang.

($id_category ? ' AND c.`id_category` = '.(int)$id_category : '').

($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '').

($only_active ? ' AND product_shop.`active` = 1' : '').'

ORDER BY '.(isset($order_by_prefix) ? pSQL($order_by_prefix).'.' : '').'`'.pSQL($order_by).'` '.pSQL($order_way).

($limit > 0 ? ' LIMIT '.(int)$start.','.(int)$limit : '');

$rq = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

if ($order_by == 'price')

Tools::orderbyPrice($rq, $order_way);

 

foreach ($rq as &$row)

$row = Product::getTaxesInformations($row);

 

return ($rq);

}

 

 

This would save me tons of time, because the database is optimised, but it is bit hard to get to understand it.

Link to comment
Share on other sites

hello i've got nice and easy in use solution for this, check please this tutorial: disable out of stock products in my opinion it's better than modyfing the source codes of prestashop

 

This solution is good, but I want other thing. This disales the view of the product, I would like just to hide the product from product list with ability to find it on google or relink to product, not to deactivate it from all views, maybe it could be done in productController with this solutiun plus enabling to view deactivated product, but it is not the best solution. The best would be changing the code, where the products load to product-list and filter them by quantity greater than 0.

 

Changing the core can be done in override section am I right?

Link to comment
Share on other sites

wouldnt there be problem with attributes? We are talking about shop with clothes, so allmost every product have some attributes. I found somewhere in one tutorial that you can remove the products by if statement which was something like: if quantity 0 and all attributes quantity 0 then dont show. Do I have to care about attribute quantyties in this case? Or prestashop set this stock.quantity automatically when there is 0 of every attribute?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...