Exemplo n.º 1
0
 public function view()
 {
     $customer = new Customer();
     $order = VividOrder::getByID($customer->getLastOrderID());
     if (is_object($order)) {
         $this->set("order", $order);
     } else {
         $this->redirect("/cart");
     }
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
 }
Exemplo n.º 2
0
 public function view()
 {
     $customer = new Customer();
     $order = VividOrder::getByID($customer->getLastOrderID());
     if (is_object($order)) {
         $this->set("order", $order);
     } else {
         $this->redirect("/cart");
     }
     $this->addFooterItem(Core::make('helper/html')->javascript('vivid-store.js', 'vivid_store'));
     $this->addHeaderItem(Core::make('helper/html')->css('vivid-store.css', 'vivid_store'));
 }
Exemplo n.º 3
0
 public function validateAddress($data, $billing = null)
 {
     $e = Core::make('helper/validation/error');
     $vals = Loader::helper('validation/strings');
     $customer = new Customer();
     if ($billing) {
         if ($customer->isGuest()) {
             if (!$vals->email($data['email'])) {
                 $e->add(t('You must enter a valid email address'));
             }
         }
     }
     if (strlen($data['fName']) < 1) {
         $e->add(t('You must enter a first name'));
     }
     if (strlen($data['fName']) > 30) {
         $e->add(t('Your First Name is quite long. Please keep it under 30 characters'));
     }
     if (strlen($data['lName']) < 3) {
         $e->add(t('You must enter a Last Name'));
     }
     if (strlen($data['lName']) > 30) {
         $e->add(t('That is a long Last Name. Please keep it under 30 characters'));
     }
     if (strlen($data['addr1']) < 3) {
         $e->add(t('You must enter an address'));
     }
     if (strlen($data['addr1']) > 50) {
         $e->add(t('That is a long street name. Please keep it under 50 characters'));
     }
     if (strlen($data['count']) < 2) {
         $e->add(t('You must enter a Country'));
     }
     if (strlen($data['count']) > 30) {
         $e->add(t('You did not select a Country from the list.'));
     }
     if (strlen($data['city']) < 2) {
         $e->add(t('You must enter a City'));
     }
     if (strlen($data['city']) > 30) {
         $e->add(t('You must enter a valid City'));
     }
     if (strlen($data['postal']) > 10) {
         $e->add(t('You must enter a valid Postal Code'));
     }
     if (strlen($data['postal']) < 2) {
         $e->add(t('You must enter a valid Postal Code'));
     }
     return $e;
 }
Exemplo n.º 4
0
 public function submitPayment()
 {
     $gateway = Omnipay::create('AuthorizeNet_AIM');
     $gateway->setApiLoginId(Config::get('vividstore.authnetLoginID'));
     $gateway->setTransactionKey(Config::get('vividstore.authnetTransactionKey'));
     $gateway->setDeveloperMode(Config::get('vividstore.authnetTestmode'));
     $customer = new StoreCustomer();
     $formData = array('firstName' => $customer->getValue("billing_first_name"), 'lastName' => $customer->getValue("billing_last_name"), 'billingPhone' => $customer->getValue("billing_phone"), 'email' => $customer->getEmail(), 'number' => $_POST['authnet-checkout-credit-card'], 'expiryMonth' => $_POST['authnet-checkout-exp-month'], 'expiryYear' => $_POST['authnet-checkout-exp-year'], 'cvv' => $_POST['authnet-checkout-ccv']);
     $response = $gateway->purchase(array('amount' => StoreCalculator::getGrandTotal(), 'currency' => 'USD', 'card' => $formData))->send();
     if ($response->isSuccessful()) {
         return array('error' => 0, 'transactionReference' => $response->getTransactionReference());
     } else {
         // payment failed: display message to customer
         return array('error' => 1, 'errorMessage' => $response->getMessage());
     }
 }
