function doSubmitEmailForm($data, $form) { $originalEmail = $email = trim(Convert::Raw2SQL($data['Email'])); $clientKey = trim(Convert::Raw2SQL($data['ClientKey'])); $order = ShopOrder::orderSession(); $clientID = $order->ClientID; if ($client = DataObject::get_one("ShopClient", "ClientKey LIKE '" . $clientKey . "'")) { //existing client $clientID = $client->ID; if ($lastOrder = DataObject::get_one("ShopOrder", "ClientID = {$clientID} AND Status != 'Unsubmitted'", null, "Created DESC")) { if ($addr = $lastOrder->InvoiceAddress()) { //use the last invoice adress, if empty if ($order->InvoiceAddressID == 0) { $newAddr = new ShopAddress(); $newAddr->merge($addr, 'right'); //restore the relations $newAddr->OrderID = $order->ID; $newAddr->ClientID = $clientID; $newAddr->write(); $order->InvoiceAddressID = $newAddr->ID; $order->write(); } } if ($addr = $lastOrder->DeliveryAddress()) { //use the last shipping adress, if empty if ($order->DeliveryAddressID == 0) { $newAddr = new ShopAddress(); $newAddr->merge($addr, 'right'); //restore the relations $newAddr->OrderID = $order->ID; $newAddr->ClientID = $clientID; $newAddr->write(); $order->DeliveryAddressID = $newAddr->ID; $order->write(); } } } } else { //create new client, if not $client = $order->Client() ? $order->Client() : new ShopClient(); $client->Status = "Customer"; if ($clients = DataObject::get("ShopClient", "Email LIKE '" . $email . "' OR Email LIKE 'shop.renamed.%." . $email . "'")) { $client->Email = "shop.renamed." . $clients->count() . "." . $email; $client->Status = "Guest"; } else { $client->Email = $email; } $client->ClientKey = ShopClient::generateClientKey($email); $client->Password = $client->ClientKey; $client->write(); //add to group $client->Groups()->add(DataObject::get_one("Group", "Title LIKE 'ShopClients'")); $client->write(); $clientID = $client->ID; //todo, send welcome email to client //create adress fields for invoice+shipping if ($order->InvoiceAddress()->ID == 0) { $a = new ShopAddress(); $a->ClientID = $clientID; $a->Email = $email; $a->OrderID = $order->ID; $a->write(); $order->InvoiceAddressID = $a->ID; } if ($order->DeliveryAddress()->ID == 0) { $a = new ShopAddress(); $a->ClientID = $clientID; $a->Email = $email; $a->OrderID = $order->ID; $a->write(); $order->DeliveryAddressID = $a->ID; } } $order->Email = $originalEmail; $order->ClientID = $clientID; $order->CouponCode = strtoupper(Convert::raw2SQL($data['CouponCode'])); $order->TaxIDNumber = Convert::raw2SQL($data['TaxIDNumber']); $client->ClientKey = $clientKey; $client->write(); $order->write(); $this->redirectToNextStepFrom("email"); return array(); }
function Salutation() { return ShopClient::salutationNice($this->Gender); }