VirtueMart 2 > Product creation
How to echo the price and ID value of related products on Product Details page
fabelmik:
Hi,
Does anyone know how to echo different product values of the "related products" on the Product Details page?
I can see that $this->product->customfieldsRelatedProducts points to the related products, but I don´t know how to echo specific product information e.g. prices, product-ID and so on..
In my default.php (product details) file the following code echoes the related products:
<?php
foreach ($this->product->customfieldsRelatedProducts as $field){
?>
<div style="display:inline-block;" class="product-field product-field-type-<?php echo $field->field_type ?>" >
<div class="product-field-display" style="width: 7em; overflow: hidden; line-height: 1.2em; max-height: 8.3em;position: relative;top: 0px; text-align: center;margin-left: 5px;
margin-right: 15px;"><?php echo $field->display ?></div>
jefchenko:
Hi fabelmik,
If you would put this somewhere in that file:
print_r($this->product->customfieldsRelatedProducts);
It will output all the fields virtuemart is getting for you. Unfortunately, no price is included in the array of related products.
The related products are in fact just linked to a (system generated) customfield (customfield id=1) of the product.
You would have to write your own script/query to get the price of those related products from the custom_value field (which represents the virtuemart_product_id of the related product).
I would also like this... Can anyone help us write a short code for this?
fabelmik:
Hi jefchenko,
Thanks for the answer.
I guess we have to hope for someone to help us with a usable script.
What I really want to achieve is to show price and have an "add to cart" function on each related product.
fabelmik:
@jefchenko
It seems noone´s answering this post, so I have now made a "Commercial jobs" request instead:
http://forum.virtuemart.net/index.php?topic=105701.0
I will post the solution if or when someone applies for the job.
dennis.g:
There is no easy answer to this. You have to override the viewer for related products and add some code in multiple places.
Find the file /components/com_virtuemart/view/productdetails/tmpl/default_relatedproducts.php
Copy it to /templates/<your template>/html/com_virtuemart/productdetails/default_relatedproducts.php
That will create an override.
Now open that file and add
--- Code: ---$model = new VirtueMartModelProduct();
$calculator = calculationHelper::getInstance();
$currency = CurrencyDisplay::getInstance();
--- End code ---
after this line:
--- Code: ---defined ( '_JEXEC' ) or die ( 'Restricted access' );
--- End code ---
Then locate the line
--- Code: ---<span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
--- End code ---
and replace it with
--- Code: --- <span class="product-field-desc"><?php
echo jText::_($field->custom_field_desc);
$product = $model->getProductSingle($field->custom_value,false);
$price = $calculator -> getProductPrices($product);
echo $currency->priceDisplay($price['salesPriceWithDiscount']);
?></span>
--- End code ---
Not exactly a piece of cake :)
Navigation
[0] Message Index
[#] Next page
Go to full version