News:

Looking for documentation? Take a look on our wiki

Main Menu

"Generic Child Variant" - Prevent adding Parent to Shopping cart

Started by mulcamd, March 27, 2012, 19:43:35 PM

Previous topic - Next topic

mulcamd

When making a parent and children with "Generic Child Variant" I get a very nice dropdown list with the parent and the children listed. THIS IS FINE!

BUT because often the parent is the template for the variants of the children, the parent, at least in some cases, should not be addable to the shopping cart.
This because all the variations, the children, have the specific properties.

For example T-shirts. T-shirts have size and color.
To show all the variants with "Generic Child Variant" works perfectly. The parent being the pattern and the children the different entities.
But if a shopper, by accident puts the parent in the shopping cart, the shop owner can not know which size and color to ship.

How can be prevent that the parent is put in the shopping cart.

If not possible in version 2.0.2 / 2.0.3, could an option be added to parents like "addable to shoping cart"or "valid cart value" or ... (what's in a name).

Please give me advise how to handle.

Orfirel

I have the same problem. My semi optimal solution so far is to add these lines after line 703 in
administrator\components\com_virtuemart\models\customfields.php
----------------------------------------------------------------------
if (sizeof($options) > 1) {
    $options[0]['text'] = "Choose";
}
----------------------------------------------------------------------
And then add the following lines after line 119 in
components\com_virtuemart\controllers\cart.php
----------------------------------------------------------------------
if (sizeof($virtuemart_product_ids)>0) {
            $jobDb = JFactory::getDbo();
            $sqlStmt = 'SELECT count(*) FROM #__virtuemart_products p, #__virtuemart_product_customfields f, #__virtuemart_customs c
                                        WHERE p.product_parent_id=0 and p.virtuemart_product_id='.$virtuemart_product_ids[0].' and
                                            p.virtuemart_product_id=f.virtuemart_product_id and c.field_type=\'A\' and c.virtuemart_custom_id=f.virtuemart_custom_id';
            $jobDb->setQuery($sqlStmt);
         $jobResult = $jobDb->loadResult();               

            if ((int)$jobResult >= 1) {
                jExit();   
            }
        }

mulcamd

One word: GREAT!

One small suggestion: when trying to add the parent to the shopping cart, give a error message that the user has to choose!

Orfirel

Insert these lines in cart.php instead:
-----------------------------------------------------
       if (sizeof($virtuemart_product_ids)>0) {
            $jobDb = JFactory::getDbo();
            $sqlStmt = 'SELECT c.custom_title FROM #__virtuemart_products p, #__virtuemart_product_customfields f, #__virtuemart_customs c
                                        WHERE p.product_parent_id=0 and p.virtuemart_product_id='.$virtuemart_product_ids[0].' and
                                            p.virtuemart_product_id=f.virtuemart_product_id and c.field_type=\'A\' and c.virtuemart_custom_id=f.virtuemart_custom_id';
            $jobDb->setQuery($sqlStmt);
            $jobResult = $jobDb->loadResult();               

            if ($jobResult != null) {
                $errorMsg = "You must choose " . $jobResult;
                $this->json->msg = '<a class="continue" href="' . $continue_link . '" >' . JText::_('COM_VIRTUEMART_CONTINUE_SHOPPING') . '</a>';
      $this->json->msg .= '<div>'.$errorMsg.'</div>';
      $this->json->stat = '2';
                echo json_encode($this->json);
                jExit();   
            }
        }
-----------------------------------------------------

Can someone from the virtuemart team please respond on this topic? Why can't we have such a basic feature without editing the source code? Or am I missing something fundamental here?

patrik60

This is a very good solution. Thank you. Would it be possible to have an option like "please choose" instead of the parents name at the top of the list?

Orfirel

Yes you can by inserting these lines after line 703 in administrator\components\com_virtuemart\models\customfields.php
if (sizeof($options) > 1) {
    $options[0]['text'] = "Please choose";
}


Another semi optimal solution is to follow Milbo's advice here: http://forum.virtuemart.net/index.php?topic=98648.0
That way your users will have the first variant if they forget to choose and click the "add to cart"-button.

I have found another bug in VM2 regarding variants. The combo box is not visible when using IE9 and the default VM2 template. It works in firefox and chrome though.

patrik60

Thank you for your answer. But it doesn't help. I still don't see the "Please choose", just the parents name on top of the dropdown. May be this is why I'm testing with version 2.0.3H? This version seems to have some bugs.

EDIT: updated to 2.0.3 I, still no effect. First part in cart.php works fine! Is it correct to insert it just before the line beginning with
"if ($is_list>0) {"

EDIT2: I have found it: Need to go to line 766 after

foreach($uncatChildren as $k => $child){
$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']);

Orfirel

Oh sorry, I forgot to mention, I am using 2.0.2 which according to "Virtuemart 2 - Live update" is the latest stable version. Nevertheless, it seems so unstable that I will have to go back to 1.1.9.

cmalo

I see that you write that you have a good dropdown list when using "Generic Child Variant"

If i make this, i get a list , but it expands and closes when i click on the list.
Only way to choose from the list is when i hold my mouse button on the list, and move the mouse cursor a little bit....

Someone that can help me out??

http://cmalo.nl/testsite2/index.php?option=com_virtuemart&amp;view=productdetails&amp;virtuemart_category_id=37&amp;virtuemart_product_id=58

thomaska

I am facing another problem and i am looking for a solution.
I am using VM 2.0.2 and Joomla 2.5.4
I had create a Generic Child Variant, associated with the parent item, and one child item. My problem is that the dropdown list contains the parent item more than once time and one child item. The result of the dropdown is the parent 3 times and the child one.

Any suggestions how to resolve the problem?

Thomas

olesman

@cmalo...I clicked on your link because I am having the same problem you describe.

How did you fix it?

Bruce Morgan

I see you guys are using 2.0.2 not 2.0.4.  Have you tried updating?  I need to implement a similar solution.

olesman

It's all in the upgrade apparently.

After upgrading to 2.0.4 it looks like the customfield for child product variants has a drop down that stay dropped down.

The issue @cmalo was having.

thomaska

I tried upgrading to 2.0.4 and this version was worst than 2.0.2
Any suggenstions on 2.0.2?

cmalo

Quote from: olesman on April 12, 2012, 15:27:09 PM
@cmalo...I clicked on your link because I am having the same problem you describe.

How did you fix it?

Updating to 2.0.4 fixed it

_______________________________

My next problem is that i dont know how to sort child items