Page 1 of 1

insert database custom fields code problem - Opencart 3

Posted: Fri Sep 07, 2018 3:49 am
by elpidios
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())) . "'");
               

Re: insert database custom fields code problem - Opencart 3

Posted: Fri Sep 07, 2018 3:51 am
by straightlight
As a new forum user, please read the forum rules. No OC version posted, unelaborated request. Dumped codes.

Re: insert database custom fields code problem - Opencart 3

Posted: Fri Sep 07, 2018 4:32 am
by elpidios
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

Re: insert database custom fields code problem - Opencart 3

Posted: Fri Sep 07, 2018 3:41 pm
by elpidios
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?

Re: insert database custom fields code problem - Opencart 3

Posted: Fri Sep 07, 2018 7:36 pm
by thekrotek
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.