Post by katalin » Tue Apr 11, 2023 3:08 am

Hello guys, I am using a free extension that lists all the gift vouchers attached to an account and I need to paginate it. Can anyone help?
I am using OC 3.0.3.8
LE: Here's the extension I am using: https://www.opencart.com/index.php?rout ... n_id=37813
I want to mention that developer is not answering to emails.

Here is the code in catalog/controller/account/giftvoucher.php

Code: Select all

<?php
class ControllerAccountGiftvoucher extends Controller {
	public function index() {
		if (!$this->customer->isLogged()) {
			$this->session->data['redirect'] = $this->url->link('account/giftvoucher', '', true);

			$this->response->redirect($this->url->link('account/login', '', true));
		}

		$this->load->language('account/giftvoucher');

		$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_account'),
			'href' => $this->url->link('account/account', '', true)
		);

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

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

  	    $resultsss = $this->model_account_giftvoucher->getGifttotal();

		foreach ($resultsss as $result) {
			$data['gifttotal'][] = array(
				'voucher_id' => $result['voucher_id'],
				'total'      => $this->currency->format($result['total'], $this->config->get('config_currency'))
			);
		}

		$results = $this->model_account_giftvoucher->getVouchergift();

		foreach ($results as $result) {
			if ($result['amount'] + (float)$result['used'] > 0) {
				$data['vouchers'][] = array(
					'voucher_id'  => $result['voucher_id'],
					'code'        => $result['code'],
					'from_name'   => $result['from_name'],
					'date_added'  => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
					'amount'      => $this->currency->format($result['amount'], $this->config->get('config_currency')),
				);
			}
		}

		$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('account/giftvoucher', $data));
	}
}
Last edited by katalin on Sat Apr 15, 2023 11:31 pm, edited 1 time in total.

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by xxvirusxx » Tue Apr 11, 2023 4:40 am

See the code from transaction controller.

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by katalin » Tue Apr 11, 2023 12:30 pm

xxvirusxx wrote:
Tue Apr 11, 2023 4:40 am
See the code from transaction controller.
I am not that experienced. I tried some variants but didnt succeed, that’s why I asked for help here

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by katalin » Sat Apr 15, 2023 6:30 am

Anyone?

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by xxvirusxx » Sat Apr 15, 2023 3:06 pm

See if work

LE. Download below
Last edited by xxvirusxx on Sat Apr 15, 2023 7:38 pm, edited 1 time in total.

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by katalin » Sat Apr 15, 2023 7:00 pm

xxvirusxx wrote:
Sat Apr 15, 2023 3:06 pm
See if work
Pagination is displayed under the voucher list but for each page it displays all the results and adds 5 pages.

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by xxvirusxx » Sat Apr 15, 2023 7:29 pm

Now should work. Replace all files

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by katalin » Sat Apr 15, 2023 11:31 pm

xxvirusxx wrote:
Sat Apr 15, 2023 7:29 pm
Now should work. Replace all files
Works perfect. Thanks a lot!

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by katalin » Sun Apr 16, 2023 4:22 am

xxvirusxx wrote:
Sat Apr 15, 2023 7:29 pm
Now should work. Replace all files
I just noticed that now it returns all results, before your modification it returned only the vouchers that have remaining balance but now it returns all vouchers even if balance is 0. Can you help make it return the results as it was before? Thanks!

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by by mona » Sun Apr 16, 2023 6:51 am

Swap the controller (not tested)
.. and thank xxvirusxx he did all the work

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am

Post by katalin » Sun Apr 16, 2023 3:10 pm

by mona wrote:
Sun Apr 16, 2023 6:51 am
Swap the controller (not tested)
.. and thank xxvirusxx he did all the work
It works now but it shows results including the used vouchers. Total vouchers are 45 unused and 2 used and it displays: Showing 1 - 10 of 47 (5 pages). It should display just 45 results.

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by xxvirusxx » Sun Apr 16, 2023 5:19 pm

You can add that field. used > 0 to getTotalVouchers mysql function.

Code: Select all

