Пример #1
0
 public function form()
 {
     \CI::form_validation()->set_rules('to_email', 'lang:recipient_email', 'trim|required');
     \CI::form_validation()->set_rules('to_name', 'lang:recipient_name', 'trim|required');
     \CI::form_validation()->set_rules('from', 'lang:sender_name', 'trim|required');
     \CI::form_validation()->set_rules('personal_message', 'lang:personal_message', 'trim');
     \CI::form_validation()->set_rules('beginning_amount', 'lang:amount', 'trim|required|numeric');
     $data['page_title'] = lang('add_gift_card');
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('gift_card_form', $data);
     } else {
         $save['code'] = generate_code();
         // from the string helper
         $save['to_email'] = \CI::input()->post('to_email');
         $save['to_name'] = \CI::input()->post('to_name');
         $save['from'] = \CI::input()->post('from');
         $save['personal_message'] = \CI::input()->post('personal_message');
         $save['beginning_amount'] = \CI::input()->post('beginning_amount');
         \CI::GiftCards()->saveCard($save);
         if (\CI::input()->post('sendNotification')) {
             \GoCart\Emails::giftCardNotification($save);
         }
         \CI::session()->set_flashdata('message', lang('message_saved_gift_card'));
         redirect('admin/gift-cards');
     }
 }
Пример #2
0
 public function register()
 {
     $redirect = \CI::Login()->isLoggedIn(false, false);
     //if they are logged in, we send them back to the my_account by default
     if ($redirect) {
         redirect('my-account');
     }
     \CI::load()->library('form_validation');
     //default values are empty if the customer is new
     $data = ['company' => '', 'firstname' => '', 'lastname' => '', 'email' => '', 'phone' => '', 'address1' => '', 'address2' => '', 'city' => '', 'state' => '', 'zip' => '', 'redirect' => \CI::session()->flashdata('redirect')];
     \CI::form_validation()->set_rules('company', 'lang:account_company', 'trim|max_length[128]');
     \CI::form_validation()->set_rules('firstname', 'lang:account_firstname', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('lastname', 'lang:account_lastname', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('email', 'lang:account_email', ['trim', 'required', 'valid_email', 'max_length[128]', ['check_email_callable', function ($str) {
         return $this->check_email($str);
     }]]);
     \CI::form_validation()->set_rules('phone', 'lang:account_phone', 'trim|required|max_length[32]');
     \CI::form_validation()->set_rules('email_subscribe', 'lang:email_subscribe', 'trim|numeric|max_length[1]');
     \CI::form_validation()->set_rules('password', 'lang:account_password', 'required|min_length[6]');
     \CI::form_validation()->set_rules('confirm', 'lang:account_confirm', 'required|matches[password]');
     if (\CI::form_validation()->run() == FALSE) {
         //if they have submitted the form already and it has returned with errors, reset the redirect
         if (\CI::input()->post('submitted')) {
             $data['redirect'] = \CI::input()->post('redirect');
         }
         // load other page content
         //\CI::load()->model('banner_model');
         \CI::load()->helper('directory');
         $data['registrationErrors'] = \CI::form_validation()->get_error_array();
         $this->view('login', $data);
     } else {
         $save['id'] = false;
         $save['firstname'] = \CI::input()->post('firstname');
         $save['lastname'] = \CI::input()->post('lastname');
         $save['email'] = \CI::input()->post('email');
         $save['phone'] = \CI::input()->post('phone');
         $save['company'] = \CI::input()->post('company');
         $save['active'] = (bool) config_item('new_customer_status');
         $save['email_subscribe'] = intval((bool) \CI::input()->post('email_subscribe'));
         $save['password'] = \CI::input()->post('password');
         $redirect = \CI::input()->post('redirect');
         //if we don't have a value for redirect
         if ($redirect == '') {
             $redirect = 'my-account';
         }
         // save the customer info and get their new id
         $id = \CI::Customers()->save($save);
         //send the registration email
         \GoCart\Emails::registration($save);
         //load twig for this language string
         $loader = new \Twig_Loader_String();
         $twig = new \Twig_Environment($loader);
         //if they're automatically activated log them in and send them where they need to go
         if ($save['active']) {
             \CI::session()->set_flashdata('message', $twig->render(lang('registration_thanks'), $save));
             //lets automatically log them in
             \CI::Login()->loginCustomer($save['email'], \CI::input()->post('confirm'));
             //to redirect them, if there is no redirect, the it should redirect to the homepage.
             redirect($redirect);
         } else {
             //redirect to the login page if they need to wait for activation
             \CI::session()->set_flashdata('message', $twig->render(lang('registration_awaiting_activation'), $save));
             redirect('login');
         }
     }
 }
Пример #3
0
 function submitOrder($transaction = false)
 {
     foreach ($this->items as $item) {
         if ($item->type == 'gift card') {
             //touch giftcard
             \CI::GiftCards()->updateAmountUsed($item->description, $item->total_price);
             continue;
         } elseif ($item->type == 'coupon') {
             //touch coupon
             \CI::Coupons()->touchCoupon($item->description);
             continue;
         } elseif ($item->type == 'product') {
             //update inventory
             if ($item->track_stock) {
                 \CI::Products()->touchInventory($item->product_id, $item->quantity);
             }
             //if this is a giftcard purchase, generate it and send it where it needs to go.
             if ($item->is_giftcard) {
                 //process giftcard
                 $options = CI::Orders()->getItemOptions(GC::getCart()->id);
                 $giftCard = [];
                 foreach ($options[$item->id] as $option) {
                     if ($option->option_name == 'gift_card_amount') {
                         $giftCard[$option->option_name] = $option->price;
                     } else {
                         $giftCard[$option->option_name] = $option->value;
                     }
                 }
                 $giftCard['code'] = generate_code();
                 $giftCard['activated'] = 1;
                 //save the card
                 \CI::GiftCards()->saveCard($giftCard);
                 //send the gift card notification
                 \GoCart\Emails::giftCardNotification($giftCard);
             }
         }
     }
     if (!$transaction) {
         $transaction = $this->transaction();
     }
     //add transaction info to the order
     $this->cart->order_number = $transaction->order_number;
     $this->cart->transaction_id = $transaction->id;
     $this->cart->status = config_item('order_status');
     $this->cart->ordered_on = date('Y-m-d H:i:s');
     $orderNumber = $this->cart->order_number;
     $this->saveCart();
     //refresh the cart
     $this->getCart(true);
     //get the order as it would be on the order complete page
     $order = \CI::Orders()->getOrder($orderNumber);
     //send the cart email
     \GoCart\Emails::Order($order);
     //return the order number
     return $orderNumber;
 }
Пример #4
0
 public function resetPassword($username)
 {
     $admin = $this->getAdminByUsername($username);
     if ($admin) {
         CI::load()->helper('string');
         CI::load()->library('email');
         $newPassword = random_string('alnum', 8);
         $admin['password'] = sha1($newPassword);
         $this->save($admin);
         \GoCart\Emails::resetPassword($newPassword, $admin['email']);
         return true;
     } else {
         return false;
     }
 }