VirtueMart Forum

VirtueMart 2 + 3 + 4 => Product creation => Topic started by: cybgak on April 27, 2012, 18:22:08 PM

Title: Core code fix for generic child variants
Post by: cybgak on April 27, 2012, 18:22:08 PM
After spending hours trying to get Generic child variants to work on Virtuemart 2.06 I finally came up with this solution.
It alters the drop down box for Generic child variants to display the contents of the internal notes field for the product so you can have custom text for each option rather than it displaying the same product name.
It also allows you to have the same product name for the parent and child products so it looks correct in the category view and when you make selections in the drop down the name remains constant.
The drop down box now also includes the price so the customer can see how much each variant costs without clicking on each one in turn...

Anyway here's the code changes: (Lines marked < are the old code and lines marked > are the replacement code just so you can see what's changed)

\administrator\components\com_virtuemart\models\customfields.php line 763

<               $options[] = array( 'value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id='.$virtuemart_category_id.'&virtuemart_product_id='.$child['virtuemart_product_id']),'text' =>$child['product_name'] );

>               $options[] = array( 'value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id='.$virtuemart_category_id.'&virtuemart_product_id='.$child['virtuemart_product_id']) ,'text' =>$child['intnotes'].': '.$currency->priceDisplay((float)$child['price']) );


\administrator\components\com_virtuemart\models\product.php line 1538

<                       USING (`virtuemart_product_id`)  ';

>                       USING (`virtuemart_product_id`)
>                      LEFT JOIN `#__virtuemart_product_prices` as pp
>                      USING (`virtuemart_product_id`) ';


Hope that's some use to everyone, it was driving me nuts!

P.S. If anyone knows how to achieve this without hacking the core code I'd love to know how :-)
Title: Re: Core code fix for generic child variants
Post by: Georgios Kolomvos on June 10, 2012, 14:12:04 PM
Quote from: cybgak on April 27, 2012, 18:22:08 PM
It alters the drop down box for Generic child variants to display the contents of the internal notes field for the product so you can have custom text for each option rather than it displaying the same product name.
This is a great hack cybgak
But there is a problem with the cart module: when the product is added to the cart, it doesn't show the variant characteristic (i.e. the  internal notes value), so that the shopper can see that he has ordered the right product variant.
It would be great if we could found a way to add the "intnotes" to the cart product row (e.g. concat product name and intnotes fields in the cart product row)

I tried to make such a hack but i am not that competent with php and Virtuemart coding.
Could you please have a look to it?   
Title: Re: Core code fix for generic child variants
Post by: jjk on June 10, 2012, 15:48:59 PM
Quote from: cybgak on April 27, 2012, 18:22:08 PM
P.S. If anyone knows how to achieve this without hacking the core code I'd love to know how :-)

You can enter child product names which are either different or identical  to the parent product, which will be used in the dropdown - whatever you like, without hacking the code. But the 'Product Alias" ("Slug" in the database table) has to be unique.

However, I think adding the price to each option is a good idea.
Title: Re: Core code fix for generic child variants
Post by: Parsimonious on June 10, 2012, 19:37:07 PM
Quote from: jjk on June 10, 2012, 15:48:59 PM
Quote from: cybgak on April 27, 2012, 18:22:08 PM
P.S. If anyone knows how to achieve this without hacking the core code I'd love to know how :-)

You can enter child product names which are either different or identical  to the parent product, which will be used in the dropdown - whatever you like, without hacking the code. But the 'Product Alias" ("Slug" in the database table) has to be unique.

However, I think adding the price to each option is a good idea.

Yes, you can change the child name, but I name my products with the brand and what it is which can make it a bit long. It's nicer to have short easy to read choices in the dropdown for the customer. EG my child product name might be "Zuo Modern Wilco Dining Table - White", but I'd just like "White $xxx" to be in the drop down. Otherwise I have to compromise on naming for the sake of simplicity in the drop down. EG "Wilco - White", but I don't like this short hand so much as the displayed title for the product. Including prices beside each would be great!
Title: Re: Core code fix for generic child variants
Post by: Georgios Kolomvos on June 10, 2012, 19:42:06 PM
Quote from: jjk on June 10, 2012, 15:48:59 PM
You can enter child product names which are either different or identical  to the parent product, which will be used in the dropdown - whatever you like, without hacking the code.
The problem is that it is not nice to repeat the product name in the dropdown list, for example the product "T-Shirt JoomlaDay" comes to 5 colors, then the drop down list will be:
T-shirt JoomlaDay red
T-shirt JoomlaDay green
T-shirt JoomlaDay yellow
T-shirt JoomlaDay gray
T-shirt JoomlaDay blue

It would be more natural for the dropdown list to have just the color options:
Red
Green
Yellow
Gray
Blue

So cybgak's solution covers this need.

