limitcracker Posted August 10, 2020 Share Posted August 10, 2020 (edited) Hi, What else I need in order make some custom fields in Product class and save them in columns I created in ps_product table? If get some errors like: Unknown column 'price_recent1' in 'field list' What I have done: I tweaked Product.php in order to add the three fields: ... class ProductCore extends ObjectModel { ... public $price_recent1; public $price_recent2; public $price_recent3; ... 'price_recent1' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'), 'price_recent2' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'), 'price_recent3' => array('type' => self::TYPE_STRING, 'shop' => true, 'validate' => 'isString'), ... } then in mymodule.php I added the displayAdminProductsExtra hook in order to display a Tab inside the product edit backoffice: public function hookDisplayAdminProductsExtra($params) { global $smarty; $product = new Product((int)Tools::getValue('id_product')); if (Validate::isLoadedObject($product)) { $this->context->smarty->assign(array( 'price_recent1' => $product->price_recent1, 'price_recent2' => $product->price_recent2, 'price_recent3' => $product->price_recent3)); return $this->display(__FILE__, 'views/templates/admin/sleed.tpl'); } } and finally I display them in mymodule.tpl: <div id="mymodule" class="panel product-tab"> <input type="hidden" name="submitted_tabs[]" value="mymodule" /> <h3 class="tab"><i class="icon-info"></i> {l s='MyModule'}</h3> <div class="form-group"> <label class="control-label col-lg-3" for="price_recent1"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #1'}"> {l s='Recent Price #1'} </span> </label> <div class="col-lg-9"> <input type="text" id="price_recent1" name="price_recent1" value="{$product->price_recent1|htmlentitiesUTF8}"/> </div><br> <label class="control-label col-lg-3" for="price_recent2"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #2'}"> {l s='Recent Price #2'} </span> </label> <div class="col-lg-9"> <input type="text" id="price_recent2" name="price_recent2" value="{$product->price_recent2|htmlentitiesUTF8}"/> </div><br> <label class="control-label col-lg-3" for="price_recent3"> <span class="label-tooltip" data-toggle="tooltip" title="{l s='Recent Price #3'}"> {l s='Recent Price #3'} </span> </label> <div class="col-lg-9"> <input type="text" id="price_recent3" name="price_recent3" value="{$product->price_recent3|htmlentitiesUTF8}"/> </div><br> </div> <div class="panel-footer"> <a href="{$link->getAdminLink('AdminProducts')|escape:'html':'UTF-8'}{if isset($smarty.request.page) && $smarty.request.page > 1}&submitFilterproduct={$smarty.request.page|intval}{/if}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a> <button type="submit" name="submitAddproduct" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> {l s='Save'}</button> <button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right" disabled="disabled"><i class="process-icon-loading"></i> {l s='Save and stay'} </button> </div> Thanks for your time! -John Edited August 10, 2020 by limitcracker (see edit history) Link to comment Share on other sites More sharing options...
Minsky_ae Posted August 11, 2020 Share Posted August 11, 2020 Hi @limitcracker, Here it's a French tutorial but by checking the source code of the module, you might be able to find help maybe. :)https://www.arnaud-merigeau.fr/prestashop-1-7-ajouter-des-champs-texte-aux-produits-2/ Link to comment Share on other sites More sharing options...
limitcracker Posted August 11, 2020 Author Share Posted August 11, 2020 Hi @Minsky_ae I think I posted under international section. Where else I could post for more to see? Br, John Link to comment Share on other sites More sharing options...
Minsky_ae Posted August 12, 2020 Share Posted August 12, 2020 Hi @limitcracker, You did! It's just that I don't have this resource in English. :( But you might not need to read the post, just download the module and check the source code. Link to comment Share on other sites More sharing options...
iipa Posted August 17, 2020 Share Posted August 17, 2020 Have you added the new fields into database? Check post below how to do it: https://www.prestashop.com/forums/topic/288826-solved-installdb-not-created-in-database/ Link to comment Share on other sites More sharing options...
limitcracker Posted August 17, 2020 Author Share Posted August 17, 2020 (edited) 11 hours ago, iipa said: Have you added the new fields into database? Check post below how to do it: https://www.prestashop.com/forums/topic/288826-solved-installdb-not-created-in-database/ Hi, yes I did. But I did using ALTER TABLE queries and they are working fine. I managed to solve the problem by also creating the columns also in ps_product_shop table! I don't know why it was required though. I was developing in PS 1.6.1.9 Br, John Edited August 17, 2020 by limitcracker (see edit history) 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