Post by odyssus » Tue May 17, 2022 11:16 pm

I created the following code in model

Code: Select all

public function coupon_test() { 
        $charscode = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $res = "";
        for ($i = 0; $i < 10; $i++) {
        $res .= $charscode[mt_rand(0, strlen($charscode)-1)];
        }
       $this->db->query("INSERT INTO `" . DB_PREFIX . "coupon` SET name = 'Newsletter coupon', code = '" .$res . "', type = 'P', 
       discount = '10', logged = '0', shipping = '0', total = '0', date_start = CURRENT_DATE(), 
       date_end = DATE_ADD(CURRENT_DATE(), INTERVAL 6 DAY), status = '1', date_added = NOW()");  
               
         
            }
and in controller

Code: Select all

public function Ajaxcallacumba() {
        $this->load->model('total/coupon');
        $this->model_total_coupon->coupon_test();
        
        
    }
What i want is to be able to use in my controller function either the variable $res from my model or call the code variable from the database. How can i do this. I have opencart 2.1.0.2

Newbie

Posts

Joined
Mon May 09, 2022 4:37 pm

Post by DigitCart » Tue May 17, 2022 11:45 pm

Hi
Use 'return'. Do it like this:

Code: Select all

public function coupon_test() { 
	// your code here
	// ...
	
	return $res;
}

Code: Select all

public function Ajaxcallacumba() {
	$this->load->model('total/coupon');
	
	$res = $this->model_total_coupon->coupon_test();
}

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by odyssus » Tue May 17, 2022 11:59 pm

DigitCart wrote:
Tue May 17, 2022 11:45 pm
Hi
Use 'return'. Do it like this:

Code: Select all

public function coupon_test() { 
	// your code here
	// ...
	
	return $res;
}

Code: Select all

public function Ajaxcallacumba() {
	$this->load->model('total/coupon');
	
	$res = $this->model_total_coupon->coupon_test();
}
Thanks you, you saved me!

Newbie

Posts

Joined
Mon May 09, 2022 4:37 pm

Post by straightlight » Wed May 18, 2022 4:35 am

odyssus wrote:
Tue May 17, 2022 11:59 pm
DigitCart wrote:
Tue May 17, 2022 11:45 pm
Hi
Use 'return'. Do it like this:

Code: Select all

public function coupon_test() { 
	// your code here
	// ...
	
	return $res;
}

Code: Select all

public function Ajaxcallacumba() {
	$this->load->model('total/coupon');
	
	$res = $this->model_total_coupon->coupon_test();
}
Thanks you, you saved me!
Now that the issue has been posted and duplicated, please add: [SOLVED] at the beginning of the subject line on your first post.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by grgr » Wed May 18, 2022 3:02 pm

You should maybe check that the coupon code does not already exist in the database before you try inserting it.

-
Image Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by straightlight » Wed May 18, 2022 5:52 pm

By using confirm() and unconfirm() methods in the order totals, that can also be validated with the coupon codes.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON
Who is online

Users browsing this forum: No registered users and 157 guests