VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: Kuubs on October 07, 2020, 10:03:58 AM

Title: Override checkbox default custom field
Post by: Kuubs on October 07, 2020, 10:03:58 AM
Hello,

I have found that when you add a 1 to the database for the custom fields per product you get a disabled checkbox available in your product to disable the custom field, but not delete it. Because when you delete a custom field that value is also deleted in hte order list, so for example if you have a custom field color and Red is unavailable or sold out, you remove the color red. But that also means that the previously made orders that chose the color red do not have the color red anymore in the order itself.

So my solution was to disable the field rather than removing it altogether. But I can only have that disable checkbox if I have the override set to 1 in the database. Now I do that manually, but I want to add it so the default of the database is 1 rather than zero. Does anyone know how I can achieve this?

I tried changing the default to 1 in the database but it still gets 0 so I think somewhere in the code the making of the custom fields gets put in a 0 instaed of a 1 that I want.
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 12, 2020, 10:54:59 AM
Anyoen has an idea? Maybe overriding the core somewhere?
Title: Re: Override checkbox default custom field
Post by: Studio 42 on October 12, 2020, 17:10:52 PM
In this create a customfield plugin so you can manage all this problems yourself.
You can have so many specific cases
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 13, 2020, 09:24:21 AM
Quote from: Studio 42 on October 12, 2020, 17:10:52 PM
In this create a customfield plugin so you can manage all this problems yourself.
You can have so many specific cases

No I literally only have to set the override field in the database to 1. For all custom fields. Where can I do this?
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 15, 2020, 15:48:41 PM
Someone know how to do this? I absolutely need to implement this because it is a vital function right now in my webshops.
Title: Re: Override checkbox default custom field
Post by: Studio 42 on October 21, 2020, 10:41:28 AM
Quote from: Huubs on October 15, 2020, 15:48:41 PM
Someone know how to do this? I absolutely need to implement this because it is a vital function right now in my webshops.
You need a custom developement, it's not so easy to do and to explain.
1st is to verify on add to cart that the value is safe(because you cannot compare after if you remove a value a day)
After, because you know that the value is safe, you can directly render the value saved in the database.
You can only do this with a plugin, because you have to use another logic that the core customfield system.
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 24, 2020, 10:53:00 AM
Quote from: Studio 42 on October 21, 2020, 10:41:28 AM
Quote from: Huubs on October 15, 2020, 15:48:41 PM
Someone know how to do this? I absolutely need to implement this because it is a vital function right now in my webshops.
You need a custom developement, it's not so easy to do and to explain.
1st is to verify on add to cart that the value is safe(because you cannot compare after if you remove a value a day)
After, because you know that the value is safe, you can directly render the value saved in the database.
You can only do this with a plugin, because you have to use another logic that the core customfield system.

You are greatly misunderstanding my problem here. When you add a custom field and make a child the override checkbox comes up by default. You can disable the custom field for that specific child product. Now this can be achieved for normal porduct as well by adding a 1 to the override product_custom_field in teh database. Now I want to set this default to 1 so the custom field can be disbaled by the admin in the product overview.

I literally have to add a 1 instead of a 0 in the code, presumably the model code, so that the custom field database row gets inserted with a 1 to the override instead of 0. I tried setting it to default value of 1 in the database but that is not working.
Title: Re: Override checkbox default custom field
Post by: pinochico on October 24, 2020, 13:20:46 PM
If this code is not in core as you want, then for your project need custom developing.
Don't wait answer from the forum - forum is not free developers :)
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 26, 2020, 12:16:48 PM
Quote from: pinochico on October 24, 2020, 13:20:46 PM
If this code is not in core as you want, then for your project need custom developing.
Don't wait answer from the forum - forum is not free developers :)

I dont understand why you guys cannot seem to grasp what I want. I want to make a 0 a 1. I just want to know where the code islocated.
Title: Re: Override checkbox default custom field
Post by: jenkinhill on October 26, 2020, 16:59:58 PM
A zero is entered into the override column as the default value. This is from the installation SQL for the ###_virtuemart_product_customfields table:
`override` int(1) UNSIGNED NOT NULL DEFAULT '0',

For a pre-existing table you can change the default to 1, but this will only be applied for new entries:
ALTER TABLE `###_virtuemart_product_customfields` CHANGE `override` `override` INT(1) UNSIGNED NOT NULL DEFAULT '1';

You can export the database table to change existing entries using a suitable editor (I use NoteTab Pro) and re-import.

There is no code in the core to set overrides to 1 for all entries that I have been able to locate.
Title: Re: Override checkbox default custom field
Post by: Kuubs on October 27, 2020, 16:40:52 PM
Quote from: jenkinhill on October 26, 2020, 16:59:58 PM
A zero is entered into the override column as the default value. This is from the installation SQL for the ###_virtuemart_product_customfields table:
`override` int(1) UNSIGNED NOT NULL DEFAULT '0',

For a pre-existing table you can change the default to 1, but this will only be applied for new entries:
ALTER TABLE `###_virtuemart_product_customfields` CHANGE `override` `override` INT(1) UNSIGNED NOT NULL DEFAULT '1';

You can export the database table to change existing entries using a suitable editor (I use NoteTab Pro) and re-import.

There is no code in the core to set overrides to 1 for all entries that I have been able to locate.

Thank you!

EDIT: I changed it in the database and if I add a new custom field it does not autoamtically set it to override, it still isnerts a 0 at the new row.
Title: Re: Override checkbox default custom field
Post by: jenkinhill on October 27, 2020, 18:21:51 PM
Hmm the SQL worked on a test site on a subdomain of a live site on my VPS but on Xampp localhost it errors.
#1067 - Invalid default value for 'created_on'

I don't have time to look into this, but I do believe that changing the default value for override could provide a solution.