Author Topic: Custom fields not working in 2.9.6  (Read 8088 times)

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9607
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom fields not working in 2.9.6
« Reply #15 on: July 25, 2014, 00:51:33 am »
<field type="vmjpluginwarning" addfieldpath="/administrator/components/com_virtuemart/fields"/>

isnt the path added above?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #16 on: July 25, 2014, 18:32:29 pm »
No it's not:-

Code: [Select]
    <config>
        <fields name="params">
            <fieldset name="template">
            <field type="vmjpluginwarning"/>
            <field name="custom_size" type="text"  size="15"  default="10" label="VMCUSTOM_TEXTINPUT_SIZE" description="VMCUSTOM_TEXTINPUT_SIZE_DESC" />
            <field name="custom_price_by_letter" type="list"  default="0" label="VMCUSTOM_TEXTINPUT_PRICE_BY_LETTER_OR_INPUT" description="VMCUSTOM_TEXTINPUT_PRICE_BY_LETTER_OR_INPUT_DESC" >
                <option value="0">VMCUSTOM_TEXTINPUT_PRICE_BY_INPUT</option>
                <option value="1">VMCUSTOM_TEXTINPUT_PRICE_BY_LETTER</option>
            </field>
            </fieldset>
        </fields>
    </config>

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9607
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom fields not working in 2.9.6
« Reply #17 on: July 25, 2014, 18:44:35 pm »
Okey, how is the vm2.9.8a version?
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #18 on: July 25, 2014, 18:53:59 pm »
There seem to be some problems still in administrator/components/com_virtuemart/plugins/vmcustom.php line 91

Code: [Select]
public function parseCustomParams (&$field, $xParams = 'custom_params') {

I think should be

Code: [Select]
public function parseCustomParams (&$field, $xParams = 'customfield_params') {

But I don't think you are using this function any more, I can't find anywhere in the code that call it now.

Also line 118 should be

Code: [Select]
VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam);

Lines 99

Code: [Select]
$custom_params = json_decode ($field->customfield_params, TRUE);

and

Code: [Select]
$this->params = json_decode ($field->custom_params);

don't make sense any more, because the parameters don't seem to be in json format now (also should be $field->customfield_params)

I am having some problems with the plugin parameters, I am trying to adapt one of my own plugins for Virtuemart 3, it seems the best way to test the plugin system, I think I have followed your explanation here http://docs.virtuemart.net/tutorials/development/175-code-adjustments-for-virtuemart-3.html but when I try to use them in function plgVmOnProductEdit() I find that I still need a call to    VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam) for them to be defined. To be clear, in the constructor I am using:-

Code: [Select]
$this->varsToPush = array(
'media_id'=>array(0,'int'),'requires_registration'=>array(0,'int'),'shopper_groups'=>array(array(),'array'),'redirect_url'=>array('','char'),'title'=>array('','char'),'description'=>array('','char'),'loadStylesheet'=>array('','char')
);
$this->setConfigParameterable('customfield_params',$this->varsToPush);


Also I am including the triggers

Code: [Select]
function plgVmDeclarePluginParamsCustomVM3(&$data){
  return $this->declarePluginParams('custom', $data);
}
function plgVmGetTablePluginParams($psType, $name, $id, &$xParams, &$varsToPush){
  return $this->getTablePluginParams($psType, $name, $id, $xParams, $varsToPush);
}

but when I want to use the parameters, eg in function plgVmOnProductEdit() I find that I still need to include a call to VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam), otherwise the parameters are not defined. Clearly I am missing something somewhere, but I cannot see what.






sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #19 on: July 25, 2014, 19:00:21 pm »
Mostly I am finding the 2.9.8a version good, I am not finding lots of problems with it, it is only where I am looking very closely at the plugin system that I am finding problems. I think for general users if you were to release it as Virtuemart 3 then most users would be quite happy, but developers would complain a bit that the plugin system is still a bit buggy.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9607
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom fields not working in 2.9.6
« Reply #20 on: July 26, 2014, 16:01:32 pm »
There seem to be some problems still in administrator/components/com_virtuemart/plugins/vmcustom.php line 91

Code: [Select]
public function parseCustomParams (&$field, $xParams = 'custom_params') {

I think should be

Code: [Select]
public function parseCustomParams (&$field, $xParams = 'customfield_params') {

But I don't think you are using this function any more, I can't find anywhere in the code that call it now.
Yeh legacy. could be obsolete and nonsense maybe. I took your suggestion, so if someone forgot to exchange it, it could still work

Also line 118 should be

Code: [Select]
VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam);

Lines 99

Code: [Select]
$custom_params = json_decode ($field->customfield_params, TRUE);

and

Code: [Select]
$this->params = json_decode ($field->custom_params);

don't make sense any more, because the parameters don't seem to be in json format now (also should be $field->customfield_params)

Yepp, is for legacy there. I take your suggestion.



but when I want to use the parameters, eg in function plgVmOnProductEdit() I find that I still need to include a call to VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam), otherwise the parameters are not defined. Clearly I am missing something somewhere, but I cannot see what.


