Author Topic: Adding Add to Cart & Price of Products in Related Products in VirtueMart 2.0  (Read 17856 times)

suesbarn

  • Beginner
  • *
  • Posts: 18
I want to have prices and add to cart options (including parent & child options) on the products in the related products section of each product's description page. I have found tutorials and forums on how to do it in older versions of VirtueMart, but nothing on the newest version. Can anyone help me with this?

Thank you,
~ Mike

ahaaaa

  • Beginner
  • *
  • Posts: 14
There is a solution here

http://forum.virtuemart.net/index.php?topic=105344.msg354393#msg354393

If you change the value "false" to "true" in the following line, 

$product = $model->getProductSingle($field->custom_value,false);

it displays custom fields

ahaaaa

  • Beginner
  • *
  • Posts: 14
I've been playing with this to include stockable variants that also displays price variations.  I think i've found a solution.

It requires copying the "default_relatedproducts.php", "default_showprices.php" and "default_addtocart.php" to your "template/html/com_virtuemart/productdetails" folder. Then replace all of the code in the "default_relatedproducts.php" with the following code:-

Code: [Select]
<?php
/**
 *
 * Show the product details page
 *
 * @package VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen

 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_relatedproducts.php 5406 2012-02-09 12:22:33Z alatak $
 */

// Check to ensure this file is included in Joomla!
defined '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator calculationHelper::getInstance();
$currency CurrencyDisplay::getInstance();
?>

<?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></div>
        <div class="product-related-products">

    <?php
    
