Post by elpidios » Fri Sep 07, 2018 3:49 am

Hi
I have created the following code (CODE1) which is working very good and save my custom field. Unfortunately my other code (CODE2) which doing the same thing is not working. Do you have any idea what is going wrong?
CODE 1

Code: Select all

 public function assignaccount() {
			if(isset($this->request->get['login'])){
				$data['email'] = $this->customer->getEmail();
				$this->load->model('account/customer');
				$customer_info = $this->model_account_customer->getCustomerByEmail($this->customer->getEmail());
				if($customer_info){
					$custom_field = json_decode($customer_info['custom_field']);
					$cust = array();
					foreach($custom_field as $key=>$c){
						$cust[$key] = $c;
						if($key == 11){
							$cust[$key] = $this->request->get['login'];
						}
					}
					$this->db->query("UPDATE " . DB_PREFIX . "customer SET custom_field = '" . $this->db->escape(json_encode($cust))."' WHERE LCASE(email) = '" . $this->db->escape(utf8_strtolower($this->customer->getEmail())) . "'");
					
CODE 2

Code: Select all

public function assignaccounteur() {
         if(isset($this->request->get['login'])){
            $data['email'] = $this->customer->getEmail();
            $this->load->model('account/customer');
            $customer_info = $this->model_account_customer->getCustomerByEmail($this->customer->getEmail());
            if($customer_info){
               $custom_field = json_decode($customer_info['custom_field']);
               $cust = arrayeuro();
               foreach($custom_field as $key=>$c){
                  $cust[$key] = $c;
                  if($key == 12){
                     $cust[$key] = $this->request->get['login'];
                  }
               }
               $this->db->query("UPDATE " . DB_PREFIX . "customer SET custom_field = '" . $this->db->escape(json_encode($cust))."' WHERE LCASE(email) = '" . $this->db->escape(utf8_strtolower($this->customer->getEmail())) . "'");
               
Last edited by straightlight on Thu Feb 27, 2020 12:29 pm, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Wed Feb 28, 2018 2:26 am

Post by straightlight » Fri Sep 07, 2018 3:51 am

As a new forum user, please read the forum rules. No OC version posted, unelaborated request. Dumped 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

Post by elpidios » Fri Sep 07, 2018 4:32 am

straightlight wrote:
Fri Sep 07, 2018 3:51 am
As a new forum user, please read the forum rules. No OC version posted, unelaborated request. Dumped codes.
Thanks for your answer. If i am not wrong you mentioned me yesterday the same about OC version. So we need to write the exact version and not only Opencart 3?
My opencart Version is 3.0.2.0
Can you help me please with my code what you mean duplicate? I am new to opencart and also in php and i am reading lot of articles every day.
If you could make me a good tip to understand what you mean will be very usefull for me
thanks

New member

Posts

Joined
Wed Feb 28, 2018 2:26 am

Post by elpidios » Fri Sep 07, 2018 3:41 pm

now i have change the code to this. if working fine but else if is not working

Code: Select all

    public function assignaccount() {
			if(isset($this->request->get['login'])){
				$data['email'] = $this->customer->getEmail();
				$this->load->model('account/customer');
				$customer_info = $this->model_account_customer->getCustomerByEmail($this->customer->getEmail());
				if($customer_info){
					$custom_field = json_decode($customer_info['custom_field']);
					$cust = array();
					foreach($custom_field as $key=>$c){
						$cust[$key] = $c;
						if($key == 11){
							$cust[$key] = $this->request->get['login'];
						}
					}
					$this->db->query("UPDATE " . DB_PREFIX . "customer SET custom_field = '" . $this->db->escape(json_encode($cust))."' WHERE LCASE(email) = '" . $this->db->escape(utf8_strtolower($this->customer->getEmail())) . "'");
					}


					elseif($customer_info){
					$custom_field = json_decode($customer_info['custom_field']);
					$cust = arrayeuro();
					foreach($custom_field as $key=>$c){
						$cust[$key] = $c;
						if($key == 12){
							$cust[$key] = $this->request->get['login'];
						}
					}
					$this->db->query("UPDATE " . DB_PREFIX . "customer SET custom_field = '" . $this->db->escape(json_encode($cust))."' WHERE LCASE(email) = '" . $this->db->escape(utf8_strtolower($this->customer->getEmail())) . "'");
					}
			}
	   }
	   

but still not working
any recomendations?
Last edited by straightlight on Thu Feb 27, 2020 12:29 pm, edited 1 time in total.
Reason: Added code tags.

New member

Posts

Joined
Wed Feb 28, 2018 2:26 am

Post by thekrotek » Fri Sep 07, 2018 7:36 pm

Nobody will give you any recommendations, because nobody understands "not working" description of the issue. ALWAYS describe EVERY issue in detail and expand "not working" definition.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am

Who is online

Users browsing this forum: Bing [Bot], nonnedelectari, Semrush [Bot] and 406 guests