VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: OpenGlobal on May 13, 2012, 21:43:36 PM

Title: One code suggestion and one "WTF?!" for stockable variants plugin
Post by: OpenGlobal on May 13, 2012, 21:43:36 PM
I have one code suggestion for the stockable variants plugin.


if ($listoptions[0] == '') $html .= '';// <span style="width:98px; display: inline-block;color:#000;">'.JText::_('VMCUSTOM_STOCKABLE_NO_OPTION') .'</span>';
else $html .= JHTML::_('select.genericlist', $option, $name.'['.$selectoptions.']','style="width:100px !important;"','text','value',$childList[$child->id][$selectoptions],false,true)."\n";


in plgVmOnProductEdit() should be changed to:


if ($listoptions[0] == '' && $field->{'selectname'.$i}) $html .= '<input type="text" name="'.$name.'['.$selectoptions.']" value="'.$childList[$child->id][$selectoptions].'" style="width:100px;" />';
else if ($listoptions[0] == '') $html .= '';// <span style="width:98px; display: inline-block;color:#000;">'.JText::_('VMCUSTOM_STOCKABLE_NO_OPTION') .'</span>';
else $html .= JHTML::_('select.genericlist', $option, $name.'['.$selectoptions.']','style="width:100px !important;"','text','value',$childList[$child->id][$selectoptions],false,true)."\n";


This will mean that a single custom field config can be used for every product because it creates a text field rather than a dropdown list of options at the backend.

If I have product A available in 'red' and 'blue', product B available in 'blue' and 'black', product C available in 'turquoise' and 'taupe', product D available in 'mauve with mulberry stripes'.....etc.....I will need a stockable variant custom field each each separate product.

By implementing the code change above, I just need one stockable variant custom field 'Colour' and I can fill this in for each product.

Now, whilst looking into this, I've discovered why the "New" button doesn't do anything. I found the following code in plgVmOnProductEdit() which just made me think WTF:


                $script = "
        jQuery( function($) {
                $('#new_stockable_product').click(function() {
                        var Prod = $('#new_stockable');// input[name^=\"stockable\"]').serialize();

                        $.getJSON('index.php?option=com_virtuemart&view=product&task=saveJS&token=".JUtility::getToken()."' ,
                                {
                                        product_sku: Prod.find('input[name*=\"product_sku\"]').val(),
                                        product_name: Prod.find('input[name*=\"product_name\"]').val(),
                                        product_price: Prod.find('input[name*=\"product_price\"]').val(),
                                        product_in_stock: Prod.find('input[name*=\"product_in_stock\"]').val(),
                                        product_parent_id: ".$product_id.",
                                        published: 1,
                                        format: \"json\"
                                },
                                function(data) {
                                        //console.log (data);
                                        //$.each(data.msg, function(index, value){
                                                $(\"#new_stockable\").append(data.msg);
                                        //});
                                });
                });
        });
        ";
                $document = JFactory::getDocument();
                $document->addScriptDeclaration($script);
                // $html  ='<input type="text" value="'.$field['custom_name'].'" size="10" name="custom_param['.$row.'][custom_name]"> ';
                // $html .='<input type="text" value="'.$field['custom_size'].'" size="10" name="custom_param['.$row.'][custom_size]">';
                //$html .=JTEXT::_('VMCUSTOM_TEXTINPUT_NO_CHANGES_BE');
                $retValue .= $html;


This will not work because this function is being called via AJAX. You can't addScriptDeclaration() to an AJAX document. Instead, the only possible way that this can work is if the last line is changed to something like:


                $retValue .= $html.'<script type="text/javascript">'.$script.'</script>';


A lot of people are getting very annoyed that this essential functionality still doesn't work properly and there doesn't seem to be any progress being made. Would the powers that be like me to start submitting the bug fixes to SVN to get this moving? I'd much rather get this fixed than have to fork essential 'core' functionality into a separate plugin.

OpenGlobal
Title: Re: One code suggestion and one "WTF?!" for stockable variants plugin
Post by: Milbo on May 14, 2012, 23:43:51 PM
Of course we are happy, when you want to repair this plugin. Atm we work more on a child based solution. The plugin is atm more an example and need to be overhauled.