Exemplo n.º 5
0
 public function view()
 {
     $customer = new StoreCustomer();
     if ($customer->getLastOrderID()) {
         $order = StoreOrder::getByID($customer->getLastOrderID());
     }
     if (is_object($order)) {
         $this->set("order", $order);
     } else {
         $this->redirect("/cart");
     }
     $this->requireAsset('javascript', 'jquery');
     $js = \Concrete\Package\VividStore\Controller::returnHeaderJS();
     $this->addFooterItem($js);
     $this->requireAsset('javascript', 'vivid-store');
     $this->requireAsset('css', 'vivid-store');
 }
 public function isWithinSelectedCountries()
 {
     $customer = new StoreCustomer();
     $custCountry = $customer->getValue('shipping_address')->country;
     if ($this->getCountries() != 'all') {
         $selectedCountries = explode(',', $this->getCountriesSelected());
         if (in_array($custCountry, $selectedCountries)) {
             return true;
         } else {
             return false;
         }
     } else {
         return true;
     }
 }
Exemplo n.º 7
0
 public function isTaxable()
 {
     $taxAddress = $this->getTaxAddress();
     $taxCountry = strtolower($this->getTaxCountry());
     $taxState = strtolower(trim($this->getTaxState()));
     $taxCity = strtolower(trim($this->getTaxCity()));
     $customer = new StoreCustomer();
     $customerIsTaxable = false;
     switch ($taxAddress) {
         case "billing":
             $userCity = strtolower(trim($customer->getValue("billing_address")->city));
             $userState = strtolower(trim($customer->getValue("billing_address")->state_province));
             $userCountry = strtolower(trim($customer->getValue("billing_address")->country));
             break;
         case "shipping":
             $userCity = strtolower(trim($customer->getValue("shipping_address")->city));
             $userState = strtolower(trim($customer->getValue("shipping_address")->state_province));
             $userCountry = strtolower(trim($customer->getValue("shipping_address")->country));
             break;
     }
     if ($userCountry == $taxCountry) {
         $customerIsTaxable = true;
         if (!empty($taxState)) {
             if ($userState != $taxState) {
                 $customerIsTaxable = false;
             }
         }
         if (!empty($taxCity)) {
             if ($userCity != $taxCity) {
                 $customerIsTaxable = false;
             }
         }
     }
     return $customerIsTaxable;
 }
Exemplo n.º 8
0
 public function add($data, $pm, $status = null)
 {
     $taxBased = Config::get('vividstore.taxBased');
     $taxlabel = Config::get('vividstore.taxName');
     $this->set('taxlabel', $taxlabel);
     $taxCalc = Config::get('vividstore.calculation');
     $db = Database::get();
     //get who ordered it
     $customer = new Customer();
     //what time is it?
     $dt = Core::make('helper/date');
     $now = $dt->getLocalDateTime();
     //get the price details
     $shipping = VividCart::getShippingTotal();
     $shipping = Price::formatFloat($shipping);
     $taxvalue = VividCart::getTaxTotal();
     $taxName = Config::get('vividstore.taxName');
     $total = VividCart::getTotal();
     $total = Price::formatFloat($total);
     $tax = 0;
     $taxIncluded = 0;
     if ($taxCalc == 'extract') {
         $taxIncluded = $taxvalue;
     } else {
         $tax = $taxvalue;
     }
     $tax = Price::formatFloat($tax);
     //get payment method
     $pmID = $pm->getPaymentMethodID();
     //add the order
     $vals = array($customer->getUserID(), $now, $pmID, $shipping, $tax, $taxIncluded, $taxName, $total);
     $db->Execute("INSERT INTO VividStoreOrders(cID,oDate,pmID,oShippingTotal,oTax,oTaxIncluded,oTaxName,oTotal) VALUES (?,?,?,?,?,?,?,?)", $vals);
     $oID = $db->lastInsertId();
     $order = Order::getByID($oID);
     if ($status) {
         $order->updateStatus($status);
     } else {
         $order->updateStatus(OrderStatus::getStartingStatus()->getHandle());
     }
     $order->setAttribute("email", $customer->getEmail());
     $order->setAttribute("billing_first_name", $customer->getValue("billing_first_name"));
     $order->setAttribute("billing_last_name", $customer->getValue("billing_last_name"));
     $order->setAttribute("billing_address", $customer->getValueArray("billing_address"));
     $order->setAttribute("billing_phone", $customer->getValue("billing_phone"));
     $order->setAttribute("shipping_first_name", $customer->getValue("shipping_first_name"));
     $order->setAttribute("shipping_last_name", $customer->getValue("shipping_last_name"));
     $order->setAttribute("shipping_address", $customer->getValueArray("shipping_address"));
     $customer->setLastOrderID($oID);
     //add the order items
     $cart = VividCart::getCart();
     foreach ($cart as $cartItem) {
         $taxvalue = VividCart::getTaxProduct($cartItem['product']['pID']);
         $tax = 0;
         $taxIncluded = 0;
         if ($taxCalc == 'extract') {
             $taxIncluded = $taxvalue;
         } else {
             $tax = $taxvalue;
         }
         $productTaxName = $taxName;
         if ($taxvalue == 0) {
             $productTaxName = '';
         }
         OrderItem::add($cartItem, $oID, $tax, $taxIncluded, $productTaxName);
         $product = VividProduct::getByID($cartItem['product']['pID']);
         if ($product && $product->hasUserGroups()) {
             $usergroupstoadd = $product->getProductUserGroups();
             foreach ($usergroupstoadd as $id) {
                 $g = Group::getByID($id);
                 if ($g) {
                     $customer->getUserInfo()->enterGroup($g);
                 }
             }
         }
     }
     if (!$customer->isGuest()) {
         //add user to Store Customers group
         $group = \Group::getByName('Store Customer');
         if (is_object($group) || $group->getGroupID() < 1) {
             $customer->getUserInfo()->enterGroup($group);
         }
     }
     // create order event and dispatch
     $event = new OrderEvent($order);
     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", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("order_receipt", "vivid_store");
     $mh->sendMail();
     //order notification
     $mh->from($fromEmail);
     foreach ($alertEmails as $alertEmail) {
         $mh->to($alertEmail);
     }
     $mh->addParameter("order", $order);
     $mh->addParameter("taxbased", $taxBased);
     $mh->addParameter("taxlabel", $taxlabel);
     $mh->load("new_order_notification", "vivid_store");
     $mh->sendMail();
     VividCart::clear();
     return $order;
 }
