public function updateShipping($data) { //update the users shipping address $this->validateAddress($data); $customer = new Customer(); $customer->setValue("shipping_first_name", trim($data['fName'])); Session::set('shipping_first_name', trim($data['fName'])); $customer->setValue("shipping_last_name", trim($data['lName'])); Session::set('shipping_last_name', trim($data['lName'])); $address = array("address1" => trim($data['addr1']), "address2" => trim($data['addr2']), "city" => trim($data['city']), "state_province" => trim($data['state']), "postal_code" => trim($data['postal']), "country" => trim($data['count'])); $customer->setValue("shipping_address", $address); Session::set('shipping_address', $address); }
public function completeOrder() { $smID = \Session::get('smID'); $groupstoadd = array(); $createlogin = false; $orderItems = $this->getOrderItems(); $customer = new Customer(); foreach ($orderItems as $orderItem) { $product = $orderItem->getProductObject(); if ($product && $product->hasUserGroups()) { $groupstoadd = array_merge($groupstoadd, $product->getProductUserGroups()); } if ($product && $product->pCreateUserAccount) { $createlogin = true; } } if ($createlogin && $customer->isGuest()) { $email = $customer->getEmail(); $user = UserInfo::getByEmail($email); if (!$user) { $password = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 10); $mh = Loader::helper('mail'); $mh->addParameter('siteName', Config::get('concrete.site')); $navhelper = Core::make('helper/navigation'); $target = Page::getByPath('/login'); if ($target) { $link = $navhelper->getLinkToCollection($target, true); if ($link) { $mh->addParameter('link', $link); } } else { $mh->addParameter('link', ''); } $valc = Loader::helper('concrete/validation'); $min = Config::get('concrete.user.username.minimum'); $max = Config::get('concrete.user.username.maximum'); $newusername = preg_replace("/[^A-Za-z0-9_]/", '', strstr($email, '@', true)); while (!$valc->isUniqueUsername($newusername) || strlen($newusername) < $min) { if (strlen($newusername) >= $max) { $newusername = substr($newusername, 0, $max - 5); } $newusername .= rand(0, 9); } $user = UserInfo::add(array('uName' => $newusername, 'uEmail' => trim($email), 'uPassword' => $password)); if (Config::get('concrete.user.registration.email_registration')) { $mh->addParameter('username', trim($email)); } else { $mh->addParameter('username', $newusername); } $mh->addParameter('password', $password); $email = trim($email); $mh->load('new_user', 'vivid_store'); // login the newly created user User::loginByUserID($user->getUserID()); } else { // we're attempting to create a new user with an email that has already been used // earlier validation must have failed at this point, don't fetch the user $user = null; } $mh->to($email); $mh->sendMail(); } elseif ($createlogin) { // or if we found a user (because they are logged in) and need to use it to create logins $user = $customer->getUserInfo(); } if ($user) { // $user is going to either be the new one, or the user of the currently logged in customer // update the order created with the user from the newly created user $this->associateUser($user->getUserID()); $billing_first_name = $customer->getValue("billing_first_name"); $billing_last_name = $customer->getValue("billing_last_name"); $billing_address = $customer->getValueArray("billing_address"); $billing_phone = $customer->getValue("billing_phone"); $shipping_first_name = $customer->getValue("shipping_first_name"); $shipping_last_name = $customer->getValue("shipping_last_name"); $shipping_address = $customer->getValueArray("shipping_address"); // update the user's attributes $customer = new Customer($user->getUserID()); $customer->setValue('billing_first_name', $billing_first_name); $customer->setValue('billing_last_name', $billing_last_name); $customer->setValue('billing_address', $billing_address); $customer->setValue('billing_phone', $billing_phone); if ($smID) { $customer->setValue('shipping_first_name', $shipping_first_name); $customer->setValue('shipping_last_name', $shipping_last_name); $customer->setValue('shipping_address', $shipping_address); } //add user to Store Customers group $group = \Group::getByName('Store Customer'); if (is_object($group) || $group->getGroupID() < 1) { $user->enterGroup($group); } foreach ($groupstoadd as $id) { $g = Group::getByID($id); if ($g) { $user->getUserObject()->enterGroup($g); } } $user->refreshUserGroups(); } VividCart::clearCode(); // create order event and dispatch $event = new OrderEvent($this); Events::dispatch('on_vividstore_order', $event); //send out the alerts $mh = new MailService(); $pkg = Package::getByHandle('vivid_store'); $fromEmail = Config::get('vividstore.emailalerts'); if (!$fromEmail) { $fromEmail = "store@" . $_SERVER['SERVER_NAME']; } $alertEmails = explode(",", Config::get('vividstore.notificationemails')); $alertEmails = array_map('trim', $alertEmails); //receipt $mh->from($fromEmail); $mh->to($customer->getEmail()); $mh->addParameter("order", $this); $mh->load("order_receipt", "vivid_store"); $mh->sendMail(); $validNotification = false; //order notification $mh->from($fromEmail); foreach ($alertEmails as $alertEmail) { if ($alertEmail) { $mh->to($alertEmail); $validNotification = true; } } if ($validNotification) { $mh->addParameter("order", $this); $mh->load("new_order_notification", "vivid_store"); $mh->sendMail(); } // unset the shipping type, as next order might be unshippable \Session::set('smID', ''); VividCart::clear(); return $this; }