Hmm strange, maybe you should call the parent at the end of the constructor
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #21 on: August 01, 2014, 20:27:32 pm »
No, it's not that, I have tried calling the parent constructor at the end, also tried the beginning and middle, it makes no difference.

Never mind, it is not a big deal, because it is still possible to access the parameters by calling VmTable::bindParameterable(), it is just strange.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9607
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom fields not working in 2.9.6
« Reply #22 on: August 02, 2014, 10:54:10 am »
you may take another look on the textinput plugin, there it works as expected.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #23 on: August 05, 2014, 14:16:54 pm »
Yes I did look at the text input plugin very closely, I have been using it as the model for my own plugin. You are right, it does seem to work as expected, that is why I am so puzzled by this, I cannot see what I am doing that is different.

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #24 on: September 04, 2014, 19:10:25 pm »
There is also a problem with saving the custom field data in the product attribute field in the virtuemart_order_items table - this seems to apply to latest version 2.9.9 and all previous versions of 2.9. The problem is that it is only possible to attach one plugin field of a particular type to a product and have the field data correctly stored in the order. It is because the product attribute is stored in the virtuemart_order_items table in a format like this:-

Code: [Select]
{"26":125,"23":{"128":{"comment":""}}}
this is an array where the keys (in this example 26 and 23) are the virtuemart_custom_id for the custom field, the problem is that if you have two custom fields of the same type then the virtuemart_custom_id is the same, so the array key is the same, and the data for the first instance is overwritten by the data for the second instance. It means for example that you would not be able to have two text input fields for a product. I don't know how much of a limitation this is, but it is certainly possible that for some plugin field types you would want to be able to have more than one instance.

This was not a problem before Virtuemart 2.9, because in earlier versions the virtuemart_customfield_id was used as the array key. This will always be unique to a particular field instance so the problem does not arise, in this example it would mean rewriting the array as

Code: [Select]
{"125":26,"128":{"23":{"comment":""}}}
I don't know why you changed things around, it seems to be a bit of a mistake to do that.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9607
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Custom fields not working in 2.9.6
« Reply #25 on: September 04, 2014, 21:08:15 pm »
I tested it with the textinput. To have two times the same textinput and it works as expected.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rdcustom

  • Beginner
  • *
  • Posts: 4
Re: Custom fields not working in 2.9.6
« Reply #26 on: September 05, 2014, 18:36:36 pm »
hi.
i am having issues with custom fields too.

joomla 3.3.3
vm 2.9.9b

when i add a custom field to a product, i can see it in the product page, but when i select the option the price don't update and in the cart i don't see any variant.

in the order too, of course

sealion

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 53
    • Spiral Scripts
Re: Custom fields not working in 2.9.6
« Reply #27 on: September 05, 2014, 19:07:51 pm »
But if you have two times the same text input attached to a product, only the input data from the second instance will be saved in the order.

What I mean is, suppose the site owner creates a text input field in the products->custom fields admin section. This custom field is stored in the database table virtuemart_customs with virtuemart_custom_id number of 23.

The site owner creates a product, it is a T-shirt which allows the customer to print two names on it, so it requires two input fields, so the product has two instances of the text input field that has just been created attached to it, one for each name, these are stored in the database table virtuemart_product_customfields with virtuemart_customfield_id of 127 and 128. Note that both these fields will have the same virtuemart_custom_id of 23.

Now a customer buys a T-shirt, they put the names Sid and Nancy into the two input fields, this data is saved as the product attribute in the virtuemart_order_items table entry for the product, it will be saved as

Code: [Select]
{"23":{"128":{"comment":"Nancy"}}}
This is because both the custom fields have the same key, which is the virtuemart_custom_id, so the first entry just gets forgotten.

There is a way to avoid this problem, by at the beginning in the admin products->custom fields, creating two text input fields, text input 1 and text input 2, then these would be stored in the virtuemart_customs table with for example id numbers of 23 and 24 for the virtuemart_custom_id field.

Then to attach two fields to a product you would attach one instance of text input 1 and one instance of text input 2, then when the customer buys the product the data should be stored correctly in the virtuemart_order_items table as

Code: [Select]
{"23":{"127":{"comment":"Sid"}},"24":{"128":{"comment":"Nancy"}}}
This should work but it is a bit cumbersome, you can bet people would be confused by having to do things this way.

As I mentioned before you do not have this problem in Virtuemart 2 because the virtuemart_customfield_id is used as the array key.

If you used the virtuemart_customfield_id as the array key then the key is always unique, you can have two instances of the same text input field attached to a product, and in my example the data could be saved as

Code: [Select]
{"127":{"23":{"comment":"Sid"}},"128":{"23":{"comment":"Nancy"}}}

rdcustom

  • Beginner
  • *
  • Posts: 4
Re: Custom fields not working in 2.9.6
« Reply #28 on: September 06, 2014, 15:08:42 pm »
Just re-installed vm, tried to check EVERYTHING in settings, overrides etc, but custom fields still not working. I have not developing skill, I need an input to find the problem :(