News:

Support the VirtueMart project and become a member

Main Menu

Core code fix for generic child variants

Started by cybgak, April 27, 2012, 18:22:08 PM

Previous topic - Next topic

cybgak

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 :-)

Georgios Kolomvos

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?   
Georgios Kolomvos
Patras, Greece

jjk

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.
Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Parsimonious

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!

Georgios Kolomvos

#4
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...
Georgios Kolomvos
Patras, Greece

jjk

Non-English Shops: Are your language files up to date?
http://virtuemart.net/community/translations

Parsimonious

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

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.

Georgios Kolomvos

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
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.
Georgios Kolomvos
Patras, Greece

uschmi

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

Milbo

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 !
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Parsimonious

Good to hear. Is there a rough estimate on ETA for this?

mowgs

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?

sukhrob

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.

en jie rudd

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

en jie rudd

 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