Bonjour @Guipau,
Avant toute chose, je vous conseille de créer un thème enfant en suivant la documentation officielle si ce n'est pas déjà fait : https://devdocs.prestashop.com/1.7/themes/reference/template-inheritance/parent-child-feature/
Ainsi, les changements que vous apporterez au thème ne seront pas écrasés si ce dernier doit être mis à jour.
Ensuite, j'ai une question : vos déclinaisons varient-elles selon la texture seulement ou selon plusieurs attributs ?
- Premier cas : on peut rajouter un peu de code dans le fichier /themes/votre_theme/templates/catalog/_partials/products-variants.tpl :
<label aria-label="{$group_attribute.name}"> {assign var="attributes" value=[$id_attribute]} {assign var="id_product_attribute" value=Product::getIdProductAttributeByIdAttributes(Tools::getValue('id_product'), $attributes)} {assign var="out_of_stock" value=$combinations[$id_product_attribute].quantity <= 0} <input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected && !$out_of_stock} checked="checked"{/if}{if $out_of_stock} disabled{/if}> <span {if $group_attribute.texture} class="color texture" style="background-image: url({$group_attribute.texture});{if $out_of_stock} opacity: 60%; cursor: not-allowed;{/if}" {elseif $group_attribute.html_color_code} class="color" style="background-color: {$group_attribute.html_color_code}" {/if} ><span class="sr-only">{$group_attribute.name}</span></span> </label>
Il remplace le code des lignes 44 à 53, à savoir :
<label aria-label="{$group_attribute.name}"> <input class="input-color" type="radio" data-product-attribute="{$id_attribute_group}" name="group[{$id_attribute_group}]" value="{$id_attribute}" title="{$group_attribute.name}"{if $group_attribute.selected} checked="checked"{/if}> <span {if $group_attribute.texture} class="color texture" style="background-image: url({$group_attribute.texture})" {elseif $group_attribute.html_color_code} class="color" style="background-color: {$group_attribute.html_color_code}" {/if} ><span class="sr-only">{$group_attribute.name}</span></span> </label>
Je suis pas très fan de ma méthode, puisqu'elle encombre un template avec de la logique, mais c'est la seule que j'ai trouvé sans passer par de l'override.
Parce que oui, je suppose qu'on pourrait aussi override la fonction "assignAttributesGroups" du ProductController.php.
- Deuxième cas : il faut tenir compte des autres attributs sélectionnés.
Il faudrait ainsi remplacer la ligne :
{assign var="attributes" value=[$id_attribute]}
par
{assign var="attributes" value=Tools::getValue('group')}
{if $group_attribute.texture}
{$attributes[$id_attribute_group] = $id_attribute}
{/if}
Mais le problème, c'est que si l'utilisateur arrive sur la page produit et ne modifie aucun attribut, la variable 'group' n'est pas définie.
Donc je pense qu'il faudrait trouver une autre méthode si vous êtes dans cette situation...
Je pourrais me pencher sur la création d'un module si besoin est, ce serait peut-être plus propre. 😅
Bonne fin de journée,
Kaudaj.