Post by wonderland » Fri Dec 28, 2012 4:20 am

Hello!

I needed to create 5 additional fields for user, so I decided to add them after "company" field.

I edited files in catalog/controller, catalog/model and catalog/view for front-end of the site and
admin/controller, admin/model and admin/view for back-end of the site

I also added new columns in "address" table of database.

Since these new fields were pretty much the same as "company" field, 1 line of text and not mandatory, I used "company" fields code as a guide to create my other fields.

At the moment everything is almost fine, I'm experiencing 1 problem, which I don't know how to fix or why is it present.

When I register account from front-end, I see all the new fields I can fill them with no problem, after registering an account information from these fields gets written to database. I can also edit/change these fields and this information will get updated in database. Everything is great when working from font-end.

Problems start with back-end. When I try to view user account "address" tab (where company field and my new fields are located) from administration panel. For some reason address information is displayed from another account, although in front-end right address information (including my custom fields) is displayed.

I also tried creating account from administration panel, in this case I can also fill my custom fields with no problem, and information from these fields also gets written to database. I can even view "address" information in front-end.

I'm using oc 1.5.1.3

New member

Posts

Joined
Wed Jun 15, 2011 8:25 pm

Post by pedro1993 » Fri Dec 28, 2012 4:28 am

It is hard to pin-point the problem with no code.

Could you first of all check the database and make sure all of the data match. Could you also post these two files:
admin/controller and admin/model (the 2 files you edited to show the additional customer data)

Peter :)

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by wonderland » Fri Dec 28, 2012 5:05 am

Thank you for a fast response!

It seems that everything matches, I just tried creating account new account and data from custom fields did get written to database exactly as I wrote it.

I added the 2 files in a zip file.

new fields are:
reg_no
bank
account
swift
http

New member

Posts

Joined
Wed Jun 15, 2011 8:25 pm

Post by pedro1993 » Fri Dec 28, 2012 5:30 am

Well that eliminates the database end. One other question before I have a look at the code, do the fields show the data for a specific customer? For example is it always showing the details for the first customer in the database?

Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by pedro1993 » Fri Dec 28, 2012 5:57 am

Could you try the following and let me know what happens.

In the model file search for

Code: Select all

return $address_data;
Right above that can you add this code

Code: Select all

print_r($address_data);
Also, in the model file can you change the following code from:

Code: Select all

$address_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE customer_id = " . (int)$address_id . "");
to:

Code: Select all

$address_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE address_id = " . (int)$address_id . "");
Let me know what happens when you change that :)
Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by wonderland » Fri Dec 28, 2012 3:54 pm

To answer the first question - Each time I created new user, information displayed was from another user, it wasn't a specific user.

Thank you for providing these suggestions!

When I added

Code: Select all

print_r($address_data);
it caused some additional problems, but I removed it

But when I used

Code: Select all

$address_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE address_id = " . (int)$address_id . "");
it solved my problem. :)

I'm sorry If I'm being a bit rude but I have another question, it seems that I already found a fix, just wanted to ask if it's ok.

It is also regarding file customer.php file located in admin/model/sale

When viewing order details from back end I get this error "Notice: Undefined index: address_id in /admin/model/sale/customer.php on line 218"

code for line 215 - 218

Code: Select all

	
public function getAddress($address_id) {
		$address_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE address_id = " . (int)$address_id . "");
		
		$default_query = $this->db->query("SELECT address_id FROM " . DB_PREFIX . "customer WHERE address_id = '" . (int)$address_query->row['address_id'] . "'");	
Code in question (line 218) is one line below the fix you just provided, it seemed to me that this might be some leftover from some earlier mod (I didn't know about vqmod at first :( ), so I removed this line, which immediately fixed this error.
Is it safe to remove this line ?

Thank you again!

New member

Posts

Joined
Wed Jun 15, 2011 8:25 pm

Post by pedro1993 » Fri Dec 28, 2012 10:59 pm

I would leave it there, it is there for a reason and it may affect other parts of the admin panel because models can be used in various different locations in the admin panel.
The error is correct. $query->row['address_id'] is not being defined anywhere in the function. Try change it to this:

Code: Select all

$default_query = $this->db->query("SELECT address_id FROM " . DB_PREFIX . "customer WHERE address_id = '" . (int)$address_id. "'"); 
Let me know how you get on :)

Thanks
Peter

For OpenCart & PHP/MySQL support feel free to PM me :)
Click here for my extentions
Did I help you? Donate here to show support


Active Member

Posts

Joined
Tue Oct 18, 2011 4:31 am
Location - Glasgow, Scotland

Post by wonderland » Thu Jan 03, 2013 6:07 pm

This worked perfectly.

Thank you very much!

New member

Posts

Joined
Wed Jun 15, 2011 8:25 pm
Who is online

Users browsing this forum: No registered users and 115 guests