taniacr Posted June 24, 2019 Share Posted June 24, 2019 (edited) Hi, In product-details.tpl the features, when grouped, are generated inside a single <dd> {block name='product_features'} {if $product.grouped_features} <section> <h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3> <dl> {foreach from=$product.grouped_features item=feature} <dt>{$feature.name}</dt> <dd>{$feature.value|escape:'htmlall'|nl2br nofilter}</dd> {/foreach} </dl> </section> {/if} {/block} I need to create somethink like the following (that of course doesn't work): {if $product.grouped_features} <section> <h3>{l s='Data sheet' d='Shop.Theme.Catalog'}</h3> <dl> {foreach from=$product.grouped_features item=feature} <dt>{$feature.name}</dt> <dd>{foreach $feature.value}<span title="{$feature.value|replace:' ':'_'}">{$feature.value|escape:'htmlall'|nl2br nofilter}</span>{/foreach}</dd> {/foreach} </dl> </section> {/if} Edited June 24, 2019 by taniacr (see edit history) Link to comment Share on other sites More sharing options...
giuse Posted March 27, 2021 Share Posted March 27, 2021 hello Tania, have you solved? I also have this problem Link to comment Share on other sites More sharing options...
taniacr Posted March 29, 2021 Author Share Posted March 29, 2021 On 3/27/2021 at 12:58 PM, giuse said: hello Tania, have you solved? I also have this problem Hi! Unfortunately no but haven't looked at this issue since. If anyone could shed a light would be very helpful still Link to comment Share on other sites More sharing options...
AfterGlow93 Posted January 9, 2023 Share Posted January 9, 2023 (edited) Hi Sorry to bring up this old post but lack of answer to this case could help some people here. For anyone looking for more informations about way to un-group or change delimiter of grouped features : Variable $products.grouped_features is built through ProductLazyArray class, by the function buildGroupedFeatures then called by the function getGroupedFeatures. Here is the function buildGroupedFeatures (Line 1174 of PrestaShop/src/Adapter/Presenter/Product/ProductLazyArray.php) : protected function buildGroupedFeatures(array $productFeatures) { $valuesByFeatureName = []; $groupedFeatures = []; // features can either be "raw" (id_feature, id_product_id_feature_value) // or "full" (id_feature, name, value) // grouping can only be performed if they are "full" if (empty($productFeatures) || !array_key_exists('name', reset($productFeatures))) { return []; } foreach ($productFeatures as $feature) { $featureName = $feature['name']; // build an array of unique features $groupedFeatures[$featureName] = $feature; // aggregate feature values separately $valuesByFeatureName[$featureName][] = $feature['value']; } // replace value from features that have multiple values with the ones we aggregated earlier foreach ($valuesByFeatureName as $featureName => $values) { if (count($values) > 1) { sort($values, SORT_NATURAL); $groupedFeatures[$featureName]['value'] = implode("\n", $values); } } return $groupedFeatures; } The implode can be replaced with another delimiter (I used a semicolon with spaces in my case) or set in an array with an unique id which will be called into a foreach loop. Hope this helps Edited January 9, 2023 by AfterGlow93 (see edit history) 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