Jump to content

[ Solved] function add address ?


vermich

Recommended Posts

Hi everybody ,

 

I need your help. I would like to change address customer after registration. I made a module whitch add customer to a group. There is a function to change address? or i have just to write an "Insert" ?

 

public function hookcreateAccount($params)

{

//this is the customer object

$customer = $params['newCustomer'];

$codece = Tools::getValue('codece'); // code compagny from registration

$sql = "SELECT id_group FROM ps_group_lang WHERE code = '$codece'"; //

$id_default_group = (int)Db::getInstance()->getValue($sql);

$groupsToAdd=array();

array_push($groupsToAdd,$id_default_group);

$customer->updateGroup($groupsToAdd);

$this->setDefaultGroupId($customer->id,$id_default_group);

$sql = "SELECT adress1 FROM ps_group_lang WHERE code = '$codece'";

$address1 = (int)Db::getInstance()->getValue($sql);

$sql = "SELECT adress2 FROM ps_group_lang WHERE code = '$codece'";

$address2 = (int)Db::getInstance()->getValue($sql);

$sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'";

$postcode = (int)Db::getInstance()->getValue($sql);

$sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'";

$city = (int)Db::getInstance()->getValue($sql);

 

**add address to customer **

}

Edited by vermich (see edit history)
Link to comment
Share on other sites

i take a look at addresscontroler and that's what i suppose to use ? i'm little bit lost with cart address or deleting previous address.

 

 

  $address = new Address();
    $address->id_customer = (int)$this->context->customer->id;

    $sql = "SELECT adress1 FROM ps_group_lang WHERE code = '$codece'";
    $address1 = (int)Db::getInstance()->getValue($sql);
    $address->address1 = $address1;
    $sql = "SELECT adress2 FROM ps_group_lang WHERE code = '$codece'";
    $address2 = (int)Db::getInstance()->getValue($sql);
    $address->address2 = $address2;
    $sql = "SELECT postcode FROM ps_group_lang WHERE code = '$codece'";
    $postcode = (int)Db::getInstance()->getValue($sql);
    $address->address1 = $postcode;
    $sql = "SELECT city FROM ps_group_lang WHERE code = '$codece'";
    $city = (int)Db::getInstance()->getValue($sql);
    $address->address1 = $city;





  // If we edit this address, delete old address and create a new one
 if (Validate::isLoadedObject($this->_address))
 {
  if (Validate::isLoadedObject($country) && !$country->contains_states)
   $address->id_state = 0;
  $address_old = $this->_address;
  if (Customer::customerHasAddress($this->context->customer->id, (int)$address_old->id))
  {
   if ($address_old->isUsed())
 $address_old->delete();
   else
   {
 $address->id = (int)($address_old->id);
 $address->date_add = $address_old->date_add;
   }
  }
 }

  if ($result = $address->save())
 {  
  // Update id address of the current cart if necessary
  if (isset($address_old) && $address_old->isUsed())
   $this->context->cart->updateAddressId($address_old->id, $address->id);
  else // Update cart address
   $this->context->cart->autosetProductAddress();
	    if ((bool)(Tools::getValue('select_address', false)) == true OR Tools::getValue('type') == 'invoice' && Configuration::get('PS_ORDER_PROCESS_TYPE'))
	    {
		    $this->context->cart->id_address_invoice = (int)$address->id;
		    $this->context->cart->update();			   
	    }

 }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...