VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Development & Testing => Topic started by: sealion on June 13, 2014, 18:18:00 PM

Title: Custom fields not working in 2.9.6
Post by: sealion on June 13, 2014, 18:18:00 PM
I am having problems getting the custom fields to work in Virtuemart 2.9.6, for example:-

,

Also if you try to create a custom field of the plugin type, this cannot be done properly because the section to specify the plugin parameters is not created once the plugin is selected.

I think I know why you are having these problems, in the table virtuemart_product_customfields you renamed three of the fields in VM 2.9:-
custom_value => customfield_value
custom_price => customfield_price
custom_params => customfield_params

I do get why you did this, I guess it was because these field names conflicted with the same field names for different variables in the virtuemart_customs table, so possibly it was a good idea to change them, however it has left you with some problems where there seem to be quite a few places in the code where this change has not been picked up. I am attaching a file where I have listed the problems that I can find. I have to say that I have not tested these, it is based on my understanding (such as it is) of how the relevant code works. Also the list is probably not exhaustive, there are some parts of the code, particularly to do with the custom_params, where my knowledge is not sufficient to suggest any changes.


[attachment cleanup by admin]
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on June 16, 2014, 10:51:16 AM
Thank you for this list. First I thought, what the heck you wanna tell me. The changes are the big difference between vm2 and vm3. There are more than 200 locations in the code.

But except your suggested change in "file components/com_virtuemart/views/category/view.html.php line 347", you are right. The sql in function getSearchCustom is outdated and just wrong. The stockable wont be updated. We suggest to use the dynamic childs instead.

But I think you just had bad luck. Only one type of the customs was not working and you tried that one. You may read here http://docs.virtuemart.net/tutorials/development/175-code-adjustments-for-virtuemart-3.html and help to complete it.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on June 16, 2014, 13:26:16 PM
Thanks for the link, it does make things clearer. I was just trying to help with the list, not be alarming, I am keen for it all to be working.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on June 16, 2014, 16:46:29 PM
I am happy for your testing. contact me in skype to get an updated version. PLeease :-)
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on June 17, 2014, 21:02:43 PM
Max, thanks for the updated version. I have been doing some testing with the custom fields, I have found some problems. I can probably debug  some of these for you, but it would help to know what is supposed to be working.

You say you are not supporting the stockable variants plugin, what about the other custom plugins, the text input and the specification plugin? Neither of these works at the moment.

You say to use the child variant field instead of the stockable plugin. I have been experimenting with this but it does lead to some problems with stock control. If the parent product is not orderable (so has zero stock) and you are using stock control then the only way to get it to display is to set 'Do not Display Product, if child products also out of stock'. But then if you have a child variant that is out of stock it still displays, and you can still add it to the cart, although you do get a warning as well that the product is out of stock. I think it is possible to solve this problem though, it just requires getting the logic right. However it might be an improvement to make the stock handling choice part of the generic cart variant field options, because for some products you might want to make the parent orderable and use stock control only with the parent If the only way to set this is in the Virtuemart configuration it is a bit limiting.

I think it is a good idea to stop the stockable variants plugin, I always found it very confusing to use, the child variant field is easier to understand. But I think some people will complain all the same, there are definitely sites out there that use it, for them it will become impossible to update.

Instead of the cart variant field type I see that you are using just the string field type with a custom price. This works now, except that the custom price is not saved when you edit the field. I am sure this can be debugged.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on June 17, 2014, 23:30:42 PM
The stockable variant and the generic child variants are exchangeable against each other. We can enhance the dynamic child variant with parameters very easy. Wont be a big problem to add your stocking idea.

The textinput plugin was working for me fine. Hmm I retest it. btw, please be sure that you tested the last version uploaded this evening http://dev.virtuemart.net/attachments/download/758/com_virtuemart.2.9.7_extract_first.zip

edit: I just felt myself in the trap that the plugin must have "is input" and "is cart attribute" checked. We should maybe move the trigger plgVmOnStoreInstallPluginTable over $table->bindChecknStore($data), so that we  can do this with the plugin to keep unnecessary support low.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on June 18, 2014, 20:43:58 PM
No, I did test the text input with cart attribute and cart input checked. I should have been clearer, the problem was that in the front end, when the product is viewed, nothing is displayed. Solution is, in plugins/vmcustom/textinput/textinput.php line 61 should be

