Thymotep Posted November 13, 2015 Share Posted November 13, 2015 Hello, I want to add fields to the sheet via an override of the product class, but it does not. For Product.php in override/classes : <?php class Product extends ProductCore { public $is_marking = false; public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null) { self::$definition['fields']['is_marking'] = array('type' => self::TYPE_BOOL, 'validate' => 'isBool'); parent::__construct($id_product, $id_lang, $id_shop); } } For informations.tpl in override/controllers/admin/templates/products/informations.tpl, i have added these lines just after online_only checkbox : <div class="checkbox"> <label for="is_marking"> <input type="checkbox" name="is_marking" id="is_marking" value="{$product->is_marking}" {if $product->is_marking}checked="checked"{/if} > {l s='Marking product'}</label> </div> For AdminProductsController.php in /override/controllers/admin/AdminProductsController.php : <?php class AdminProductsController extends AdminProductsControllerCore { protected function copyFromPost(&$object, $table) { parent::copyFromPost($object, $table); if (get_class($object) != 'Product') return; /* Additional fields */ $languages = Language::getLanguages(false); foreach ($languages as $language) if (isset($_POST['meta_keywords_'.$language['id_lang']])) { $_POST['meta_keywords_'.$language['id_lang']] = $this->_cleanMetaKeywords(Tools::strtolower($_POST['meta_keywords_'.$language['id_lang']])); // preg_replace('/ *,? +,* /', ',', strtolower($_POST['meta_keywords_'.$language['id_lang']])); $object->meta_keywords[$language['id_lang']] = $_POST['meta_keywords_'.$language['id_lang']]; } $_POST['width'] = empty($_POST['width']) ? '0' : str_replace(',', '.', $_POST['width']); $_POST['height'] = empty($_POST['height']) ? '0' : str_replace(',', '.', $_POST['height']); $_POST['depth'] = empty($_POST['depth']) ? '0' : str_replace(',', '.', $_POST['depth']); $_POST['weight'] = empty($_POST['weight']) ? '0' : str_replace(',', '.', $_POST['weight']); if (Tools::getIsset('unit_price') != null) $object->unit_price = str_replace(',', '.', Tools::getValue('unit_price')); if (Tools::getIsset('ecotax') != null) $object->ecotax = str_replace(',', '.', Tools::getValue('ecotax')); if ($this->isTabSubmitted('Informations')) { $object->available_for_order = (int)Tools::getValue('available_for_order'); $object->show_price = $object->available_for_order ? 1 : (int)Tools::getValue('show_price'); $object->online_only = (int)Tools::getValue('online_only'); $object->is_marking = (int)Tools::getValue('is_marking'); } if ($this->isTabSubmitted('Prices')) $object->on_sale = (int)Tools::getValue('on_sale'); } public function initFormInformations($product) { if (!$this->default_form_language) $this->getLanguages(); $data = $this->createTemplate($this->tpl_form); $currency = $this->context->currency; $data->assign('languages', $this->_languages); $data->assign('default_form_language', $this->default_form_language); $data->assign('currency', $currency); $this->object = $product; //$this->display = 'edit'; $data->assign('product_name_redirected', Product::getProductName((int)$product->id_product_redirected, null, (int)$this->context->language->id)); /* * Form for adding a virtual product like software, mp3, etc... */ $product_download = new ProductDownload(); if ($id_product_download = $product_download->getIdFromIdProduct($this->getFieldValue($product, 'id'))) $product_download = new ProductDownload($id_product_download); $product->{'productDownload'} = $product_download; $product_props = array(); // global informations array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order', 'show_price', 'online_only', 'id_manufacturer', 'is_marking' ); // specific / detailled information array_push($product_props, // physical product 'width', 'height', 'weight', 'active', // virtual product 'is_virtual', 'cache_default_attribute', // customization 'uploadable_files', 'text_fields' ); // prices array_push($product_props, 'price', 'wholesale_price', 'id_tax_rules_group', 'unit_price_ratio', 'on_sale', 'unity', 'minimum_quantity', 'additional_shipping_cost', 'available_now', 'available_later', 'available_date' ); if (Configuration::get('PS_USE_ECOTAX')) array_push($product_props, 'ecotax'); foreach ($product_props as $prop) $product->$prop = $this->getFieldValue($product, $prop); $product->name['class'] = 'updateCurrentText'; if (!$product->id || Configuration::get('PS_FORCE_FRIENDLY_PRODUCT')) $product->name['class'] .= ' copy2friendlyUrl'; $images = Image::getImages($this->context->language->id, $product->id); if (is_array($images)) { foreach ($images as $k => $image) $images[$k]['src'] = $this->context->link->getImageLink($product->link_rewrite[$this->context->language->id], $product->id.'-'.$image['id_image'], 'small_default'); $data->assign('images', $images); } $data->assign('imagesTypes', ImageType::getImagesTypes('products')); $product->tags = Tag::getProductTags($product->id); $data->assign('product_type', (int)Tools::getValue('type_product', $product->getType())); $data->assign('is_in_pack', (int)Pack::isPacked($product->id)); $check_product_association_ajax = false; if (Shop::isFeatureActive() && Shop::getContext() != Shop::CONTEXT_ALL) $check_product_association_ajax = true; // TinyMCE $iso_tiny_mce = $this->context->language->iso_code; $iso_tiny_mce = (file_exists(_PS_ROOT_DIR_.'/js/tiny_mce/langs/'.$iso_tiny_mce.'.js') ? $iso_tiny_mce : 'en'); $data->assign('ad', dirname($_SERVER['PHP_SELF'])); $data->assign('iso_tiny_mce', $iso_tiny_mce); $data->assign('check_product_association_ajax', $check_product_association_ajax); $data->assign('id_lang', $this->context->language->id); $data->assign('product', $product); $data->assign('token', $this->token); $data->assign('currency', $currency); $data->assign($this->tpl_form_vars); $data->assign('link', $this->context->link); $data->assign('PS_PRODUCT_SHORT_DESC_LIMIT', Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT') ? Configuration::get('PS_PRODUCT_SHORT_DESC_LIMIT') : 400); $this->tpl_form_vars['product'] = $product; $this->tpl_form_vars['custom_form'] = $data->fetch(); } } And in my database, i have added "is_marking" field in product table. The display goes well in the back office, but the value is not saved, and I do not understand why. Did I forget something? Could someone help me? thank you in advance! Thymotep Link to comment Share on other sites More sharing options...
Thymotep Posted November 18, 2015 Author Share Posted November 18, 2015 No one to help me solve my problem? Link to comment Share on other sites More sharing options...
Thymotep Posted November 18, 2015 Author Share Posted November 18, 2015 I solved my problem with this message : https://www.prestashop.com/forums/topic/354986-custom-product-field-not-changeable/?p=1795472 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