function createOrderCustomerAccount($order, $accountDetails) { $autoAccount = false; if(empty($accountDetails['password'])) { $accountDetails['password'] = substr(md5(uniqid(true)), 0, 8); $autoAccount = true; } $savedata = array( 'custconemail' => $order['ordbillemail'], 'custpassword' => $accountDetails['password'], 'custconfirstname' => $order['ordbillfirstname'], 'custconlastname' => $order['ordbilllastname'], 'custconcompany' => $order['ordbillcompany'], 'custconphone' => $order['ordbillphone'], 'customertoken' => generateCustomerToken(), ); if(!empty($accountDetails['customFormFields'])) { $savedata['custformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($accountDetails['customFormFields']); } $customerId = getClass('ISC_CUSTOMER') ->CreateCustomerAccount($savedata, true, $autoAccount); if(!$customerId) { return; } // OK, we've added in the customer, now for the addresses if (isset($accountDetails['addresses']) && is_array($accountDetails['addresses'])) { $shippingEntity = new ISC_ENTITY_SHIPPING; foreach($accountDetails['addresses'] as $address) { $address['shipcustomerid'] = $customerId; // If our address is unique then stick it in (the database that is :)) if (!$shippingEntity->basicSearch($address)) { // OK, its unique. We now need to save the custom form data (if we have to) and then the // shipping record if (isset($address['customFormFields']) && is_array($address['customFormFields'])) { $address['shipformsessionid'] = $GLOBALS['ISC_CLASS_FORM']->saveFormSessionManual($address['customFormFields']); if (!isId($address['shipformsessionid'])) { unset($address['shipformsessionid']); } } $shippingEntity->add($address); } } } if(!$autoAccount) { getClass('ISC_CUSTOMER')->LoginCustomerById($customerId, true); } // Lastly, we need to update the orders with this new customer ID $savedata = array( "ordcustid" => $customerId ); $GLOBALS["ISC_CLASS_DB"]->UpdateQuery("orders", $savedata, "orderid='".$order['orderid']."'"); }
private function SaveNewShippingAddress() { $entity = new ISC_ENTITY_SHIPPING(); $shippingData = $entity->get($_POST['shipid']); $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, true); /** * Validate the field input */ $errmsg = ''; if (!$this->validateFieldData($fields, $errmsg)) { return $this->AddShippingAddress($errmsg, MSG_ERROR); } $ShippingAddress = $this->parseFieldData($fields); if (isset($ShippingAddress['shipfirstname']) && isset($ShippingAddress['shipaddress1'])) { $entity = new ISC_ENTITY_SHIPPING(); if (isId($shippingid = $entity->add($ShippingAddress))) { if (isset($_SESSION['LOGIN_REDIR'])) { // Take them to the page they wanted $page = $_SESSION['LOGIN_REDIR']; unset($_SESSION['LOGIN_REDIR']); header(sprintf("Location: %s", $page)); } else { // Take them to the my account page header(sprintf("Location: %s/account.php", $GLOBALS['ShopPath'])); } } else { // Database error ob_end_clean(); header(sprintf("location:%s/%s", $GLOBALS['ShopPath'], 'account.php?action=add_shipping_address')); die; } } else { // Bad details ob_end_clean(); header(sprintf("location:%s/%s", $GLOBALS['ShopPath'], 'account.php?action=add_shipping_address')); die; } }