Hello!
En modifiant un de mes modules en cours de dev, pour lui permettre d'afficher des données dans smarty, j'ai obtenu cette erreur
Plugin tag 'customerAddField' already registered
La modification étant bien entendu cette partie (AbstractSmartyPlugin).
J'ai fait tout comme un autre module (qui fonctionne) :
<services>
<service id="smarty.additionalcustomerfield.fieldvalue" class="AdditionalCustomerField\Smarty\Plugins\AdditionalCustomerFieldPlugin" scope="request">
<tag name="thelia.parser.register_plugin" />
</service>
</services>
<?php
namespace AdditionalCustomerField\Smarty\Plugins;
use AdditionalCustomerField\AdditionalCustomerField;
use TheliaSmarty\Template\AbstractSmartyPlugin;
use TheliaSmarty\Template\SmartyPluginDescriptor;
use AdditionalCustomerField\Model\AdditionalCustomerFieldCustomerQuery;
class AdditionalCustomerFieldPlugin extends AbstractSmartyPlugin
{
/**
* @return SmartyPluginDescriptor[] an array of SmartyPluginDescriptor
*/
public function getPluginDescriptors()
{
return [
new SmartyPluginDescriptor("function", "customerAddField", $this, "customerAddFieldValue")
];
}
public function customerAddFieldValue($params)
{
$locale = $this->getRequest()->getSession()->getLang()->getLocale();
$currentCustomer = $this->securityContext->getCustomerUser();
$output = '';
if (null !== $currentCustomer && !isset($params['id'])) {
$search = AdditionalCustomerFieldCustomerQuery::create()
->filterByAdditionalCustomerFieldId($params['id'])
->filterByCustomerId($currentCustomer->getId())
->find();
if(null !== $search){
if(count($search)>1){
$output = array();
}
foreach($search as $result){
if($result->getIsFreeText()){
$value = $result->getFreeTextValue();
}else{
$value = $result->setLocale($locale)->getTitle();
}
if(is_array($output)){
$output[] = $value;
}else{
$output = $value;
}
}
}
}
return $output;
}
}
J'ai bien entendu qu'une seule déclaration de ce "Plugin tag" et donc, qu'à cet endroit.
Une idée d'où ça pourrait venir ?
Last edited by Elyos (11-04-2024 09:17:12)