D
D
Danil Larionov2020-06-10 17:14:52
css
Danil Larionov, 2020-06-10 17:14:52

How to add a percentage discount sticker for open cards 3?

5ee0eaa4eed4e493805258.jpeg
There is a sticker in the top right corner, I want to add something like that, are there any modules, or how to do it yourself, who can tell me if there are styles for it)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
secretsergey, 2020-06-14
@wolf65

An example of the "Featured" module (others by analogy) for OpenCart 3:
1) catalog/controller/extension/module/featured.php
Looking for:

if ((float)$product_info['special']) {
            $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
          } else {
            $special = false;
          }

Change to:
if ((float)$product_info['special']) {
            $special = $this->currency->format($this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
            $percent_discount = 100 - $this->tax->calculate($product_info['special'], $product_info['tax_class_id'], $this->config->get('config_tax')) * 100 / $this->tax->calculate($product_info['price'], $product_info['tax_class_id'], $this->config->get('config_tax')) . '%';
          } else {
            $special = false;
            $percent_discount = false;
          }

Are looking for:
$data['products'][] = array(
            'product_id'  => $product_info['product_id'],
            'thumb'       => $image,
            'name'        => $product_info['name'],
            'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
            'price'       => $price,
            'special'     => $special,
            'tax'         => $tax,
            'rating'      => $rating,
            'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
          );

Change to:
$data['products'][] = array(
            'product_id'  => $product_info['product_id'],
            'thumb'       => $image,
            'name'        => $product_info['name'],
            'description' => utf8_substr(strip_tags(html_entity_decode($product_info['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
            'price'       => $price,
            'special'     => $special,
            'percent_discount'     => $percent_discount,
            'tax'         => $tax,
            'rating'      => $rating,
            'href'        => $this->url->link('product/product', 'product_id=' . $product_info['product_id'])
          );

2) catalog/view/theme/*/template/extension/module/featured.twig Paste
in the right place:
{% if product.percent_discount %}{{ product.percent_discount }}{% endif %}

W
WapSter, 2020-06-10
@wapster92

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question