function plgVmOnDisplayProductFEVM3(&$product,&$group) {


not

function plgVmOnDisplayProductFE(&$product,&$group) {


When you fix that the text input plugin seems to do what it should

I mentioned that the custom prices were not being saved, eg when using a string field as a cart variant, this is because of this:

file administrator/components/com_virtuemart/tables/product_customfields.php line 71

      if(!empty($this->custom_price)){

should be
      if(!empty($this->customfield_price)){



Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on June 18, 2014, 21:08:11 PM
yepp, thanks, I sent you already yesterday a fixed version. Atm I am thinking about how we can use the new and old triggers in the same plugin, but with the same name. Hmm....

lol damn I did it right in the function itself, but not the test to check if the function must be done. Thank you.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on July 07, 2014, 20:08:40 PM
Sorry I have not been in touch recently.

There is one thing I noticed in 2.9.7 which still seems to be in 2.9.8, for the date custom field type, when you view it in the front end the date drop-down selector does not work. This is due to the JQuery ui which defines the datepicker not being loaded in the front end, to fix it you just need to add a call to vmJsApi::js ('jquery-ui', FALSE, '', TRUE); in the jDate method in administrator/components/com_virtuemart/helpers/vmjsapi.php.

I will have a bit more time now to do some testing, I will do some testing on the custom plugins in VM 2.9.8 now, and will continue to post things as I find them.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on July 18, 2014, 20:06:07 PM
components/com_virtuemart/views/product_details/tmpl/default.php line 232

echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'ontop'));


should be

echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'onbottom'));
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 21, 2014, 13:09:16 PM
I have now


    // Show child categories
    if (VmConfig::get('showCategory', 1)) {
echo $this->loadTemplate('showcategory');
    }
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'onbottom'));
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'related_products','class'=> 'product-related-products'));
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'related_categories','class'=> 'product-related-categories'));

I wonder myself, maybe showcategory template should be the last line... maybe it should be


echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'related_categories','class'=> 'product-related-categories'));
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'related_products','class'=> 'product-related-products'));
echo shopFunctionsF::renderVmSubLayout('customfields',array('product'=>$this->product,'position'=>'onbottom'));
// Show child categories
if (VmConfig::get('showCategory', 1)) {
echo $this->loadTemplate('showcategory');
}
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 21, 2014, 13:14:15 PM
Quote from: moonaway on July 19, 2014, 09:43:28 AM
Why?

If the position is not specified, the output of related products is in the position of "normal". Here is an example: http://store25.eyemotion.ru/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=1&virtuemart_category_id=1&Itemid=121 (http://store25.eyemotion.ru/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=1&virtuemart_category_id=1&Itemid=121)

Yepp, seems I removed the fallback. So the updater needs a check to add related_products/related_categories to the positions.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 21, 2014, 13:15:30 PM
I think also now we should stick with onbot and not onbottom.

We cannot just update it, if people use an override.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on July 21, 2014, 14:36:23 PM
Yes, onbot is better, I had forgotten about this.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on July 22, 2014, 20:15:06 PM
A couple of minor points, in plugins/vmcustom/textinput/textinput.xml

line 23
            <field type="vmjpluginwarning"/>


should be

            <field type="vmjpluginwarning" addfieldpath="/administrator/components/com_virtuemart/fields"/>


At the moment the plugin warning is not displayed.

Also in the lines

    <updateservers>
        <!-- Note: No spaces or linebreaks allowed between the server tags -->
        <server type="extension" name="VirtueMart3 plg_vmcustom_textinput Update Site"><![CDATA[http://virtuemart.net/releases/vm3/plg_vmcustom_textinput_update.xml]]></server>
    </updateservers>


If you actually go to the URL http://virtuemart.net/releases/vm3/plg_vmcustom_textinput_update.xml (http://virtuemart.net/releases/vm3/plg_vmcustom_textinput_update.xml) the information there seems to be for the paypal plugin
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 25, 2014, 00:51:33 AM
<field type="vmjpluginwarning" addfieldpath="/administrator/components/com_virtuemart/fields"/>

isnt the path added above?
Title: Re: Custom fields not working in 2.9.6
Post by: sealion on July 25, 2014, 18:32:29 PM
No it's not:-

    <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>
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 25, 2014, 18:44:35 PM
Okey, how is the vm2.9.8a version?
Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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

public function parseCustomParams (&$field, $xParams = 'custom_params') {


I think should be

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

VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam);


Lines 99

$custom_params = json_decode ($field->customfield_params, TRUE);


and

$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 (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:-

$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

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.





Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on July 26, 2014, 16:01:32 PM
Quote from: sealion 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

public function parseCustomParams (&$field, $xParams = 'custom_params') {


I think should be

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

Quote from: sealion on July 25, 2014, 18:53:59 PM
Also line 118 should be

VmTable::bindParameterable ($field, 'customfield_params', $this->_varsToPushParam);


Lines 99

$custom_params = json_decode ($field->customfield_params, TRUE);


and

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


Quote from: sealion on July 25, 2014, 18:53:59 PM

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
Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo on August 02, 2014, 10:54:10 AM
you may take another look on the textinput plugin, there it works as expected.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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.
Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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:-

{"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

{"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.
Title: Re: Custom fields not working in 2.9.6
Post by: Milbo 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.
Title: Re: Custom fields not working in 2.9.6
Post by: rdcustom 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
Title: Re: Custom fields not working in 2.9.6
Post by: sealion 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

{"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

{"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

{"127":{"23":{"comment":"Sid"}},"128":{"23":{"comment":"Nancy"}}}
Title: Re: Custom fields not working in 2.9.6
Post by: rdcustom 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 :(