Jump to content
Sign in to follow this  
mario512

Возвращает пустой массив.

Recommended Posts

Добрый день. Есть код в success.php, который заимствован из данной ветки: https://opencartforum.com/topic/69184-resheno-kak-otredaktirovat-stranicu-checkoutsuccess/?do=findComment&comment=641849

			$totals = $this->model_account_order->getOrderTotals($order_id);
			
			foreach ($totals as $total) {
				$data['totals'][] = array(
					'title' => $total['title'],
					'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
				);
			}

Не могу понять, почему в $totals пустой массив?

Edited by mario512

Share this post


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

$order_id

$this->session->data['order_id']

Share this post


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

$this->session->data['order_id']

Спасибо за ответ. Я пытался. Результат:

2019-07-28 16:21:07 - PHP Notice:  Undefined index: order_id in D:\Winginx\home\caseroom\caseroom.in.ua\www\system\storage\modification\catalog\controller\checkout\success.php on line 279

Share this post


Link to post
Share on other sites

Покажите лучше конечный suceess.php, подозреваю, что после $this->cart->clear(); не стал $order_id = $this->session->data['order_id']; и приходит $order_id = '0';

Share this post


Link to post
Share on other sites

так вы наверно прописываете после удаления

unset($this->session->data['order_id']);

Share this post


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

Покажите лучше конечный suceess.php, подозреваю, что после $this->cart->clear(); не стал $order_id = $this->session->data['order_id']; и приходит $order_id = '0';

Вот:

Спойлер