$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher` v LEFT JOIN `" . DB_PREFIX . "customer` c ON(v.to_email = c.email) WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND v.used > 0");
Should work if used field is added in voucher table.
Because I don't know what changes was made before....
katalin wrote:
Wed Feb 01, 2023 8:07 pm
Someone helped me with this so it's solved now! Thanks for the help guys!

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by katalin » Sun Apr 16, 2023 7:25 pm

xxvirusxx wrote:
Sun Apr 16, 2023 5:19 pm
You can add that field. used > 0 to getTotalVouchers mysql function.

Code: Select all

$query = $this->db->query("SELECT COUNT(*) AS `total` FROM `" . DB_PREFIX . "voucher` v LEFT JOIN `" . DB_PREFIX . "customer` c ON(v.to_email = c.email) WHERE `customer_id` = '" . (int)$this->customer->getId() . "' AND v.used > 0");
Should work if used field is added in voucher table.
Because I don't know what changes was made before....
katalin wrote:
Wed Feb 01, 2023 8:07 pm
Someone helped me with this so it's solved now! Thanks for the help guys!
Fatal error: Uncaught Exception: Error: Unknown column 'v.used' in 'where clause'<br />Error No: 1054<br />SELECT COUNT(*) AS `total` FROM `ocmd_voucher` v LEFT JOIN `ocmd_customer` c ON(v.to_email = c.email) WHERE `customer_id` = '1' AND v.used > 0 in /home/urbanlin/public_html/system/library/db/mysqli.php:48 Stack trace: #0 /home/urbanlin/sitedata/storage/modification/system/library/db.php(55): DB\MySQLi->query('SELECT COUNT(*)...') #1

This is the old file:

Code: Select all

<?php
class ModelAccountGiftvoucher extends Model {
	public function getGifttotal() {
		$db = "SELECT v.voucher_id, (v.amount + SUM(vh.amount)) as total FROM " . DB_PREFIX . "voucher_history vh JOIN " . DB_PREFIX . "voucher v JOIN " . DB_PREFIX . "customer c WHERE v.voucher_id = vh.voucher_id AND v.to_email = c.email AND c.customer_id = '" . (int)$this->customer->getId() . "'"; $db .= " GROUP BY v.voucher_id";
		$result = $this->db->query($db);
		return $result->rows;
	}
	public function getVouchergift() {
		$db = "SELECT

		(SELECT SUM(vh.amount) FROM " . DB_PREFIX . "voucher_history vh WHERE v.voucher_id = vh.voucher_id) AS used,


		v.voucher_id, v.code, v.from_name, v.date_added, v.amount FROM " . DB_PREFIX . "voucher v JOIN " . DB_PREFIX . "customer c WHERE v.to_email = c.email AND c.customer_id = '" . (int)$this->customer->getId() . "'"; $db .= " ORDER BY v.date_added DESC";
		$query = $this->db->query($db);
		return $query->rows;
	}
}

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România

Post by katalin » Tue Apr 18, 2023 4:53 am

xxvirusxx wrote:
Mon Apr 17, 2023 9:56 pm
Try this model...
It doesn't work properly, it doesn't display results that still have an amout left. For example if a voucher total was 1000 and now is 200 it doesn't display it on the results page, it should only remove the vouchers with 0 balance remaining.

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by katalin » Fri Apr 21, 2023 8:25 pm

xxvirusxx wrote:
Mon Apr 17, 2023 9:56 pm
Try this model...
Can you make it work properly please?

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by katalin » Wed May 03, 2023 9:27 pm

xxvirusxx wrote:
Mon Apr 17, 2023 9:56 pm
Try this model...
Are you able to fix this issue please?

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by katalin » Sat Jun 03, 2023 8:14 pm

xxvirusxx wrote:
Mon Apr 17, 2023 9:56 pm
Try this model...
Is there any chance you can help me fix this so it works properly?

Active Member

Posts

Joined
Wed May 05, 2010 2:28 am

Post by xxvirusxx » Sun Jun 04, 2023 2:39 pm

I think controller need to be rewriten to work....

You can try to post on Commercial section...or wait an Expert to reply here...

Upgrade Service | OC 2.3.0.2 PHP 8 | My Custom OC 3.0.3.8 | Buy me a beer


User avatar
Expert Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm
Location - România
Who is online

Users browsing this forum: No registered users and 49 guests