我想显示相关的产品定价,并添加到购物车按钮以及每个相关产品。
以下是相关产品页面的代码段。 $ field没有任何定价。如何显示定价和“添加到购物车”按钮?提前致谢
<?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 } ?>
答案 0 :(得分:2)
我在这里找到了解决方案,它对我有用: no need to edit core files
它需要将“default_relatedproducts.php”,“default_showprices.php”和“default_addtocart.php”复制到“template / html / com_virtuemart / productdetails”文件夹中。然后使用以下代码替换“default_relatedproducts.php”中的所有代码:
<?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>
答案 1 :(得分:1)
有同样的问题。但我必须只显示价格。 因此,最快的方法是在customfields.php
中更改sql select语句Joomla 2.5 for Virtuemart 2.0管理员/组件/ com_virtuemart / models / customfields.php的路径
的第548行public function getProductCustomsFieldRelatedProducts($product)
仅更改
$query=
与
'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"';
毕竟在第559行改变
$field->custom_price
到
$field->product_price
最后...... 在产品说明的模板视图中,插入以下代码以显示相关产品的价格
<?php echo $field->product_price ?>
答案 2 :(得分:0)
以下解决方案的唯一问题是它没有显示相关产品的正确图像。它使用主要产品图像并重复它。