giulym Posted May 29, 2019 Share Posted May 29, 2019 I'm trying to separate the variants of the product-variants.tpl I need this split (and I have to add them on product-special.tpl: TAB 1 colors: all the colors TAB 2 colors 2: all the second colors TAB 3 option 1: A B TAB 4 option 2: C D I'm calling the group by ID, but I still see the others groups too. {elseif $group.group_type == 'color'} <ul id="group_1"> {foreach from=$group.attributes key=id_attribute item=group_attribute} <li class="float-xs-left input-container"> <label> <input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[1]" value="{$id_attribute}"{if $group_attribute.selected} checked="checked"{/if}> <span {if $group_attribute.html_color_code}class="color" style="background-color: {$group_attribute.html_color_code}" {/if} {if $group_attribute.texture}class="color texture" style="background-image: url({$group_attribute.texture})" {/if} ><span class="sr-only">{$group_attribute.name}</span></span> </label> </li> {/foreach} </ul> Link to comment Share on other sites More sharing options...
giulym Posted May 31, 2019 Author Share Posted May 31, 2019 just let me know if it is possible or not Link to comment Share on other sites More sharing options...
ottojack Posted November 22, 2020 Share Posted November 22, 2020 (edited) Hello, did you find amy solution? I'm facing the same problem, i want to keep saperate variants (es.color/size/etc) also in homepage non only in detailed product page. Edited November 22, 2020 by ottojack (see edit history) Link to comment Share on other sites More sharing options...
swtiris Posted April 2, 2022 Share Posted April 2, 2022 (edited) Hello there, I want to have the product variants in the front list of the product so I edited templates/catalog/_partials/miniatures/product.tpl and inserted {block name='product_variants'} {include file='catalog/_partials/product-variants.tpl'} {/block} in the according place but I get nothing. I troubleshooted it a while and it seems that {$groups|@var_dump} inside templates/catalog/_partials/product-variants.tpl returns NULL while inside the product it returns all the array. Any hint for what should be done to appear the variants in the front list of the product ? I am with PS 1.7.5.2 for your reference. Thank you Edited April 2, 2022 by swtiris (see edit history) Link to comment Share on other sites More sharing options...
compsoul.dev Posted November 10, 2022 Share Posted November 10, 2022 You have to do this in the different way: http://shop.compsoul.pl Presta blocks and allows show to only one type of attribute, color. If You want to add another, You have to create module. If You want to ready solution, write to me I will give You this solution for free. I do not know, that admins allow add here custom module. Link to comment Share on other sites More sharing options...
endriu107 Posted November 11, 2022 Share Posted November 11, 2022 @compsoul.pl You can post free solution here. Link to comment Share on other sites More sharing options...
JJPato Posted December 23, 2022 Share Posted December 23, 2022 Clearly it was not that free, as he mention Link to comment Share on other sites More sharing options...
compsoul.dev Posted December 23, 2022 Share Posted December 23, 2022 I do not add my solutions, because the rules of the forum are not clear to me. But in this case I guess I can: <?php if (!defined('_PS_VERSION_')) { exit; } class CompsoulMainVariants extends Module { public function __construct() { $this->name = 'compsoulmainvariants'; $this->tab = 'front_office_features'; $this->version = '1.0.0'; $this->author = 'compsoul.pl'; $this->need_instance = 0; $this->ps_versions_compliancy = [ 'min' => '1.7.6', 'max' => _PS_VERSION_, ]; $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('Compsoul Main Variants'); $this->description = $this->l('Description of my module.'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall?'); if (!Configuration::get('COMPSOUL_MAIN_VARIANTS')) { $this->warning = $this->l('No name provided'); } } public function install() { if (Shop::isFeatureActive()) { Shop::setContext(Shop::CONTEXT_ALL); } return ( parent::install() && $this->registerHook('displayCompsoulMainVariants') && Configuration::updateValue('COMPSOUL_MAIN_VARIANTS', 'my friend') ); } public function uninstall() { return ( parent::uninstall() && Configuration::deleteByName('COMPSOUL_MAIN_VARIANTS') ); } public function hookDisplayCompsoulMainVariants($params) { $product = $this->getProductById($params['product']->id_product); $attributes = $product->getAttributesInformationsByProduct($params['product']->id_product); $attributesList = $this->getAttributesIdList($attributes, $params['product']->id_product); $atributesGroup = array(); if(!$attributesList) return false; foreach ($attributesList as $key => $value) { $atributesGroup[$key] = $this->getAttributesGroupById($params['product']->id_product, $value); foreach ($atributesGroup[$key] as $index => $result) { $atributesGroup[$key][$index]['url'] = $this->getProductAttributeLink($params['product']->id_product, $result['id_product_attribute']); } } $this->context->smarty->assign([ 'compsoul_main_variants_name' => Configuration::get('COMPSOUL_MAIN_VARIANTS'), 'compsoul_main_variants_link' => $this->context->link->getModuleLink('compsoulmainvariants', 'display'), 'compsoul_main_variants_atributes' => $atributesGroup, 'compsoul_main_variants_listing' => $params['listing'] ]); return $this->display(__FILE__, 'compsoulmainvariants.tpl'); } public function getAttributesIdList($attributes = null, $idProduct = null ) { if(!$attributes || !$idProduct) return false; $attributesIdList = array(); foreach ($attributes as $key => $value) { $attributesIdList[$key] = $value['id_attribute_group']; } return array_unique($attributesIdList); } public function getAttributesGroupById($idProduct = null, $idAttributeGroup = null) { if(!$idProduct || !$idAttributeGroup) return false; $idLang = $this->context->language->id; $checkStock = !Configuration::get('PS_DISP_UNAVAILABLE_ATTR'); if (!$res = Db::getInstance()->executeS( ' SELECT pa.`id_product`, pac.`id_product_attribute`, ' . ($checkStock ? 'SUM(IF(stock.`quantity` > 0, 1, 0))' : '0') . ' qty, a.`id_attribute`, al.`name`, color, IF(color = "", a.id_attribute, color) group_by FROM `' . _DB_PREFIX_ . 'product_attribute` pa ' . Shop::addSqlAssociation('product_attribute', 'pa') . ($checkStock ? Product::sqlStock('pa', 'pa') : '') . ' JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.`id_product_attribute` = product_attribute_shop.`id_product_attribute`) JOIN `' . _DB_PREFIX_ . 'attribute` a ON (a.`id_attribute` = pac.`id_attribute`) JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = ' . (int) $idLang . ') JOIN `' . _DB_PREFIX_ . 'attribute_group` ag ON (a.id_attribute_group = ag.`id_attribute_group`) WHERE pa.`id_product` IN (' . $idProduct . ') AND ag.`id_attribute_group` = '. $idAttributeGroup .' GROUP BY pa.`id_product`, a.`id_attribute`, `group_by` ' . ($checkStock ? 'HAVING qty > 0' : '') . ' ORDER BY a.`position` ASC;' ) ) { return false; } return $res; } public function getProductById($id = null) { if($id) $id = new Product($id, $this->context->language->id); return $id; } public function getProductAttributeLink($idProduct = null, $idProductAttribute = null) { $link = new Link(); $url = null; if($idProduct && $idProductAttribute) { $url = $link->getProductLink( $idProduct, null, null, null, $this->context->language->id, null, $idProductAttribute, false, false, true ); } return $url; } } 1 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