1

我想显示相关产品的定价,并与每个相关产品一起添加到购物车按钮。

以下是相关产品页面的代码片段。$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 } ?> 
4

3 回答 3

2

我在这里找到了解决方案,它对我有用: 无需编辑核心文件

它需要将“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>
于 2013-07-28T11:32:35.763 回答
1

有同样的问题。但我必须只显示价格。所以最快的方法是在customfields.php中更改sql select语句

Joomla 2.5 中 Virtuemart 2.0 管理员/components/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 ?>
于 2012-08-15T15:57:27.747 回答
0

以下解决方案的唯一问题是它没有为相关产品显示正确的图像。它使用主要产品图像并重复它。

于 2013-09-29T15:47:50.207 回答