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']."'"); }
/** * Map and build the address form fields * * Method will call mapFieldData() to map the field data and then biuld each * field HTML * * @access private * @param array $fields The field list * @param array $data The optional database record to map against * @return string The constructed HTML on success, empty string on failure */ private function buildFieldData($addressId = 0, $customerId = 0) { $data = array(); /** * Do we have a valid address record ID? */ if (isId($addressId)) { /** * We must also have a customer ID */ if (!isId($customerId)) { $customerId = $GLOBALS['ISC_CLASS_CUSTOMER']->GetCustomerId(); } if (!isId($customerId)) { return ''; } $entity = new ISC_ENTITY_SHIPPING(); $data = $entity->get($addressId, $customerId); if (!$data) { return ''; } } $getFromRequest = false; $getFromFormSessionId = ''; if (isId($addressId) && isId($data['shipformsessionid'])) { $getFromFormSessionId = $data['shipformsessionid']; } else { $getFromRequest = true; } $fields = $GLOBALS['ISC_CLASS_FORM']->getFormFields(FORMFIELDS_FORM_ADDRESS, $getFromRequest, $getFromFormSessionId); /** * OK, we got the fields, now we need to map the database record to it. This method has to * be called as it also adds in the country and state options, so call this regardless */ if (!$this->mapFieldData($fields, $data)) { return ''; } /** * Remove the 'Save this address' option as this is for single page checkout only */ $html = ''; foreach (array_keys($fields) as $fieldId) { if (isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'savethisaddress' || isc_strtolower($fields[$fieldId]->record['formfieldprivateid']) == 'shiptoaddress') { continue; } $html .= $fields[$fieldId]->loadForFrontend(); } return $html; }