Exemplo n.º 9
0
 public function isCustomerTaxable()
 {
     $taxAddress = Config::get('vividstore.taxAddress');
     $taxCountry = strtolower(Config::get('vividstore.taxcountry'));
     $taxState = strtolower(trim(Config::get('vividstore.taxstate')));
     $taxCity = strtolower(trim(Config::get('vividstore.taxcity')));
     $customer = new Customer();
     $customerIsTaxable = false;
     switch ($taxAddress) {
         case "billing":
             $userCity = strtolower(trim($customer->getValue("billing_address")->city));
             $userState = strtolower(trim($customer->getValue("billing_address")->state_province));
             $userCountry = strtolower(trim($customer->getValue("billing_address")->country));
             break;
         case "shipping":
             $userCity = strtolower(trim($customer->getValue("shipping_address")->city));
             $userState = strtolower(trim($customer->getValue("shipping_address")->state_province));
             $userCountry = strtolower(trim($customer->getValue("shipping_address")->country));
             break;
     }
     if ($userCountry == $taxCountry) {
         $customerIsTaxable = true;
         if ($taxState && $userState != $taxState) {
             $customerIsTaxable = false;
         } elseif ($taxCity && $userCity != $taxCity) {
             $customerIsTaxable = false;
         }
     }
     return $customerIsTaxable;
 }
Exemplo n.º 10
0
 public function dispatchEmailNotifications()
 {
     $fromEmail = Config::get('vividstore.emailalerts');
     if (!$fromEmail) {
         $fromEmail = "store@" . $_SERVER['SERVER_NAME'];
     }
     $fromName = Config::get('vividstore.emailalertsname');
     $mh = new MailService();
     $alertEmails = explode(",", Config::get('vividstore.notificationemails'));
     $alertEmails = array_map('trim', $alertEmails);
     //receipt
     $customer = new StoreCustomer();
     $mh->from($fromEmail, $fromName ? $fromName : null);
     $mh->to($customer->getEmail());
     $mh->addParameter("order", $this);
     $mh->load("order_receipt", "vivid_store");
     $mh->sendMail();
     $validNotification = false;
     //order notification
     $mh->from($fromEmail, $fromName ? $fromName : null);
     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();
     }
 }
