paddle07 Posted December 10, 2013 Share Posted December 10, 2013 Hi I build a custom products field module following this tutorial: http://nemops.com/prestashop-products-new-tabs-fields/ I added the shop id as I'm using multistore. Everything works fine until I want to update an existing product… as soon as I edit a product (e.g. price or quantity) and save it (either with save and stay or save) the content of the custom field turns blank. The content of the custom field is only saved correctly when I click on the “custom-field-Tab” before I save e.g. a new price… Here's my hookActionProductUpdate code: public function hookActionProductUpdate($params) { // get all languages // for each of them, store the new field $id_product = $params['product']->id; $id_shop = $this->context->shop->id; $languages = Language::getLanguages(true); foreach ($languages as $lang) { if(!Db::getInstance()->update('product_lang', array('custom_field'=> pSQL(Tools::getValue('custom_field_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_shop = ' .$id_shop. ' AND id_product = ' .$id_product )) $this->context->controller->_errors[] = Tools::displayError('Error: ').mysql_error(); } } Thanks! Link to comment Share on other sites More sharing options...
bellini13 Posted December 11, 2013 Share Posted December 11, 2013 you are probably erasing the content in the database when you click on save. The product tabs are probably not being loaded unless you click on the tab. Prestashop uses ajax to load the tab data when you click on the tab. So if you do not click the tab, then the content is blank, and clicking on save will execute your hook and your hook is saving blank to the database. Link to comment Share on other sites More sharing options...
nozzula Posted January 27, 2014 Share Posted January 27, 2014 Hi, here a solution is proposed by Jeff (see comments) I've found how to solve your bug in hookActionProductUpdate, you've to check if POST vars are set before save it with Tools::getIsset. public function hookActionProductUpdate($params){// get all languages// for each of them, store the new field$id_product = (int)Tools::getValue('id_product');$languages = Language::getLanguages(true);foreach ($languages as $lang) {if (Tools::getIsset('custom_field_'.$lang['id_lang']))if(!Db::getInstance()->update('product_lang', array('custom_field'=> pSQL(Tools::getValue('custom_field_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_product = ' .$id_product ))$this->context->controller->_errors[] = Tools::displayError('Error: ').mysql_error();}} 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