Jump to content
Sign in to follow this  
yurabr

price_2 в <span id="cart-total">. Подскажите, люди добрые

Recommended Posts

Здравствуйте.

Файл catalog/controller/common/cart.php

Спойлер
<?php
class ControllerCommonCart extends Controller {
	public function index() {
		$this->load->language('common/cart');

		// Totals
		$this->load->model('extension/extension');

		$totals = array();
		$taxes = $this->cart->getTaxes();
		$total = 0;

		// Because __call can not keep var references so we put them into an array.
		$total_data = array(
			'totals' => &$totals,
			'taxes'  => &$taxes,
			'total'  => &$total
		);
			
		// Display prices
		if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
			$sort_order = array();

			$results = $this->model_extension_extension->getExtensions('total');
			$results = $this->model_extension_extension->getExtensions('total_2');

			foreach ($results as $key => $value) {
				$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
			}

			array_multisort($sort_order, SORT_ASC, $results);

			foreach ($results as $result) {
				if ($this->config->get($result['code'] . '_status')) {
					$this->load->model('extension/total/' . $result['code']);

					// We have to put the totals in an array so that they pass by reference.
					$this->{'model_extension_total_' . $result['code']}->getTotal($total_data);
				}
			}

			$sort_order = array();

			foreach ($totals as $key => $value) {
				$sort_order[$key] = $value['sort_order'];
			}

			array_multisort($sort_order, SORT_ASC, $totals);
		}

		$data['text_empty'] = $this->language->get('text_empty');
		$data['text_cart'] = $this->language->get('text_cart');
		$data['text_cart_2'] = $this->language->get('text_cart_2');
		$data['text_checkout'] = $this->language->get('text_checkout');
		$data['text_recurring'] = $this->language->get('text_recurring');
		$data['text_items_2'] = sprintf($this->language->get('text_items_2'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total_2, $this->session->data['currency']));
		$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total, $this->session->data['currency']));
		$data['text_loading'] = $this->language->get('text_loading');

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

		$this->load->model('tool/image');
		$this->load->model('tool/upload');

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

		foreach ($this->cart->getProducts() as $product) {
			if ($product['image']) {
				$image = $this->model_tool_image->resize($product['image'], $this->config->get($this->config->get('config_theme') . '_image_cart_width'), $this->config->get($this->config->get('config_theme') . '_image_cart_height'));
			} else {
				$image = '';
			}

			$option_data = array();

			foreach ($product['option'] as $option) {
				if ($option['type'] != 'file') {
					$value = $option['value'];
				} else {
					$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);

					if ($upload_info) {
						$value = $upload_info['name'];
					} else {
						$value = '';
					}
				}

				$option_data[] = array(
					'name'  => $option['name'],
					'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
					'type'  => $option['type']
				);
			}

			// Display prices
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$unit_price = $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'));
				
				$price = $this->currency->format($unit_price, $this->session->data['currency']);
				$total = $this->currency->format($unit_price * $product['quantity'], $this->session->data['currency']);
			} else {
				$price = false;
				$total = false;
			}
			
			if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
				$unit_price_2 = $this->tax->calculate($product['price_2'], $product['tax_class_id'], $this->config->get('config_tax'));
				
				$price_2 = $this->currency->format($unit_price_2, $this->session->data['currency']);
				$total_2 = $this->currency->format($unit_price_2 * $product['quantity'], $this->session->data['currency']);
			} else {
				$price_2 = false;
				$total_2 = false;
			}

			$data['products'][] = array(
				'cart_id'   => $product['cart_id'],
				'thumb'     => $image,
				'name'      => $product['name'],
				'model'     => $product['model'],
				'option'    => $option_data,
				'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
				'quantity'  => $product['quantity'],
				'price'     => $price,
				'total'     => $total,
				'price_2'     => $price_2,
				'total_2'     => $total_2,
				'href'      => $this->url->link('product/product', 'product_id=' . $product['product_id'])
			);
		}

		// Gift Voucher
		$data['vouchers'] = array();

		if (!empty($this->session->data['vouchers'])) {
			foreach ($this->session->data['vouchers'] as $key => $voucher) {
				$data['vouchers'][] = array(
					'key'         => $key,
					'description' => $voucher['description'],
					'amount'      => $this->currency->format($voucher['amount'], $this->session->data['currency'])
				);
			}
		}

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

		foreach ($totals as $total) {
			$data['totals'][] = array(
				'title' => $total['title'],
				'text'  => $this->currency->format($total['value'], $this->session->data['currency']),
				'text_2'  => $this->currency->format($total['value_2'], $this->session->data['currency']),
			);
		}

		$data['cart'] = $this->url->link('checkout/cart');
		$data['checkout'] = $this->url->link('checkout/checkout', '', true);

		return $this->load->view('common/cart', $data);
	}

	public function info() {
		$this->response->setOutput($this->index());
	}
}

 

Тпл: 

<span id="cart-total"><?php echo $text_items_2; ?></span>

Оно должно в "cart-total" записать сумму по total_2.

Подправьте, если не сложно. Или, хотя бы, скажите где я туплю (хотя мне это вряд ли поможет:))

Спасибо.

ОКстор 2.3

Edited by yurabr

Share this post


Link to post
Share on other sites

Добавлю.

price_2 у меня добавлен в скидках, внесено в базу. В симпле, во всплывающей корзине все считает.

Делал по аналогии с работающим сайтом на опенкарт 1.5.6.4, но тут очень все не так.

Share this post


Link to post
Share on other sites
5 минут назад, yurabr сказал:

price_2 у меня добавлен в скидках, внесено в базу.

Могу предположить что функция $this->cart->getProducts() не возвращает прайс_2

Share this post


Link to post
Share on other sites

У меня смутные сомнения, что там еще в какой то яваскрипт лезть нужно.

 

Share this post


Link to post
Share on other sites

Так. Я немножко ввел в заблуждение. Не указал сразу, что шаблон Aridius Modern v2. 

Хотя, контроллер стандартный, я сверял. 

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

Ладно, тему закройте, если что. Я напишу другую.

Share this post


Link to post
Share on other sites

catalog/view/javascript/common.js - в нескольких местах 

Share this post


Link to post
Share on other sites
1 час назад, PaulKravchenko сказал:

catalog/view/javascript/common.js - в нескольких местах 

Ладно с теми скриптами. Скажите кто нибудь, у меня в контроллере правильно или нет?

Share this post


Link to post
Share on other sites
16 минут назад, yurabr сказал:

у меня в контроллере правильно или нет?

Вероятней всего нет. При формировании $data['text_items_2'] используется переменная $total_2, которая я не вижу чтобы где то выше была определена.

Share this post


Link to post
Share on other sites
2 часа назад, yurabr сказал:

Хотя, контроллер стандартный, я сверял.

Контроллер-то стандартный, но он может модифицироваться. Проверить это можно в папке system/storage/modification/ ...

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

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.