Required (mandatory) custom fields (select list, cart variant) in Virtuemart 2

Started by nick-gr, April 15, 2014, 19:37:30 PM

Previous topic - Next topic

nick-gr

Hello Folks!

Could you help me please. I spend a few days trying to find solution, but didn't succeed and my brain is  exploding.
So the problem is: I'm trying to make apparel store. Have Joomla 2.5.19 with Virtuemart 2.0.26d installed. On product detail page I have custom field (select list, cart variant) called SIZE. This custom field has options: Small, Medium, Large etc., but also it has first (top) option = "Please select".
I want this custom field to be required for select (mandatory) before you'll be able to add item to cart. For example if shop customer didn't select size (left custom field option as "Please select") and pressed add to cart button, he will see alert massage ( <script type="text/javascript"> alert("Please select size first"); </script> ) and product will not be added to cart until you select size.
Have you any idea what and where I have to change? I'm new in Joomla, Virtuemart and PHP. I was searching on different forums but couldn't find exactly what I need. If I missed a proper topic, could you point me to a right direction please.
Will appreciate for any help coz I'm stuck on this in my project.

--------------------------------------------------------------------------

I think one of the way to achieve the goal is that I have to get value of custom field, value that currently selected and add some code in cart.php (components\com_virtuemart\controllers) in public function addJS() that is responsible for adding items to cart.
Something like that:

public function addJS() {
$selectedValue = //here should be code of obtaining custom field selected value
if($selectedValue=="Please select"){
<script type="text/javascript"> alert("Please select size first"); </script>
}
else{
//execute code of the function
...
}

Do you have any idea how to obtain currently selected value of VM2 custom field?