Generally, Virtuemart 2 is a real disapointment regarding product attributes/children:
The "Generic Child Variant" option has no bugs but it has many limitations (the name of the product is in the dropdown list, when the user chooses a child product the page reloads instead of changing with AJAX only the product's data the way that VM1.1 did, it has problem with more than 2 layers of inheritance, etc).
The other option "VM custom - stockable variant plugin" option has tragically many bugs (practically does not work).

I hope VM2 will soon mature regarding this matter...
Title: Re: Core code fix for generic child variants
Post by: jjk on June 10, 2012, 20:51:32 PM
In your case it might be better to use this one: http://forum.virtuemart.net/index.php?topic=99678.0 (http://forum.virtuemart.net/index.php?topic=99678.0)
Title: Re: Core code fix for generic child variants
Post by: Parsimonious on June 10, 2012, 21:12:13 PM
Quote from: jjk on June 10, 2012, 20:51:32 PM
In your case it might be better to use this one: http://forum.virtuemart.net/index.php?topic=99678.0 (http://forum.virtuemart.net/index.php?topic=99678.0)

Thanks, but each variation needs a sku so we can feed to price comparison sites. The generic child varients seem to work for what I need. It would just be better with a few tweeks.
Title: Re: Core code fix for generic child variants
Post by: Georgios Kolomvos on June 10, 2012, 22:15:45 PM
Quote from: jjk on June 10, 2012, 20:51:32 PM
In your case it might be better to use this one: http://forum.virtuemart.net/index.php?topic=99678.0 (http://forum.virtuemart.net/index.php?topic=99678.0)
Nice plugin, i will certainly use it sometime.
But the main problem is stock control and this can be done only with child products. So we need a reliable and flexible solution for child products.
Is there any other solution for child products except for "Generic child variant" and "VM custom - stockable variants plugin"? This is the big issue.
Title: Re: Core code fix for generic child variants
Post by: uschmi on June 10, 2012, 23:24:44 PM
I agree to gkolomvos.
The buggy stock control for childs is a very very big drawback for VM 2!
I´m using VM 2.0.6 on a live site and have to do my stock control / inventory by Excel sheets :(
Title: Re: Core code fix for generic child variants
Post by: Milbo on June 14, 2012, 22:01:57 PM
We are enhancing this. We see it ourself as the biggest problem in vm2. We are quite happy with the rest. The vmcustoms will be rewritten for vm2.2 !
Title: Re: Core code fix for generic child variants
Post by: Parsimonious on June 14, 2012, 22:46:20 PM
Good to hear. Is there a rough estimate on ETA for this?
Title: Re: Core code fix for generic child variants
Post by: mowgs on June 15, 2012, 08:14:33 AM
Quote from: Milbo on June 14, 2012, 22:01:57 PM
We are enhancing this. We see it ourself as the biggest problem in vm2. We are quite happy with the rest. The vmcustoms will be rewritten for vm2.2 !

Will this be based around the generic child variants, or the stockable variants plugin?
Title: Re: Core code fix for generic child variants
Post by: sukhrob on July 03, 2012, 09:51:52 AM
OMG, thank you so much!

It was driving me insane as well, that I couldn't use internal notes.

This is great fix. Should be added to the next update for sure, at least temporary.
Title: Re: Core code fix for generic child variants
Post by: en jie rudd on February 25, 2014, 00:41:33 AM
Quote from: cybgak on April 27, 2012, 18:22:08 PM
After spending hours trying to get Generic child variants to work on Virtuemart 2.06 I finally came up with this solution.
It alters the drop down box for Generic child variants to display the contents of the internal notes field for the product so you can have custom text for each option rather than it displaying the same product name.
It also allows you to have the same product name for the parent and child products so it looks correct in the category view and when you make selections in the drop down the name remains constant.
The drop down box now also includes the price so the customer can see how much each variant costs without clicking on each one in turn...

Anyway here's the code changes: (Lines marked < are the old code and lines marked > are the replacement code just so you can see what's changed)

\administrator\components\com_virtuemart\models\customfields.php line 763

<               $options[] = array( 'value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id='.$virtuemart_category_id.'&virtuemart_product_id='.$child['virtuemart_product_id']),'text' =>$child['product_name'] );

>               $options[] = array( 'value' => JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_category_id='.$virtuemart_category_id.'&virtuemart_product_id='.$child['virtuemart_product_id']) ,'text' =>$child['intnotes'].': '.$currency->priceDisplay((float)$child['price']) );


\administrator\components\com_virtuemart\models\product.php line 1538

<                       USING (`virtuemart_product_id`)  ';

>                       USING (`virtuemart_product_id`)
>                      LEFT JOIN `#__virtuemart_product_prices` as pp
>                      USING (`virtuemart_product_id`) ';


Hope that's some use to everyone, it was driving me nuts!

P.S. If anyone knows how to achieve this without hacking the core code I'd love to know how :-)

:( Please help! I am not a programmer, but can do simple code changes following instructions.

I need this function (generic child variant prices displayed in the drop down list) badly and feel I am half way there. I have managed the first part of the code change (customfields.php) with sings of price now showing in the drop down but with '0' value. I could not proceed with the second part of the code change as in my 'product.php line 1538' there is no '  USING (`virtuemart_product_id`)  ';'. I may need a few more lines before or after, or info on the section of the php file to be able to make the second part of the change and test it out.

Can someone please help?!

Thank you very much in advance.

regards

En Jie
Title: Re: Core code fix for generic child variants
Post by: en jie rudd on February 28, 2014, 09:22:44 AM
 can someone please help here! :(

I use vm 2.0.26 and the above is one of the latest a couple of issues I need to fix before getting my site up. The code must have changed as there is no '<  USING (`virtuemart_product_id`)  ';' anywhere near line 1538. I just need a bit the context for this code change to achieve the desired result - having child product prices in the drop down.

Will really appreciate it if someone can help out here.

best regards

En Jie
Title: Re: Core code fix for generic child variants
Post by: en jie rudd on February 28, 2014, 22:24:24 PM
Happy to pay for above job if anyone can help out.

regards

En Jie
Title: Re: Core code fix for generic child variants
Post by: hyperpower777 on March 17, 2014, 07:14:15 AM
I would like to know how to do this on virtuemart 2.0.26 too
Title: Re: Core code fix for generic child variants
Post by: mark R on April 09, 2014, 23:36:32 PM
Hi All,

Has any one had any joy implementing this into VM 2.6... would be great to be able to have shorter variant name (XL), but still have the full name in the cart (T-shirt Blue XL)

Many thanks
Mark
Title: Re: Core code fix for generic child variants
Post by: klattr1 on April 15, 2014, 09:01:16 AM
^ I want to know as well. Would be a very useful feature.