Перейти до вмісту
Пошук в
  • Детальніше...
Шукати результати, які ...
Шукати результати в ...

Вывод заказов и товаров к ним на странице аккаунта


Recommended Posts

Делаю вывод заказов и товаров к ним на странице аккаунта (OcStore 3).

Заказы выводятся правильно (номер, дата, стоимость), а вот товары внутри заказа показываются только по самому первому заказу в списке.

 

<?php
//ORDERS

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

$this->load->model('account/order');

$order_info = $this->model_account_order->getOrder($order_id);

$results = $this->model_account_order->getOrders();

foreach ($results as $result) {

	$data['orders'][] = array(
		'order_id'   => $result['order_id'],
		'name'       => $result['firstname'] . ' ' . $result['lastname'],
		'status'     => $result['status'],
		'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
		'products'   => ($product_total + $voucher_total),
		'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
		'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
	);
	
}

// PRODUCTS_FOR_ORDERS

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

$this->load->model('catalog/product');

$products = $this->model_account_order->getOrderProducts($result['order_id']);

foreach ($products as $product) {

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

	if ($product_info['image']) {
		$image = '/image/' . $product_info['image'];
	} else {
		$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
	}

	$data['products'][] = array(
		'name'     => $product['name'],
		'thumb'    => $image,
		'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']),
		'href'        => $this->url->link('product/product', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], true)
	);
}

 

Если в строке $products = $this->model_account_order->getOrderProducts($result['order_id']);
$result['order_id'] поменять на номер заказа, то показывают товары уже правильно относительно заказа, но тоже во всех заказах в списке.

 

Не могу правильно сформулировать зависимость товаров к заказу :(

 

Подскажите, пожалуйста, в каком месте натупил? Можно коротко.

Надіслати
Поділитися на інших сайтах


Спробуйте так

<?php
//ORDERS

$data['orders'] = [];

$this->load->model('account/order');

$order_info = $this->model_account_order->getOrder($order_id);

$results = $this->model_account_order->getOrders();

foreach ($results as $result) {
	
	$prod['products'] = [];

	$this->load->model('catalog/product');

	$products = $this->model_account_order->getOrderProducts($result['order_id']);

	foreach ($products as $product) {

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

		if ($product_info['image']) {
			$image = '/image/' . $product_info['image'];
		} else {
			$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
		}

		$prod['products'][] = array(
			'name'     => $product['name'],
			'thumb'    => $image,
			'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']),
			'href'        => $this->url->link('product/product', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], true)
		);
	}

	$data['orders'][] = array(
		'order_id'   => $result['order_id'],
		'name'       => $result['firstname'] . ' ' . $result['lastname'],
		'status'     => $result['status'],
		'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
		'products'   => ($product_total + $voucher_total),
		'product_info' => $prod['products'],
		'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
		'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
	);
	
}

 

Надіслати
Поділитися на інших сайтах

В 22.08.2022 в 11:49, S_A_P сказав:

Спробуйте так

<?php
//ORDERS

$data['orders'] = [];

$this->load->model('account/order');

$order_info = $this->model_account_order->getOrder($order_id);

$results = $this->model_account_order->getOrders();

foreach ($results as $result) {
	
	$prod['products'] = [];

	$this->load->model('catalog/product');

	$products = $this->model_account_order->getOrderProducts($result['order_id']);

	foreach ($products as $product) {

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

		if ($product_info['image']) {
			$image = '/image/' . $product_info['image'];
		} else {
			$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
		}

		$prod['products'][] = array(
			'name'     => $product['name'],
			'thumb'    => $image,
			'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']),
			'href'        => $this->url->link('product/product', 'order_id=' . $order_info['order_id'] . '&product_id=' . $product['product_id'], true)
		);
	}

	$data['orders'][] = array(
		'order_id'   => $result['order_id'],
		'name'       => $result['firstname'] . ' ' . $result['lastname'],
		'status'     => $result['status'],
		'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
		'products'   => ($product_total + $voucher_total),
		'product_info' => $prod['products'],
		'total'      => $this->currency->format($result['total'], $result['currency_code'], $result['currency_value']),
		'view'       => $this->url->link('account/order/info', 'order_id=' . $result['order_id'], true),
	);
	
}

 

 

не прокатило :( ошибок нет, но товары в заказе просто не выводятся

Надіслати
Поділитися на інших сайтах


22.08.2022 в 15:05, sdinft сказал:

 

не прокатило :( ошибок нет, но товары в заказе просто не выводятся

А Ви виводили product_info? В ній вся інфа про продукти в замовлені

Вивести можна якось так...

<div>
	<?php foreach ($orders as $order) { ?>
    <div>
		<?php foreach ($order['product_info'] as $product_info) { ?>
        <div>
          <a href="<?php echo $product_info['href']; ?>">
            <img src="<?php echo $product_info['image']; ?>" alt="<?php echo $product_info['name']; ?>" title="<?php echo $product_info['name']; ?>">
          </a>
          <div>
            <div>
              <a href="<?php echo $product_info['href']; ?>"><?php echo $product_info['name']; ?></a>
            </div>
            <div>
              <div><?php echo $product_info['price']; ?></div>
              <div><div><?php echo $product_info['total']; ?></div></div>
              <div><?php echo $product_info['quantity']; ?></div>
            </div>
          </div>
      </div>
     <?php } ?>
  </div>
<?php } ?>

 

Надіслати
Поділитися на інших сайтах

Створіть аккаунт або увійдіть для коментування

Ви повинні бути користувачем, щоб залишити коментар

Створити обліковий запис

Зареєструйтеся для отримання облікового запису. Це просто!

Зареєструвати аккаунт

Вхід

Уже зареєстровані? Увійдіть тут.

Вхід зараз
  • Зараз на сторінці   0 користувачів

    • Ні користувачів, які переглядиють цю сторінку

×
×
  • Створити...

Important Information

На нашому сайті використовуються файли cookie і відбувається обробка деяких персональних даних користувачів, щоб поліпшити користувальницький інтерфейс. Щоб дізнатися для чого і які персональні дані ми обробляємо перейдіть за посиланням . Якщо Ви натиснете «Я даю згоду», це означає, що Ви розумієте і приймаєте всі умови, зазначені в цьому Повідомленні про конфіденційність.