foreach ($this->product->customfieldsRelatedProducts as $field) {
?>
<div class="product-field product-field-type-<?php echo $field->field_type ?>">
    <span class="product-field-display"><?php echo $field->display ?></span>
        <div style="float:right"><?php
echo jText::_($field->custom_field_desc);

$product $model->getProductSingle($field->custom_value,true);
?>

</div>
<div style="float:left"><?php echo $product->product_name?></div>
<?php ?>
<div style="float:right"id="productPrice<?php echo $product->virtuemart_product_id ?>">
<?php include 'default_showprices.php'?>
</div>
<div class="clear"><?php include 'default_addToCart.php'?></div>
</div>
<?php ?>

Seems to work, if anyone has any refinements please post them.

csho

  • Beginner
  • *
  • Posts: 33
Product price is being displayed wrong, it takes the price of the product and not the related product. :/

Here is my code if anyone can help..

Code: [Select]
<?php
/**
 *
 * Show the product details page
 *
 * @package VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen

 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_relatedproducts.php 5406 2012-02-09 12:22:33Z alatak $
 */

// Check to ensure this file is included in Joomla!
defined '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator calculationHelper::getInstance();
$currency CurrencyDisplay::getInstance();
?>

<h3><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3></div>
        <div class="product-related-products">
<table class="RelatedProductsTable">
<tr><th></th><th>Name</th><th>Category</th><th>Desc</th> <th></th></tr>
</table>
    <?php
    
foreach ($this->product->customfieldsRelatedProducts as $field) {
?>

<div class="product-field">

<?php
$product 
$model->getProductSingle($field->custom_value,true); 
?>

<table class="RelatedProductsTable">
<tr>
<td><div class="product_img">
<a title="<?php echo $product->product_name ?>" rel="vm-additional-images" href="<?php echo $product->link?>">
<?php
//echo $product->images[0]->displayMediaThumb('class="browseProductImage"', false); //Bugs everthing...
?>

 </a>
<td><div class="product_name"><?php echo JHTML::link ($product->link$product->product_name); ?></div></td>
<td><div class="product_category"><?php //echo $product->$virtuemart_category_id; ?></div></td>
<td><div class="short_desc"><?php echo $product->product_s_desc?></div></td>
<td><div class="product_price">
<?php //FIX:Display Cart/Price
include 'default_showprices.php';
include 
'default_addtocart.php'
?>
</td>
</tr>
</table>


</div>
<!--
<div class="product-field product-field-type-<?php //echo $field->field_type ?>">
    <span class="product-field-display"><?php// echo $field->display ?></span>

<div style="float:right"><?php
//echo jText::_($field->custom_field_desc);
//$product = $model->getProductSingle($field->custom_value,true);
//$price = $calculator -> getProductPrices($product);
?>

</div>
<div style="float:left"><?php// echo $product->product_name; ?></div>
<?php ?>

<div style="float:left" id="productCategory><?php //echo $product->virtuemart_category_id ; ?>">
<?php //include 'default_showcategory.php'; ?>
</div>

<div style="float:right"id="productPrice<?php //echo $product->virtuemart_product_id ?>">
<?php //include 'default_showprices.php'; ?>
</div>

<div class="clear"><?php //include 'default_addToCart.php'; ?></div>
</div>-->


<?php ?>

I wanted to have this set of display in product result page when search and in related products.
I can't find how to change the appearance of result page and the related products page has some problems.
I wanted to show the image,title,category,description and cart/price.

Image and Cart/Price take product data and not the related product ones.
I can't figure out how to show related products category (with link).

I hope anyone can help...

VirtueMarky

  • Beginner
  • *
  • Posts: 10
Hi,

today i realised that i have nearly the same problem.
The shown product price is not the one of the related product - its the one of the opened product.
I included the price some time ago into the related_products.php like this:

<?php echo $this->loadTemplate('showprices') ?>

It seems that since month customers is shown the wrong price for every related product... bäähh

I hope someone has a good idea how to solve this problem soon - would be great!

Greetz

csho

  • Beginner
  • *
  • Posts: 33
Hi,

today i realised that i have nearly the same problem.
The shown product price is not the one of the related product - its the one of the opened product.
I included the price some time ago into the related_products.php like this:

<?php echo $this->loadTemplate('showprices') ?>

It seems that since month customers is shown the wrong price for every related product... bäähh

I hope someone has a good idea how to solve this problem soon - would be great!

Greetz

I managed to solve this but seeing the code posted by someone else, here in the forum.
You actually make a button yourself and show the price, if i find it again i will post it back.

vanaveno

  • Beginner
  • *
  • Posts: 10
  • vanaveno
    • Fotoblog Vanaveno
Hello, I need add to cart to related products. I found this solution:

<?php
/**
 *
 * Show the product details page
 *
 * @package   VirtueMart
 * @subpackage
 * @author Max Milbers, Valerie Isaksen

 * @link http://www.virtuemart.net
 * @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
 * VirtueMart is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 * @version $Id: default_relatedproducts.php 6431 2012-09-12 12:31:31Z alatak $
 */

// Check to ensure this file is included in Joomla!
defined ( '_JEXEC' ) or die ( 'Restricted access' );
$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
?>
        <div class="product-related-products">
       <h3><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h3>

   <?php
    foreach ($this->product->customfieldsRelatedProducts as $field) {
    ?><div class="product">
    <div class="description">
            <h2 class="product-field-display"><?php echo $field->display ?></h2>
         
        </div>
       
        <a title="<?php echo $product->product_name ?>" rel="vm-additional-images" href="<?php echo $product->link; ?>">

 </a>
            <span class="product-field-desc"><?php

echo jText::_($field->custom_field_desc);

$product = $model->getProductSingle($field->custom_value,false);
$price = $calculator -> getProductPrices($product);
echo "<div class='product-price'><span>".$currency->priceDisplay($price['salesPrice'])."</span></div>";
?>
</span>

<?php // This is the beginning of "Add to cart" ?>

<form method="post" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
<div class="cart-detail">
   <div class="addtocart-bar">
         <?php // Display the quantity box ?>
         <!-- <label for="quantity<?php echo $product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
         <span class="quantity-box">
            <input style="display:none;" type="text" class="quantity-input" name="quantity[]" value="1" />
         </span>
         
         <?php // Display the quantity box END ?>

         <?php // Add the button
         $button_lbl = JText::_('COM_VIRTUEMART_CART_ADD_TO_CAT');
         $button_cls = ''; //$button_cls = 'addtocart_button';
         if (VmConfig::get('check_stock') == '1' && !$product->product_in_stock) {
            $button_lbl = JText::_('COM_VIRTUEMART_CART_NOTIFY');
            $button_cls = 'notify-button';
         } ?>

         <?php // Display the add to cart button ?>
         <div class="addtocart-button">
            <input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
         </div>

      <div class="clear"></div>
      </div></div>

      <?php // Display the add to cart button END ?>
      <input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
      <input type="hidden" name="option" value="com_virtuemart" />
      <input type="hidden" name="view" value="cart" />
      <noscript><input type="hidden" name="task" value="add" /></noscript>
      <input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
      <?php /** @todo Handle the manufacturer view */ ?>
      <input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
      <input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>




        </div>
    <?php } ?>
      
        </div>
       
<div class="clear"></div>


But without <?php echo $field->display ?> I need change it on title and images separatly. I would like to add tags to picture and title.
<h2> Title </h2>
<div class="image"> <img ...</div>
Can anybody help me please?

Thanks
Vana