function createaddress() { global $db, $user; if ($user->isLoggedIn()) { // save the address, make it default if it is the users first one $address = new address(); $count = $address->find('count', 'user_id=' . $user->id); if ($count == 0) { $this->params['is_default'] = 1; } $this->params['user_id'] = $user->id; $address->update($this->params); // set the billing/shipping method if (isset($this->params['addresstype'])) { if ($this->params['addresstype'] == 'shipping') { $shipping = new shipping(); $shipping->shippingmethod->setAddress($address); } elseif ($this->params['addresstype'] == 'billing') { $billing = new billing(); $billing->billingmethod->setAddress($address); } } } redirect_to(array('controller' => 'cart', 'action' => 'checkout')); }