News:

Support the VirtueMart project and become a member

Main Menu

Need Clarification of Listing Children on Parent Product Page - Yes or No?

Started by Greg P, November 13, 2011, 18:45:06 PM

Previous topic - Next topic

Greg P

I've read a number of discussions about this, but can't derive a clear answer.  Perhaps a straightforward, clear example of what is being sought might help. Understanding that Browsing is driven by Categories, the question lies in the Product creation and the proper use of the correct type of custom fields:

In short, a customer cannot buy the parent, they must buy one of the children:

  • A Category called "Movies" contains many parent products (the movie Titles)
      Titles:
      • Twilight
      • The Godfather
      • Harry Potter
      • etc., etc., etc. ...
  • Each parent Product (the Title) has several child Products (the Formats)
      Twilight (SKU='TWI'):
      • Blue Ray (SKU='TWI-BR')
      • DVD (SKU='TWI-DVD')
      • Streaming (SKU='TWI-STR')
The objective is to have a Product Page for a movie Title, and an AddToCart button for each of the children products,  The result being a page showing the movie title, an image from the movie, then the choice to add one of the child products (not a cart variant) to the cart.  The biggest reason (aside from specific inventoried SKUs) that a cart variant is not possible, is that each child Format has specific information such as Blue Ray having an extra 2hrs of additional footage, or the DVD has an interactive game, or the Streaming has a fixed license period, etc. - data that custom fields for the Product must contain, not just a cart variation. (These are just brief examplex of product specific info - each format has format specific info that far exceeds the limitations of a cart variation such as a size or color choice of a t-shirt)

So, how does one correctly create a Parent Product, and then the Child Products to properly accomplish the above scenario? The correct choice and sequence of choices seems to drive this, and frankly, I just don't get it.  ???

Thanks so very much in advance for assistance in this.  I'm dying to bet my teeth into the new version, but this is a showstopper for me (and apparently many others).  (And with all due respect, answers about alternative approaches to the problem will only confuse the issue I think. At least in my case, I must do it this way. :) )[/list][/list]

Stephen Roberts

I've wondered the "proper" way to do this myself. In my case, I needed to sell music and videos where the user can purchase the whole CD or purchase individual tracks from the CD. Here's an example:

http://www.iworshipnow.com/index.php?page=shop.product_details&flypage=flypage_digital_types.tpl&product_id=355&category_id=10&option=com_virtuemart&Itemid=152

In VM 1.1.9, I had to hack the core to allow this. I have a prototype working in VM2 right now where everything is handled by overriding the productdetails template. I simply get the child products and loop to output the info and an addtocart button for each child. I can send you my template override if you'd like to see the code. Here's my VM2 prototype - formatting isn't finished and I don't have prices for tracks either.

http://imd-test.davidccook.com/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=5394&virtuemart_category_id=2
Sell downloadable (virtual) products in VirtueMart 2 and deliver downloads via local server, Amazon S3, and more! http://www.digitollsoftware.com

Greg P

It seems to me that this would be the single purpose of a parent/child design - without it, what's the point of having children products?  Perhaps there is one, but I can't see it, so keep returning to the dead stop I'm at trying to make that work.

The Product Details default.php has code for the children:

/* Product custom Childs
  * to display a simple link use $field->virtuemart_product_id as link to child product_id
  * custom_value is relation value to child
  */
if (!empty($this->product->customsChilds)) {  ?>
<div class="product-fields">
<?php foreach ($this->product->customsChilds as $field) {  ?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field->field_type ?>">
<span class="product-fields-title" ><b><?php echo JText::_($field->field->custom_title?></b></span>
<span class="product-field-desc"><?php echo JText::_($field->field->custom_value?></span>
<span class="product-field-display"><?php echo $field->display ?></span>

</div><br />
<?php
?>

</div>
<?php ?>


and the query to populate "customsChilds" is in models/customfields.php:

     function getProductCustomsChilds($childs){

$data = array();
      foreach ($childs as &$child) {
      $query='SELECT C.* , field.*
FROM `#__virtuemart_product_customfields` AS field
LEFT JOIN `#__virtuemart_customs` AS C ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
WHERE `virtuemart_product_id` ='.(int)$child->virtuemart_product_id;
$query .=' and C.field_type = "C" ';

$this->_db->setQuery($query);
$child->field = $this->_db->loadObject();
      $child->display = $this->displayType($child->virtuemart_product_id,'C');
      if ($child->field) $data[] = $child ;
      }
return $data ;

     }


I just can't figure out how to properly get a field type to be a "C"

yourwings

I know it's an old topic, but I just do not get the edge ...
In productdetails.php I have the following code:

   if (!empty($this->product->customsChilds)) { ?>
   <?php } ?>
      <?php foreach ($this->product->customfieldsCart as $field) { ?>
         <?php echo $this->product->product_sku; ?>
          <?php }       ?>

I have setup a parent/child, but it just never enters the IF-condition ...

Someone wrote:
--- and the query to populate "customsChilds" is in models/customfields.php:

Is there somewhere the bug, do I have to trigger that code  ?

Any idea ?

Best regards