<?php
class ControllerCheckoutSuccess extends Controller {
	public function index() {
		$this->load->language('checkout/success');

		$order_id = '0';

		if (isset($this->session->data['order_id'])) {
			
			$this->cart->clear();

			$order_id = $this->session->data['order_id'];

			// Add to activity log
			if ($this->config->get('config_customer_activity')) {
				$this->load->model('account/activity');

				if ($this->customer->isLogged()) {
					$activity_data = array(
						'customer_id' => $this->customer->getId(),
						'name'        => $this->customer->getFirstName() . ' ' . $this->customer->getLastName(),
						'order_id'    => $this->session->data['order_id']
					);

					$this->model_account_activity->addActivity('order_account', $activity_data);
				} else {
					$activity_data = array(
						'name'     => $this->session->data['guest']['firstname'] . ' ' . $this->session->data['guest']['lastname'],
						'order_id' => $this->session->data['order_id']
					);

					$this->model_account_activity->addActivity('order_guest', $activity_data);
				}
			}

			unset($this->session->data['shipping_method']);
			unset($this->session->data['shipping_methods']);
			unset($this->session->data['payment_method']);
			unset($this->session->data['payment_methods']);
			unset($this->session->data['guest']);
			unset($this->session->data['comment']);
		    unset($this->session->data['order_id']);
			unset($this->session->data['coupon']);
			unset($this->session->data['reward']);
			unset($this->session->data['voucher']);
			unset($this->session->data['vouchers']);
			unset($this->session->data['totals']);
		    
		}
        
		$this->document->setTitle($this->language->get('heading_title'));

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

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/home')
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_basket'),
			'href' => $this->url->link('checkout/cart')
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_checkout'),
			'href' => $this->url->link('checkout/checkout', '', true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_success'),
			'href' => $this->url->link('checkout/success')
		);

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

		if ($this->customer->isLogged()) {
			$data['text_message'] = sprintf($this->language->get('text_customer'), $this->url->link('account/account', '', true), $this->url->link('account/order', '', true), $this->url->link('account/download', '', true), $this->url->link('information/contact'));
		} else {
			$data['text_message'] = sprintf($this->language->get('text_guest'), $this->url->link('information/contact'));
		}

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

		$data['continue'] = $this->url->link('common/home');
        //start
		$this->load->model('account/order');
		$this->load->model('catalog/product');
		$this->load->model('setting/setting');

		$order_info = $this->model_account_order->getOrder($order_id);
		
		$store_info = $this->model_setting_setting->getSetting('config', $order_info['store_id']);
				
		if ($store_info) {
			$data['store_name'] = $store_info['config_name'];
			$data['store_address'] = $store_info['config_address'];
			$data['store_emal'] = $store_info['config_email'];
			$data['store_tel'] = $store_info['config_telephone'];
		} else {
			$data['store_name'] = $this->config->get('config_name');
			$data['store_address'] = $this->config->get('config_address');
			$data['store_emal'] = $this->config->get('config_email');
			$data['store_tel'] = $this->config->get('config_telephone');
		}

		if ($order_info) {
			$this->document->setTitle($this->language->get('text_order'));

			$data['text_order_detail'] = $this->language->get('text_order_detail');
			$data['text_invoice_no'] = $this->language->get('text_invoice_no');
			$data['text_order_id'] = $this->language->get('text_order_id');
			$data['text_date_added'] = $this->language->get('text_date_added');
			$data['text_shipping_method'] = $this->language->get('text_shipping_method');
			$data['text_shipping_address'] = $this->language->get('text_shipping_address');
			$data['text_payment_method'] = $this->language->get('text_payment_method');
			$data['text_payment_address'] = $this->language->get('text_payment_address');
			$data['text_history'] = $this->language->get('text_history');
			$data['text_comment'] = $this->language->get('text_comment');

			$data['column_name'] = $this->language->get('column_name');
			$data['column_model'] = $this->language->get('column_model');
			$data['column_quantity'] = $this->language->get('column_quantity');
			$data['column_price'] = $this->language->get('column_price');
			$data['column_total'] = $this->language->get('column_total');
			$data['column_action'] = $this->language->get('column_action');
			$data['column_date_added'] = $this->language->get('column_date_added');
			$data['column_status'] = $this->language->get('column_status');
			$data['column_comment'] = $this->language->get('column_comment');

			$data['button_return'] = $this->language->get('button_return');
			$data['button_reorder'] = $this->language->get('button_reorder');
			$data['button_continue'] = $this->language->get('button_continue');

			if ($order_info['invoice_no']) {
				$data['invoice_no'] = $order_info['invoice_prefix'] . $order_info['invoice_no'];
			} else {
				$data['invoice_no'] = '';
			}

			$data['order_id'] = $order_id;
			$data['date_added'] = date($this->language->get('date_format_short'), strtotime($order_info['date_added']));
			$data['telephone'] = $order_info['telephone'];
            $data['email'] = $order_info['email'];

			if ($order_info['payment_address_format']) {
				$format = $order_info['payment_address_format'];
			} else {
				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
			}

			$find = array(
				'{firstname}',
				'{lastname}',
				'{company}',
				'{address_1}',
				'{address_2}',
				'{city}',
				'{postcode}',
				'{zone}',
				'{zone_code}',
				'{country}'
			);

			$replace = array(
				'firstname' => $order_info['payment_firstname'],
				'lastname'  => $order_info['payment_lastname'],
				'company'   => $order_info['payment_company'],
				'address_1' => $order_info['payment_address_1'],
				'address_2' => $order_info['payment_address_2'],
				'city'      => $order_info['payment_city'],
				'postcode'  => $order_info['payment_postcode'],
				'zone'      => $order_info['payment_zone'],
				'zone_code' => $order_info['payment_zone_code'],
				'country'   => $order_info['payment_country']
			);

			$data['payment_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

			$data['payment_method'] = $order_info['payment_method'];

			if ($order_info['shipping_address_format']) {
				$format = $order_info['shipping_address_format'];
			} else {
				$format = '{firstname} {lastname}' . "\n" . '{company}' . "\n" . '{address_1}' . "\n" . '{address_2}' . "\n" . '{city} {postcode}' . "\n" . '{zone}' . "\n" . '{country}';
			}

			$find = array(
				'{firstname}',
				'{lastname}',
				'{company}',
				'{address_1}',
				'{address_2}',
				'{city}',
				'{postcode}',
				'{zone}',
				'{zone_code}',
				'{country}'
			);

			$replace = array(
				'firstname' => $order_info['shipping_firstname'],
				'lastname'  => $order_info['shipping_lastname'],
				'company'   => $order_info['shipping_company'],
				'address_1' => $order_info['shipping_address_1'],
				'address_2' => $order_info['shipping_address_2'],
				'city'      => $order_info['shipping_city'],
				'postcode'  => $order_info['shipping_postcode'],
				'zone'      => $order_info['shipping_zone'],
				'zone_code' => $order_info['shipping_zone_code'],
				'country'   => $order_info['shipping_country']
			);

			$data['shipping_address'] = str_replace(array("\r\n", "\r", "\n"), '<br />', preg_replace(array("/\s\s+/", "/\r\r+/", "/\n\n+/"), '<br />', trim(str_replace($find, $replace, $format))));

			$data['shipping_method'] = $order_info['shipping_method'];

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

			$products = $this->model_account_order->getOrderProducts($order_id);

			foreach ($products as $product) {
				$option_data = array();

				$options = $this->model_account_order->getOrderOptions($order_id, $product['order_product_id']);

				foreach ($options 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)
					);
				}

				$product_info = $this->model_catalog_product->getProduct($product['product_id']);

				if ($product_info) {
					$reorder = $this->url->link('account/order/reorder', 'order_id=' . $order_id . '&order_product_id=' . $product['order_product_id'], 'SSL');
				} else {
					$reorder = '';
				}

				$data['products'][] = array(
					'name'     => $product['name'],
					'model'    => $product['model'],
					'option'   => $option_data,
					'quantity' => $product['quantity'],
					'price'    => $this->currency->format($product['price'] + ($this->config->get('config_tax') ? $product['tax'] : 0), $order_info['currency_code'], $order_info['currency_value']),
					'total'    => $this->currency->format($product['total'] + ($this->config->get('config_tax') ? ($product['tax'] * $product['quantity']) : 0), $order_info['currency_code'], $order_info['currency_value']),
					'reorder'  => $reorder,
					'return'   => $this->url->link('account/return/add', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], 'SSL')
				);
			}

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

