StrefaBiznesu Posted March 2, 2023 Share Posted March 2, 2023 (edited) Hello. Is there is any module or a way,that could change attributes, combination to first in stock, available ones for the client. Without changing default one on back office? Also we're using clean url module. Is a must. Edited March 2, 2023 by StrefaBiznesu (see edit history) Link to comment Share on other sites More sharing options...
JBW Posted March 2, 2023 Share Posted March 2, 2023 I sell a module that can deactivate combinations/atrributes that are out of stock https://addons.prestashop.com/en/product.php?id_product=50460 Link to comment Share on other sites More sharing options...
WebDesk Solution Posted March 6, 2023 Share Posted March 6, 2023 Hello @StrefaBiznesu To display attributes and combinations in stock first, please try the following solution. Create a Product.php file in this path of \override\classes your project directory and put this code inside the newly created file. <?php class Product extends ProductCore { public function getAttributesGroups($id_lang, $id_product_attribute = null) { if (!Combination::isFeatureActive()) { return []; } $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`, product_attribute_shop.`default_on`, pa.`reference`, pa.`ean13`, pa.`mpn`, pa.`upc`, pa.`isbn`, product_attribute_shop.`unit_price_impact`, product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type` FROM `' . _DB_PREFIX_ . 'product_attribute` pa ' . Shop::addSqlAssociation('product_attribute', 'pa') . ' ' . Product::sqlStock('pa', 'pa') . ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group`) ' . Shop::addSqlAssociation('attribute', 'a') . ' WHERE pa.`id_product` = ' . (int) $this->id . ' AND al.`id_lang` = ' . (int) $id_lang . ' AND agl.`id_lang` = ' . (int) $id_lang . ' '; if ($id_product_attribute !== null) { $sql .= ' AND product_attribute_shop.`id_product_attribute` = ' . (int) $id_product_attribute . ' '; } if ($id_product_attribute !== null) { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC'; } else { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY stock.`quantity` DESC'; } return Db::getInstance()->executeS($sql); } } ?> After that, clean the cache from the back office and check on the product page where the stock combination will be displayed first. Hope this helps! If you find our reply helpful, please hit Like it. Link to comment Share on other sites More sharing options...
StrefaBiznesu Posted March 6, 2023 Author Share Posted March 6, 2023 2 hours ago, WebDesk Solution said: Hello @StrefaBiznesu To display attributes and combinations in stock first, please try the following solution. Create a Product.php file in this path of \override\classes your project directory and put this code inside the newly created file. <?php class Product extends ProductCore { public function getAttributesGroups($id_lang, $id_product_attribute = null) { if (!Combination::isFeatureActive()) { return []; } $sql = 'SELECT ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, agl.`public_name` AS public_group_name, a.`id_attribute`, al.`name` AS attribute_name, a.`color` AS attribute_color, product_attribute_shop.`id_product_attribute`, IFNULL(stock.quantity, 0) as quantity, product_attribute_shop.`price`, product_attribute_shop.`ecotax`, product_attribute_shop.`weight`, product_attribute_shop.`default_on`, pa.`reference`, pa.`ean13`, pa.`mpn`, pa.`upc`, pa.`isbn`, product_attribute_shop.`unit_price_impact`, product_attribute_shop.`minimal_quantity`, product_attribute_shop.`available_date`, ag.`group_type` FROM `' . _DB_PREFIX_ . 'product_attribute` pa ' . Shop::addSqlAssociation('product_attribute', 'pa') . ' ' . Product::sqlStock('pa', 'pa') . ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = pa.`id_product_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (ag.`id_attribute_group` = a.`id_attribute_group`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute`) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group`) ' . Shop::addSqlAssociation('attribute', 'a') . ' WHERE pa.`id_product` = ' . (int) $this->id . ' AND al.`id_lang` = ' . (int) $id_lang . ' AND agl.`id_lang` = ' . (int) $id_lang . ' '; if ($id_product_attribute !== null) { $sql .= ' AND product_attribute_shop.`id_product_attribute` = ' . (int) $id_product_attribute . ' '; } if ($id_product_attribute !== null) { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC'; } else { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY stock.`quantity` DESC'; } return Db::getInstance()->executeS($sql); } } ?> After that, clean the cache from the back office and check on the product page where the stock combination will be displayed first. Hope this helps! If you find our reply helpful, please hit Like it. An award-winning North American PrestaShop Development Agency That Delivers Powerful Results, Innovation, and Secure Digital Transformation. Thanks fow the response. Its not working. Probably is due to clean url module. Any overrides we have tried not working. But we must use clean urls. Link to comment Share on other sites More sharing options...
WebDesk Solution Posted March 7, 2023 Share Posted March 7, 2023 20 hours ago, StrefaBiznesu said: Thanks fow the response. Its not working. Probably is due to clean url module. Any overrides we have tried not working. But we must use clean urls. There are two solutions so you can try them. Solution 1: As per your statement, Any overrides we have tried are not working, so for that, please check the Disable all overrides feature is disabled on the PrestaShop back office, and after that, clear the cache. Please see the screenshot for your reference(https://prnt.sc/JCehM3mW2ukn) Solution 2: If the override is not working, change the ps core file. If you wants to shift ps core file, then go to the classes folder and open Product.php file find getAttributesGroups function and add this line if ($id_product_attribute !== null) { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC'; } Replace With the following code if ($id_product_attribute !== null) { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY ag.`position` ASC, a.`position` ASC, agl.`name` ASC'; } else { $sql .= 'GROUP BY id_attribute_group, id_product_attribute ORDER BY stock.`quantity` DESC'; } After that, clean the cache from the back office and check on the front end. Hope this helps! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now