Post by marianoctes » Thu Aug 22, 2024 6:14 am

Buenas, quiero listar los descuentos en la vista de categorias. Adjunto lo que estoy armando.

En catalog/controller/product/category.php
Dentro del for de productos

Code: Select all

			$results = $this->model_catalog_product->getProducts($filter_data);

			foreach ($results as $result) {
Agregue lo siguiente:

Code: Select all

				// AGREGADO
				$discounts = $this->model_catalog_product->getProductDiscounts($result['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'])
					);
				}
				// FIN AGREGADO

				$data['products'][] = array(
					'product_id'  => $result['product_id'],
					'thumb'       => $image,
					'name'        => $result['name'],
					'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
					'price'       => $price,
					'special'     => $special,
					'tax'         => $tax,
					'minimum'     => $result['minimum'] > 0 ? $result['minimum'] : 1,
					'rating'      => $result['rating'],
					'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url),
					'discounts'   => $data['discounts'] // AGREGADO
				);

En: catalog/view/theme/default/template/product/category.twig
Antes de:

Code: Select all

{% if product.rating %}
Agrego

Code: Select all

				{% if product.discounts %}
				{% for discount in product.discounts %}
					<hr>
					{{ product.discounts.quantity }}{{ text_discount }}{{ product.discounts.price }}
				{% endfor %}
				{% endif %}

El problema es que no se visualiza la cantidad ni el precio.. Solo se ve el bucle de "o mas"

Newbie

Posts

Joined
Tue Mar 15, 2022 10:45 pm

Post by imdevlper18 » Sat Sep 07, 2024 1:04 pm

You need to fix second part of your code. The code will be:

Code: Select all

{% if product.discounts %}
                  {% for discount in product.discounts %}
                    {{ discount.quantity }} Quanity: {{ discount.price }}<br>
                  {% endfor %}
                  <br>
                  {% endif %}
See attached output.

Attachments

scrnli_07_09_2024_10-33-00.png

category page discount display - scrnli_07_09_2024_10-33-00.png (26.41 KiB) Viewed 798 times


Opencart Extensions | Professional opencart support | Support Ticket | support@cartbinder.com


User avatar
Active Member

Posts

Joined
Sun May 11, 2014 2:04 pm
Who is online

Users browsing this forum: No registered users and 7 guests