简体   繁体   English

显示相关产品Virtuemart 2.0中的定价和添加到购物车按钮

[英]Display pricing and add to cart button in related products Virtuemart 2.0

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. $ field没有任何定价。 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 } ?> 

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. 它需要将“default_relatedproducts.php”,“default_showprices.php”和“default_addtocart.php”复制到“template / html / com_virtuemart / productdetails”文件夹中。 Then replace all of the code in the "default_relatedproducts.php" with the following code: 然后使用以下代码替换“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>

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 所以最快的方法是在customfields.php中更改sql select语句

Path in Joomla 2.5 for Virtuemart 2.0 administrator/components/com_virtuemart/models/customfields.php line 548 of 路径Joomla 2.5 for Virtuemart 2.0管理员/组件/ com_virtuemart / models / customfields.php第548行

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 毕竟在线559改变了

$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 ?>

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. 它使用主要产品图像,只是重复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM