Jump to content

Adding new checkbox on Product Information problem


tarunn

Recommended Posts

Hi there,

 

I'm having a bit of a problem with creating new check boxes on the Information tabs - The check boxes show and are ticked based on the database entry of 1, but when I try to untick, it doesn't save. Funnily enough, if the database has a 0, the checkbox is unticked, and will save if I tick it.

 

Can anyone help?

 

I have the following:

 

In the database (ps_product and ps_product_shop) i have:

  • custom_field1 - tinyint(1) - default(1)
  • custom_field2 - tinyint(1) - default(1)

In the informations.tpl:

<div class="checkbox">
    <label for="custom_field1">
	<input type="checkbox" name="custom_field1" id="custom_field1" value="1" {if $product->custom_field1}checked="checked"{/if} >
	{l s='Custom Field 1'}
    </label>
</div>
                    
<div class="checkbox">
    <label for="custom_field2">
	<input type="checkbox" name="custom_field2" id="custom_field2" value="1" {if $product->custom_field2}checked="checked"{/if} >
	{l s='Custom Field 2'}
    </label>
</div>

In the product.php override:

public $custom_field1 = false;
public $custom_field2 = false;
    
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
    self::$definition['fields']['custom_field1'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');
    self::$definition['fields']['custom_field2'] = array('type' => self::TYPE_BOOL, 'shop' => true, 'validate' => 'isBool');

    parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }

For some reason, this isn't working as described.

 

Can anyone help?

 

Thank you!

Edited by tarunn (see edit history)
Link to comment
Share on other sites

Ah thank you ever so much,

 

Just for everyone's knowledge, I put the following in an override (AdminProductsController.php)

protected function copyFromPost(&$object, $table)
{
    if ($this->isTabSubmitted('Informations'))
    {
    if ($this->checkMultishopBox('custom_field1', $this->context)){ 
         $object->custom_field1 = (int)Tools::getValue('custom_field1'); 
    } 

    if ($this->checkMultishopBox('custom_field2', $this->context))
    { 
         $object->custom_field2 = (int)Tools::getValue('custom_field2'); 
    }

    }

}
Edited by TeapotDan (see edit history)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...