Module Prestashop : ajouter le prix personnaliser au panier

Par Abdessamad, il y a 9 ans


Salut a tous,
je travaille sur un module(prestashop 1.6.1.5) qui affiche un prix personnalise par une calculation interne.
le problem c'est je veux quand le client click sur button"Ajouter au panier " il ajoute le produit avec le prix personnalise et non pas le prix standard.

existe-il une solution ??

merci davance

2 réponses

tribal, il y a 9 ans

Pour t'aider nous avons besoin d'un peu plus d'explications. Code etc la ta question est très abstraite

Abdessamad, il y a 9 ans

Merci pr ta reponse

alors je developpe un module pour un site e-commerce qui utilise prestashop j'ai cree ma classe
class kalkulationmod extends Module
et j'ai mis les fonctions de base: install ,uninstall plus les HOOks
dans mon hookdisplayProductButtons j'ai le code suivant qui calcule le prix final et j'affect ce prix a une variable qui s'appel $MyCustom_price

function hookdisplayProductButtons(){ //generate Fields User $id_product = (int)Tools::getValue('id_product'); $this->fields=$this->getUserFields($id_product); $this->context->smarty->assign("fields",$this->fields); $this->lagermaterial=$this->getLagermaterial(); $this->context->smarty->assign("lagermaterial",$this->lagermaterial); if (Tools::getValue('submitKalkulation')) { $valueFields=Tools::getValue('data'); //print_r($valueFields);die(); $countFields=sizeof($valueFields); // count of posting data $name_field_user=array(); $value_field_user=array(); foreach ($valueFields as $val) { //echo $val; $name_field_user[]=array_search($val, $valueFields); // name field on user page $value_field_user[]=$val; //value field on user page } $this->id_material=Tools::getValue('selectMaterial'); $getPrice=$this->getPriceMaterial($this->id_material)["price"]; // get price from selected lagermaterial by user //start generate formula //get variables or fields admin $this->getVariables=$this->getVariables($id_product); foreach($this->getVariables as $key => $value){ $name_field[] =$value['name_field']; // all field admin by product $value_field[]=$value['value_field']; // all value admin by product } //push array fields and values user page into array fields and values admin $allNames=array_merge($name_field,$name_field_user); $allValues=array_merge($value_field,$value_field_user); $allNames[]="preis"; // add price to array of allNames $allValues[]=$getPrice; // add price Value to array of allValues // get formula product $getFormula=$this->getProductFormula($id_product); $formulaProduct[0]=$getFormula["formula"]; for ($i=0; $i <count($allValues) ; $i++) { $formulaProduct[$i+1]=str_replace($allNames[$i],$allValues[$i],$formulaProduct[$i]); } //print_r($formulaProduct);echo "<br>"; $countValues=count($allValues); eval("\$formulaProduct[$countValues] = $formulaProduct[$countValues];"); $MyCustom_price =$formulaProduct[$countValues]; $this->context->smarty->assign("MyCustom_price ",$MyCustom_price); // MyCustom price = final price //get data in textbox // $this->context->smarty->assign('valueFields',$valueFields); // $this->context->smarty->assign('SelectedMaterial',$this->id_material); return $this->display(__FILE__, 'kalk_client.tpl'); //end generate formula } return $this->display(__FILE__, 'kalk_client.tpl'); }

Mtn je veux quand le client click sur button"Ajouter au panier " il ajoute le produit avec le prix final qui est stocke ds la variable $MyCustom_price et non pas le prix standard du produit.

j'espere que tu va m'aider à trouver une solution