speed-providing-uncl Posted January 16, 2018 Share Posted January 16, 2018 (edited) Hi, I would like to know how I can add a Reference field in the form for Order Creation, like this : (I edited the HTML source, there's no php code behind) What's the most "prestashop way" to add this form field ? I would to it via a file in /override (or /modules/my_module/override). I would preferably avoid to copy the whole controller/template, paste it to /override and edit it!! I'm coming from symfony, so I was looking for some kind of $form->add('reference') but I can't find anything like this for the order creation on PS's github. Thanks ! Florian PS: it's for prestashop 1.7 Edited January 16, 2018 by Florian more details (see edit history) Link to comment Share on other sites More sharing options...
a17000 Posted January 19, 2018 Share Posted January 19, 2018 Hi, I have the same problem, do you find some help? Link to comment Share on other sites More sharing options...
speed-providing-uncl Posted January 19, 2018 Author Share Posted January 19, 2018 Hi, not yet unfortunately.. I'm using prestashop as a B2B ERP to replace my old excel files, so I can track every payment, invoice, customers, and so on. So I need to have control on every field (at creation and modification). I successfully added my own module with CRUD for every field of payment/invoice/order state/order, e.g : I would love to be able to edit the order creation flow form, also for the date_add field Link to comment Share on other sites More sharing options...
a17000 Posted January 22, 2018 Share Posted January 22, 2018 I don't find the hook to use for modify form.tpl it's very boring... Link to comment Share on other sites More sharing options...
a17000 Posted January 25, 2018 Share Posted January 25, 2018 ok, I find, override AdminOrdersController.php the function ajaxProcessSendMailValidateOrder for update the cart with my new value get form the form.tpl. For you if you want save your field on "create order" look postProcess function 1 Link to comment Share on other sites More sharing options...
speed-providing-uncl Posted January 25, 2018 Author Share Posted January 25, 2018 (edited) Well done, I could add my reference field using code below: admin-folder/themes/default/template/controllers/orders/form.tpl add the following around l. 1524: <div class="form-group"> <label class="control-label col-lg-3" for="order_reference">{l s='Order reference' d='Admin.Orderscustomers.Feature'}</label> <div class="col-lg-6"> <input name="order_reference" id="order_reference" type="text"/> </div> </div> /override/controllers/admin/AdminOrdersController.php class AdminOrdersController extends AdminOrdersControllerCore { public function __construct() { parent::__construct(); } public function postProcess(){ // taken from https://github.com/PrestaShop/PrestaShop/blob/develop/controllers/admin/AdminOrdersController.php#L1204 if (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart')) && ($module_name = Tools::getValue('payment_module_name')) && ($id_order_state = Tools::getValue('id_order_state')) && Validate::isModuleName($module_name)) { if ($this->access('edit')) { if(empty(Tools::getValue('order_reference'))){ // the following is not working but would be great... // $this->errors[] = $this->trans('The Reference field is invalid.', [], 'Admin.Notifications.Error'); // return parent::renderForm(); } if (!Configuration::get('PS_CATALOG_MODE')) { $payment_module = Module::getInstanceByName($module_name); } else { $payment_module = new BoOrder(); } $cart = new Cart((int)$id_cart); Context::getContext()->currency = new Currency((int)$cart->id_currency); Context::getContext()->customer = new Customer((int)$cart->id_customer); $bad_delivery = false; if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery)) || !Address::isCountryActiveById((int)$cart->id_address_invoice)) { if ($bad_delivery) { $this->errors[] = $this->trans('This delivery address country is not active.', array(), 'Admin.Orderscustomers.Notification'); } else { $this->errors[] = $this->trans('This invoice address country is not active.', array(), 'Admin.Orderscustomers.Notification'); } } else { $employee = new Employee((int)Context::getContext()->cookie->id_employee); $result = $payment_module->validateOrder( (int)$cart->id, (int)$id_order_state, $cart->getOrderTotal(true, Cart::BOTH), $payment_module->displayName, $this->trans('Manual order -- Employee:', array(), 'Admin.Orderscustomers.Feature').' '. substr($employee->firstname, 0, 1).'. '.$employee->lastname, array(), null, false, $cart->secure_key ); if ($payment_module->currentOrder) { $reference = Tools::getValue('order_reference'); // <--- added these 5 lines if(!empty($reference)){ $order = new Order($payment_module->currentOrder); $order->reference = $reference; $order->update(); } Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token); } } } } parent::postProcess(); // use default behaviour } It's a shame there's no hook in the controller and we have to copy/paste code from the source... It's also surprising that form.tpl is not ussing any "block" so if we want to change it, we have to change the whole file. What'll happen when Ps will be upgraded ? ... Thanks @a17000 Edited January 25, 2018 by Florian more details (see edit history) Link to comment Share on other sites More sharing options...
a17000 Posted January 26, 2018 Share Posted January 26, 2018 14 hours ago, Florian said: Well done, I could add my reference field using code below: admin-folder/themes/default/template/controllers/orders/form.tpl add the following around l. 1524: <div class="form-group"> <label class="control-label col-lg-3" for="order_reference">{l s='Order reference' d='Admin.Orderscustomers.Feature'}</label> <div class="col-lg-6"> <input name="order_reference" id="order_reference" type="text"/> </div> </div> /override/controllers/admin/AdminOrdersController.php class AdminOrdersController extends AdminOrdersControllerCore { public function __construct() { parent::__construct(); } public function postProcess(){ // taken from https://github.com/PrestaShop/PrestaShop/blob/develop/controllers/admin/AdminOrdersController.php#L1204 if (Tools::isSubmit('submitAddOrder') && ($id_cart = Tools::getValue('id_cart')) && ($module_name = Tools::getValue('payment_module_name')) && ($id_order_state = Tools::getValue('id_order_state')) && Validate::isModuleName($module_name)) { if ($this->access('edit')) { if(empty(Tools::getValue('order_reference'))){ // the following is not working but would be great... // $this->errors[] = $this->trans('The Reference field is invalid.', [], 'Admin.Notifications.Error'); // return parent::renderForm(); } if (!Configuration::get('PS_CATALOG_MODE')) { $payment_module = Module::getInstanceByName($module_name); } else { $payment_module = new BoOrder(); } $cart = new Cart((int)$id_cart); Context::getContext()->currency = new Currency((int)$cart->id_currency); Context::getContext()->customer = new Customer((int)$cart->id_customer); $bad_delivery = false; if (($bad_delivery = (bool)!Address::isCountryActiveById((int)$cart->id_address_delivery)) || !Address::isCountryActiveById((int)$cart->id_address_invoice)) { if ($bad_delivery) { $this->errors[] = $this->trans('This delivery address country is not active.', array(), 'Admin.Orderscustomers.Notification'); } else { $this->errors[] = $this->trans('This invoice address country is not active.', array(), 'Admin.Orderscustomers.Notification'); } } else { $employee = new Employee((int)Context::getContext()->cookie->id_employee); $result = $payment_module->validateOrder( (int)$cart->id, (int)$id_order_state, $cart->getOrderTotal(true, Cart::BOTH), $payment_module->displayName, $this->trans('Manual order -- Employee:', array(), 'Admin.Orderscustomers.Feature').' '. substr($employee->firstname, 0, 1).'. '.$employee->lastname, array(), null, false, $cart->secure_key ); if ($payment_module->currentOrder) { $reference = Tools::getValue('order_reference'); // <--- added these 5 lines if(!empty($reference)){ $order = new Order($payment_module->currentOrder); $order->reference = $reference; $order->update(); } Tools::redirectAdmin(self::$currentIndex.'&id_order='.$payment_module->currentOrder.'&vieworder'.'&token='.$this->token); } } } } parent::postProcess(); // use default behaviour } What'll happen when Ps will be upgraded ? ... good question... I think presta need a good project manager Link to comment Share on other sites More sharing options...
hhennes Posted February 6, 2018 Share Posted February 6, 2018 Hello, In order to add fields to back-office form(s) you can folow this tutorial ( in french ) Dynamic hooks are availables for this task https://www.h-hennes.fr/blog/2017/06/21/prestashop-ajouter-des-champs-dans-un-formulaire-dadministration/ Regards, Link to comment Share on other sites More sharing options...
speed-providing-uncl Posted February 6, 2018 Author Share Posted February 6, 2018 Hi hhennes, thanks for the link! I think I came accross this website some time ago, but unfortunately it doesn't work for the Create Order form as it appears to be a custom form Thanks Florian 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