JoeSatriani Posted March 16, 2017 Share Posted March 16, 2017 Bonjour, Je doit rajouter un champs éditable dans le détail des commandes fournisseurs qui va s'enregistrer dans la base de donnée. Mon problème c'est que j'arrive pas a sauvegarder dans la bdd. Mon inspecteur d'élément: J'ai mis ma fonction ajax dans l'override/controllers/admin/templates/supply_orders/helpers/view.tpl : $("input.text").change(function(){ var $this = $(this); $.ajax({ type:"POST", url: "{$link->getAdminLink('AdminSupplyOrders')|addslashes}", async: true, dataType: "json", data : { ajax: "1", token: "{getAdminToken tab='AdminSupplyOrders'}", tab: "AdminSupplyOrders", action: "ajaxProcessUpdateComments", text: $(this).val(), id_supply_order_detail: $(this).attr("name") }, xhrFields: { withCredentials: false }, crossDomain: false, success : function(res) { console.log('ok'); } }); }); j'ai mis ma fonction update dans l'override/controllers/admin/AdminSupplyOrdersController.php : public function ajaxProcessUpdateComments() { if ($this->tabAccess['edit'] === '1') { $errors = array(); if (!($id_supply_order_detail = Tools::getValue('id_supply_order_detail'))) { $errors[] = Tools::displayError('Invalid order detail'); } elseif (!($text = Tools::getValue('text'))) { $errors[] = Tools::displayError('Invalid text'); } if (!count($errors)) { $id_supply_order_detail = (int)substr($id_supply_order_detail,14); // Suppression de la chaine price_te_ pour obtenir l'id $entry = new SupplyOrderDetail($id_supply_order_detail); $entry->text = (float)$text; $entry->update(); $sql = 'SELECT `text` FROM `'._DB_PREFIX_.'supply_order_detail` WHERE `id_product` = '.$entry->id_product.' AND `id_product_attribute` = '.$entry->id_product_attribute; $result = Db::getInstance()->getRow($sql); if ($result > 0) { $text = $result["text"]; $id_supply_order = $entry->id_supply_order; Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'supply_order_detail` SET `text` = '.$entry->text.' WHERE `id_product` = '.$entry->id_product.' AND `id_product_attribute` = '.$entry->id_product_attribute ); } echo Tools::jsonEncode(array_merge((array)$entry,array("currency"=>(array)new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'))))); } else { echo Tools::jsonEncode(array('errors' => $errors)); } } } et rendu editable dans le même fichier : $this->fields_list = array( 'text' => array( 'title' => $this->l('text_text'), 'align' => 'right', 'orderby' => false, 'filter' => false, 'search' => false, 'type' => 'editable', ), 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