Exemplo n.º 11
0
 public function submit()
 {
     $data = $this->post();
     //process payment
     $pmHandle = $data['payment-method'];
     $pm = StorePaymentMethod::getByHandle($pmHandle);
     if ($pm === false) {
         //There was no payment method enabled somehow.
         //so we'll force invoice.
         $pm = StorePaymentMethod::getByHandle('invoice');
     }
     if ($pm->getMethodController()->external == true) {
         $pmsess = Session::get('paymentMethod');
         $pmsess[$pm->getPaymentMethodID()] = $data['payment-method'];
         Session::set('paymentMethod', $pmsess);
         $order = StoreOrder::add($data, $pm, null, 'incomplete');
         Session::set('orderID', $order->getOrderID());
         $this->redirect('/checkout/external');
     } else {
         $payment = $pm->submitPayment();
         if ($payment['error'] == 1) {
             $pmsess = Session::get('paymentMethod');
             $pmsess[$pm->getPaymentMethodID()] = $data['payment-method'];
             Session::set('paymentMethod', $pmsess);
             $errors = $payment['errorMessage'];
             Session::set('paymentErrors', $errors);
             $customer = new StoreCustomer();
             if ($customer->isGuest()) {
                 $this->redirect("/checkout/?guest=1#payment");
             } else {
                 $this->redirect("/checkout/failed#payment");
             }
         } else {
             $transactionReference = $payment['transactionReference'];
             StoreOrder::add($data, $pm, $transactionReference);
             $this->redirect('/checkout/complete');
         }
     }
 }
Exemplo n.º 12
0
 public function validateAddress($data, $billing = null)
 {
     $e = Core::make('helper/validation/error');
     $vals = Core::make('helper/validation/strings');
     $customer = new StoreCustomer();
     if ($billing) {
         if ($customer->isGuest()) {
             if (!$vals->email($data['email'])) {
                 $e->add(t('You must enter a valid email address'));
             }
         }
     }
     if (strlen($data['fName']) < 1) {
         $e->add(t('You must enter a first name'));
     }
     if (strlen($data['fName']) > 255) {
         $e->add(t('Please enter a first name under 255 characters'));
     }
     if (strlen($data['lName']) < 1) {
         $e->add(t('You must enter a Last Name'));
     }
     if (strlen($data['lName']) > 255) {
         $e->add(t('Please enter a last name under 255 characters'));
     }
     if (strlen($data['lName']) > 255) {
         $e->add(t('Please enter a company name under 255 characters'));
     }
     if (strlen($data['addr1']) < 3) {
         $e->add(t('You must enter an address'));
     }
     if (strlen($data['addr1']) > 255) {
         $e->add(t('Please enter a street name under 255 characters'));
     }
     if (strlen($data['count']) < 2) {
         $e->add(t('You must enter a Country'));
     }
     if (strlen($data['count']) > 30) {
         $e->add(t('You did not select a Country from the list'));
     }
     if (strlen($data['city']) < 2) {
         $e->add(t('You must enter a City'));
     }
     if (strlen($data['city']) > 30) {
         $e->add(t('You must enter a valid City'));
     }
     if (strlen($data['postal']) > 10) {
         $e->add(t('You must enter a valid Postal Code'));
     }
     if (strlen($data['postal']) < 2) {
         $e->add(t('You must enter a valid Postal Code'));
     }
     return $e;
 }
Exemplo n.º 13
0
 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;
 }
Exemplo n.º 14
0
 public static function addCustomerToUserGroupsByOrder($order)
 {
     $groups = array();
     $customer = new Customer();
     $orderItems = $order->getOrderItems();
     foreach ($orderItems as $orderItem) {
         $product = $orderItem->getProductObject();
         if ($product && $product->hasUserGroups()) {
             $productUserGroups = $product->getProductUserGroups();
             foreach ($productUserGroups as $pug) {
                 $groups[] = \Group::getByID($pug->getUserGroupID());
             }
         }
     }
     //and of course, add the user to the generic group.
     $groups[] = \Group::getByName('Store Customer');
     foreach ($groups as $groupObject) {
         if (is_object($groupObject)) {
             $ui = $customer->getUserInfo();
             if (is_object($ui)) {
                 $ui->getUserObject()->enterGroup($groupObject);
             }
         }
     }
 }