Display pricing and add to cart button in related products Virtuemart 2.0
Asked Answered
C

3

1

I would like to display the related product pricing and have add to cart button along with each of the related products.

Below is the code snippet from the related products page. The $field does not have any pricing available. How can I show the pricing and "add to cart" button? Thanks in advance

<?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>
            <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>

        </div>
    <?php } ?> 
Cyprus answered 5/7, 2012 at 14:23 Comment(0)
H
2

I have found solution here and it works for me: no need to edit core files

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:

<?php


// 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">
<h4><?php echo JText::_('COM_VIRTUEMART_RELATED_PRODUCTS'); ?></h4>
<div>
    <?php
    foreach ($this->product->customfieldsRelatedProducts as $field) {
    ?>

<div class="product-field">

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

<h2><?php echo JHTML::link ($product->link, $product->product_name); ?></h2>

<a title="<?php echo $product->product_name ?>" rel="vm-additional-images" href="<?php echo $product->link; ?>">
<?php
    echo $this->product->images[0]->displayMediaThumb('class="browseProductImage"', false);
?>
 </a>


<div class="short_desc"><?php echo $product->product_s_desc; ?></div>

<?php include 'default_showprices.php'; ?>

<?php include 'default_addtocart.php'; ?>
</div>


    <?php } ?>
    </div>
    </div>
Hackbut answered 28/7, 2013 at 11:32 Comment(1)
Note that link-only answers are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference.Internationalism
W
1

Had a same problem. But I had to show only the price. So the fastest way is to change sql select statement in customfields.php

Path in Joomla 2.5 for Virtuemart 2.0 administrator/components/com_virtuemart/models/customfields.php line 548 of

public function getProductCustomsFieldRelatedProducts($product)

change only

$query=

with

'SELECT C.`virtuemart_custom_id` , `custom_parent_id` , `admin_only` , `custom_title` , `custom_tip` , C.`custom_value` 
AS value, `custom_field_desc` , `field_type` , `is_list` , `is_hidden` , C.`published` , field.`virtuemart_customfield_id` , 
    field.`custom_value`, field.`custom_param`, price.`product_price`, field.`ordering`
        FROM `#__virtuemart_customs` AS C
        LEFT JOIN `#__virtuemart_product_customfields` AS field ON C.`virtuemart_custom_id` = field.`virtuemart_custom_id`
        LEFT JOIN `#__virtuemart_product_prices` AS price ON 
    field.`custom_value` = price.`virtuemart_product_id`
        Where field.`virtuemart_product_id` ='.(int)$product->virtuemart_product_id.' and `field_type` = "R"';

After all on line 559 change

$field->custom_price

to

$field->product_price

And finally... In template view of product description insert the code below to show the prices of related products

<?php echo $field->product_price ?>
Wenonawenonah answered 15/8, 2012 at 15:57 Comment(0)
W
0

The only problem with the below solution is that it doesn't display the correct images for the related products. It's using the main products image and just repeating it.

Whaling answered 29/9, 2013 at 15:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.