Jump to content

How to add custom field(int) for product quantity page on the backend?


VBLED

Recommended Posts

My PS version is 8.0.4,  I want to add extra fields show on the backend product quantity page, not for front.

There are some modules on the market, but can only add text, images, checkbox, video, but no integer type.

Can somebody help?

Link to comment
Share on other sites

Hi.

You can also enter a number in the text field.
All you have to do is add javascript, which does not allow you to enter anything other than the range 0..9
For example, you add the actionAdminControllerSetMedia hook in the module and map the javascript.

public function hookActionAdminControllerSetMedia($params)
    {
        if ($this->context->controller->php_self == 'AdminProducts' && Tools::getValue('id_product'))
        {
            $this->context->controller->addJs(_PS_MODULE_DIR_.$this->name.'/views/js/admin/adminProduct.js');
        } 
    }

and javascript:

$(document).ready(function() {
    /* text field => my_text_field */
    $('[name=my_text_field]').keypress(function (e) {
        var charCode = (e.which) ? e.which : e.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
    });
});

 

Edited by ps8moduly.cz (see edit history)
Link to comment
Share on other sites

8 hours ago, VBLED said:

Thank you but this is not good idea.

Because I want to calculate these fields, so they must be int type.

I don't know why all custom field modules are only support text fields, numbers are not support.

Note that javascript is less tolerant than PHP. In javascript you almost always need to use parseInt or parseFloat if you want to use a field value for calculation.

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...