简体   繁体   English

Opencart 在产品特色页面中显示折扣价

[英]Opencart show discount price in product featured page

I am new to the opencart .我是opencart I have setup featured product in my homepage.我在我的主页上设置了特色产品。 So when one will visit he can see all the featured product with its description.因此,当人们访问时,他可以看到所有特色产品及其描述。 Now here in this featured page I have shown the product price by using <?php echo $product['price']; ?>现在在这个特色页面中,我使用<?php echo $product['price']; ?>显示了产品价格<?php echo $product['price']; ?> <?php echo $product['price']; ?> . <?php echo $product['price']; ?> . It is showing the product price without any problem.它显示产品价格没有任何问题。 Now I want to show the product discounts in the featured page.现在我想在特色页面中显示产品折扣。 So how to do that?那么怎么做呢? Any help and suggestion will be highly appreciable.任何帮助和建议将是非常可观的。

Untested, but should work in theory.未经测试,但理论上应该有效。

First, in catalog/language/english/module/featured.php add the following line:首先,在catalog/language/english/module/featured.php添加以下行:

$_['text_discount']     = '%s or more %s';

Next, in catalog/controller/module/featured.php do the following:接下来,在catalog/controller/module/featured.php执行以下操作:

After $this->data['button_cart'] = $this->language->get('button_cart'); $this->data['button_cart'] = $this->language->get('button_cart'); add:添加:

$this->data['text_discount'] = $this->language->get('text_discount');

After $product_info = $this->model_catalog_product->getProduct($product_id); $product_info = $this->model_catalog_product->getProduct($product_id); add:添加:

$discounts = $this->model_catalog_product->getProductDiscounts($product_id);
$product_discounts[] = array(); 

foreach ($discounts as $discount) {
    $product_discounts[] = array(
        'quantity' => $discount['quantity'],
        'price'    => $this->currency->format($this->tax->calculate($discount['price'], $product_info['tax_class_id'], $this->config->get('config_tax')))
    );
}

After 'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']), add:'href' => $this->url->link('product/product', 'product_id=' . $product_info['product_id']),添加:

'discounts'  => $product_discounts

Finally, in catalog/view/theme/<theme>/template/module/featured.tpl add this wherever you want it to display:最后,在catalog/view/theme/<theme>/template/module/featured.tpl添加这个你想要它显示的地方:

<?php foreach ($product['discounts'] as $discount) { ?>
<?php echo sprintf($text_discount, $discount['quantity'], $discount['price']); ?><br />
<?php } ?>

Finally, in catalog/view/theme//template/module/featured.tpl add this wherever you want it to display:最后,在catalog/view/theme//template/module/featured.tpl 中添加这个你想要它显示的地方:


enter image description here在此处输入图片说明

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

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