Post by myshadowself » Tue Jun 07, 2011 9:16 pm

Hi all

I'm using OC version 1.4.9.5

I'm creating a wholesale only shop for my business - all customers are businesses, not individuals - so I'm trying to make modifications to suit. I'd say my coding skills are above average, but I'm struggling to get my head around how OC does certain things. Hopefully someone with OpenCart experience can help me.
  1. In customer's accounts, I see a "Company Name" field, but this is not required, how can I make this required?

    I would like access to the customer's "Company Name" variable throughout the site for a welcome message displayed in the header, how can I do this?

    In the admin section, under Sales->Customers (admin/index.php?route=sale/customer) I would like "Customer name" to be the "Company Name" instead of the First+Last Names. Is this possible?
I would like to keep the First+Last names of the customer as contacts, so I'm not really up for modifying these to suit.

Any help would be greatly appreciated.

Thanks in advance.

Andy

Ronald Laughton is the worst referee in Rugby League


New member

Posts

Joined
Tue Jun 07, 2011 8:59 pm

Post by myshadowself » Wed Jun 08, 2011 2:47 am

OK, I think I've sussed the first part of it.

Looking through the Database structure and the data already available, it seemed to me like I'd have to create this myself, rather than just reference it.

So, in catalog/controller/common/header.php, I added this method:

Code: Select all

	public function getCustomerDetails($customer_id){
	
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
		$query1 = $this->db->query("SELECT * FROM " . DB_PREFIX . "address WHERE customer_id = '" . (int)$customer_id . "'");
		$query->row = array_merge($query->row,$query1->row);
		
		return $query->row;
	}

which gives me this extra array of data to play with:

Code: Select all

Array
(
    [customer_id] => 2
    [store_id] => 0
    [firstname] => Andy
    [lastname] => SURNAME
    [email] => me@mydomain.com
    [telephone] => 12345 6789012
    [fax] => 
    [password] => 70ae291a4e7365bhafsohfc5ba8b618cab
    [cart] => a:4:{i:51;i:1;i:55;i:1;s:10:"79:613.616";i:4;s:10:"79:619.622";i:1;}
    [newsletter] => 0
    [address_id] => 3
    [status] => 1
    [approved] => 1
    [customer_group_id] => 6
    [ip] => 123.456.789.012
    [date_added] => 2011-05-31 00:33:59
    [company] => My Company Ltd
    [address_1] => My Address
    [address_2] => My Address
    [postcode] => My Postcode
    [city] => York
    [country_id] => 222
    [zone_id] => 3576
)

and now in catalog/view/theme/MYTHEME/template/common/header.tpl, I have this:

Code: Select all

<?php
$customer_details = $this->getCustomerDetails($this->customer->isLogged());
?>
so I can get the company name like this (or indeed, any of the variables contained in that array):

Code: Select all

<?php
echo $customer_details['company'];
?>
Now, I REALLY wanted to merge the data from the address DB table into the current Customer Object, but I still can't get my head around this OC MVC malarky. If anyone could point me in the right direction to make this neater, or has any other suggestions to help in my other quests, they'd be greatly appreciated.

Cheers

Ronald Laughton is the worst referee in Rugby League


New member

Posts

Joined
Tue Jun 07, 2011 8:59 pm
Who is online

Users browsing this forum: Bing [Bot] and 12 guests