			$vouchers = $this->model_account_order->getOrderVouchers($order_id);

			foreach ($vouchers as $voucher) {
				$data['vouchers'][] = array(
					'description' => $voucher['description'],
					'amount'      => $this->currency->format($voucher['amount'], $order_info['currency_code'], $order_info['currency_value'])
				);
			}

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

			$totals = $this->model_account_order->getOrderTotals($this->session->data['order_id']);
			
			foreach ($totals as $total) {
				$data['totals'][] = array(
					'title' => $total['title'],
					'text'  => $this->currency->format($total['value'], $order_info['currency_code'], $order_info['currency_value']),
				);
			}

			
			$data['comment'] = nl2br($order_info['comment']);

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

			$results = $this->model_account_order->getOrderHistories($order_id);

			foreach ($results as $result) {
				$data['histories'][] = array(
					'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
					'status'     => $result['status'],
					'comment'    => $result['notify'] ? nl2br($result['comment']) : ''
				);
			}

			$data['continue'] = $this->url->link('account/order', '', 'SSL');
		}
		//end	
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['column_right'] = $this->load->controller('common/column_right');
		$data['content_top'] = $this->load->controller('common/content_top');
		$data['content_bottom'] = $this->load->controller('common/content_bottom');
		$data['footer'] = $this->load->controller('common/footer');
		$data['header'] = $this->load->controller('common/header');

		$this->response->setOutput($this->load->view('common/success', $data));
	}
}

 

 

Share this post


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

$this->session->data['order_id']

ну да, у вас это

посте удаления

unset($this->session->data['order_id']);

$totals = $this->model_account_order->getOrderTotals($order_info['order_id']);

Share this post


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

так вы наверно прописываете после удаления

unset($this->session->data['order_id']);

Да, вы правы, unset($this->session->data['order_id']); пустое значение. Но $order_id есть номер заказа.

Share this post


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

ну да, у вас это

посте удаления

unset($this->session->data['order_id']);


$totals = $this->model_account_order->getOrderTotals($order_info['order_id']);

Перенести unset($this->session->data['order_id']); в конец скрипта?

Share this post


Link to post
Share on other sites

Убрал unset($this->session->data['order_id']); 

 

$totals = $this->model_account_order->getOrderTotals($this->session->data['order_id']);

Результат:

array(0) { }

Share this post


Link to post
Share on other sites

Как еще можно получить итоговую сумму заказа?

Share this post


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

Написал выше, что ваш код рабочий. Но почему-то контент скрыт.

https://monosnap.com/file/xPKgKfreYoBwELv6GNHw8o9ywx4kb8

Странно! На локальной копии сайта , и на хостинге не работает!))) Возвращает пустой результат.

Edited by mario512

Share this post


Link to post
Share on other sites

Странно, часть сообщений в этой ветке скрытые...

Share this post


Link to post
Share on other sites

На локальной копии сайта , и на хостинге не работает!))) Возвращает пустой результат.

Share this post


Link to post
Share on other sites

так это возможно только после  success заказ
А также до unset($this->session->data['oreder_id']

Share this post


Link to post
Share on other sites

@chukcha, @ibond, @fanatic спасибо за помощь. Проблема в том, что записей в данной таблице нет. В каком случае идет запись в oc_order_total? Когда применяются купоны и скидки?

Share this post


Link to post
Share on other sites

при создании/редактировании заказа, когда применяются сущности из "учитывать в заказе"

Share this post


Link to post
Share on other sites
7 часов назад, AlexDW сказал:

при создании/редактировании заказа, когда применяются сущности из "учитывать в заказе"

СПАСИБО!

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.