Jump to content
  • разработка интернет магазинов на opencart
  • доработка интернет магазинов на opencart

Вывод {{ discount.price }} в категориях


Recommended Posts

Доброго времени суток. Пыиюсь вывести {{ discount.price }} (скидка при заказе от...) в категориях.

В контроллер category.php после

Spoiler

if ($this->config->get('config_review_status')) {
                    $rating = (int)$result['rating'];
                } else {
                    $rating = false;
                }

$discounts = $this->model_catalog_product->getProductDiscounts($this->request->get['product_id']);

			    $data['discounts'] = array();

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

В массив $data['products'][] = array(

'discounts'    => $discounts,
'tax_class_id' => $result['tax_class_id'],

В шаблон category.twig

{% if discounts %}
            {% for discount in discounts %}
            <li>{{ text_discount }}(>{{ discount.quantity }}): <strong>{{ discount.price }}</strong></li>
            {% endfor %}
            {% endif %}

Подскажите что гделаю не ик?

Link to comment
Share on other sites


посмотрите, как как все устроено в контроллере.

Там массив с товарами пербирается, в ним нужно рилиить, а не в $data добавлять

 

перед $data['products'][] = array(

 

нужно полулить эти скидки для текуещёго товара в цикле 

 

 

$discounts = $this->model_catalog_product->getProductDiscounts($result['product_id']);

а потом уже в  $data['products'] добавить 

 

'discounts' => $discounts

 

 

В twig уже тогда ик 

 

{% if product.discounts %}
            {% for discount in product.discounts %}
            <li>{{ text_discount }}(>{{ discount.quantity }}): <strong>{{ discount.price }}</strong></li>
            {% endfor %}
            {% endif %}
Link to comment
Share on other sites

  • 1 year later...
В 07.12.2020 в 20:53, Seriusis сказал:

посмотрите, как как все устроено в контроллере.

Там массив с товарами пербирается, в ним нужно рилиить, а не в $data добавлять

 

перед $data['products'][] = array(

 

нужно полулить эти скидки для текуещёго товара в цикле 

 

 

$discounts = $this->model_catalog_product->getProductDiscounts($result['product_id']);

а потом уже в  $data['products'] добавить 

 

'discounts' => $discounts

 

 

В twig уже тогда ик 

 

{% if product.discounts %}
            {% for discount in product.discounts %}
            <li>{{ text_discount }}(>{{ discount.quantity }}): <strong>{{ discount.price }}</strong></li>
            {% endfor %}
            {% endif %}

 

Полулилось вывести, но не выводит валюту и не округляет этону. 

Кто может подсказать? 

вот скрин 

image.png.0f745424a2b496baacb2ebd876fe1ca6.png

Link to comment
Share on other sites


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.