예제 #1
0
 public function index()
 {
     //check to see if shipping and payment modules are installed
     $data['payment_module_installed'] = (bool) count(\CI::Settings()->get_settings('payment_modules'));
     $data['shipping_module_installed'] = (bool) count(\CI::Settings()->get_settings('shipping_modules'));
     $data['page_title'] = lang('dashboard');
     // get 5 latest orders
     $data['orders'] = \CI::Orders()->getOrders(false, 'ordered_on', 'DESC', 5);
     // get 5 latest customers
     $data['customers'] = \CI::Customers()->get_customers(5);
     $this->view('dashboard', $data);
 }
예제 #2
0
 public function address()
 {
     $type = \CI::input()->post('type');
     $id = \CI::input()->post('id');
     $address = \CI::Customers()->get_address($id);
     if ($address['customer_id'] != $this->customer->id) {
         echo json_encode(['error' => lang('error_address_not_found')]);
     } else {
         if ($type == 'shipping') {
             \GC::setAttribute('shipping_address_id', $id);
         } elseif ($type == 'billing') {
             \GC::setAttribute('billing_address_id', $id);
         }
         \GC::saveCart();
         echo json_encode(['success' => true]);
     }
 }
예제 #3
0
파일: Login.php 프로젝트: haouach/GoCart3
 public function forgotPassword()
 {
     $data['page_title'] = lang('forgot_password');
     $submitted = \CI::input()->post('submitted');
     \CI::form_validation()->set_rules('email', 'lang:address_email', ['trim', 'required', 'valid_email', ['email_callable', function ($str) {
         $reset = \CI::Customers()->reset_password($str);
         if (!$reset) {
             \CI::form_validation()->set_message('email_callable', lang('error_no_account_record'));
             return FALSE;
         } else {
             //user does exist. and the password is reset.
             return TRUE;
         }
     }]]);
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('forgot_password', $data);
     } else {
         \CI::session()->set_flashdata('message', lang('message_new_password'));
         redirect('login');
     }
 }
예제 #4
0
 public function __construct()
 {
     parent::__construct();
     $this->state_taxes = config_item('state_taxes');
     $order = GC::getCart();
     $taxType = config_item('tax_address');
     if ($taxType == 'ship') {
         if ((bool) $order->shipping_address_id) {
             $this->address = CI::Customers()->get_address($order->shipping_address_id);
         } else {
             return 0;
         }
     } else {
         if ((bool) $order->billing_address_id) {
             $this->address = CI::Customers()->get_address($order->billing_address_id);
         } else {
             return 0;
         }
     }
     if (!$this->address) {
         return 0;
     }
 }
예제 #5
0
 public function check_email($str)
 {
     $email = \CI::Customers()->check_email($str);
     if ($email) {
         \CI::form_validation()->set_message('check_email_callable', lang('error_email'));
         return FALSE;
     } else {
         return TRUE;
     }
 }
예제 #6
0
 public function checkOrder()
 {
     //start tracking errors
     $errors = [];
     $cart = new stdClass();
     $addresses = \CI::Customers()->get_address_list($this->customer->id);
     foreach ($addresses as $address) {
         if ($address['id'] == $this->cart->shipping_address_id) {
             $cart->shippingAddress = (object) $address;
         }
         if ($address['id'] == $this->cart->billing_address_id) {
             $cart->billingAddress = (object) $address;
         }
     }
     //check shipping
     if ($this->orderRequiresShipping()) {
         if (!$this->getShippingMethod()) {
             $errors['shipping'] = lang('error_choose_shipping');
         }
         if (empty($cart->shippingAddress)) {
             $errors['shippingAddress'] = lang('error_shipping_address');
         }
     }
     if (empty($cart->billingAddress)) {
         $errors['billingAddress'] = lang('error_billing_address');
     }
     //check coupons
     $checkCoupons = $this->checkCoupons();
     if (!empty($checkCoupons)) {
         $errors['coupons'] = $checkCoupons;
     }
     //check the inventory of our products
     $inventory = $this->checkInventory();
     if (!empty($inventory)) {
         $errors['inventory'] = $inventory;
     }
     //if we have errors, return them
     if (!empty($errors)) {
         return $errors;
     }
 }
예제 #7
0
 public function giftCardForm($id = false, $duplicate = false)
 {
     $this->product_id = $id;
     \CI::load()->library('form_validation');
     \CI::load()->model(array('ProductOptions', 'Categories'));
     \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
     $data['categories'] = \CI::Categories()->get_categories_tiered();
     $data['page_title'] = lang('giftcard_product_form');
     $data['groups'] = \CI::Customers()->get_groups();
     //default values are empty if the product is new
     $data['id'] = '';
     $data['sku'] = '';
     $data['primary_category'] = '';
     $data['name'] = '';
     $data['slug'] = '';
     $data['description'] = '';
     $data['excerpt'] = '';
     $data['track_stock'] = '';
     $data['seo_title'] = '';
     $data['meta'] = '';
     $data['is_giftcard'] = 1;
     $data['taxable'] = '';
     $data['images'] = [];
     $data['product_categories'] = [];
     $data['product_files'] = [];
     foreach ($data['groups'] as $group) {
         $data['enabled_' . $group->id] = '';
     }
     //create the photos array for later use
     $data['photos'] = [];
     if ($id) {
         // get product & options data
         $data['ProductOptions'] = \CI::ProductOptions()->getProductOptions($id);
         $product = \CI::Products()->find($id, true);
         //if the product does not exist, redirect them to the product list with an error
         if (!$product) {
             \CI::session()->set_flashdata('error', lang('error_not_found'));
             redirect('admin/products');
         }
         //helps us with the slug generation
         $this->product_name = \CI::input()->post('slug', $product->slug);
         //set values to db values
         $data['id'] = $id;
         $data['sku'] = $product->sku;
         $data['primary_category'] = $product->primary_category;
         $data['name'] = $product->name;
         $data['seo_title'] = $product->seo_title;
         $data['meta'] = $product->meta;
         $data['slug'] = $product->slug;
         $data['description'] = $product->description;
         $data['excerpt'] = $product->excerpt;
         $data['quantity'] = $product->quantity;
         $data['taxable'] = $product->taxable;
         $data['fixed_quantity'] = $product->fixed_quantity;
         $data['is_giftcard'] = $product->is_giftcard;
         foreach ($data['groups'] as $group) {
             $data['enabled_' . $group->id] = $product->{'enabled_' . $group->id};
         }
         //make sure we haven't submitted the form yet before we pull in the images/related products from the database
         if (!\CI::input()->post('submit')) {
             $data['product_categories'] = [];
             foreach ($product->categories as $product_category) {
                 $data['product_categories'][] = $product_category->id;
             }
             $data['related_products'] = $product->related_products;
             $data['images'] = (array) json_decode($product->images);
         }
     }
     if (!is_array($data['product_categories'])) {
         $data['product_categories'] = [];
     }
     //no error checking on these
     \CI::form_validation()->set_rules('caption', 'Caption');
     \CI::form_validation()->set_rules('primary_photo', 'Primary');
     \CI::form_validation()->set_rules('sku', 'lang:sku', 'trim');
     \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim');
     \CI::form_validation()->set_rules('meta', 'lang:meta_data', 'trim');
     \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]');
     \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim');
     \CI::form_validation()->set_rules('description', 'lang:description', 'trim');
     \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim');
     \CI::form_validation()->set_rules('taxable', 'lang:taxable', 'trim|numeric');
     \CI::form_validation()->set_rules('fixed_quantity', 'lang:fixed_quantity', 'trim|numeric');
     \CI::form_validation()->set_rules('option[giftcard_values]', 'lang:giftcard_values', 'required');
     foreach ($data['groups'] as $group) {
         \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric');
     }
     /*
     if we've posted already, get the photo stuff and organize it
     if validation comes back negative, we feed this info back into the system
     if it comes back good, then we send it with the save item
     
     submit button has a value, so we can see when it's posted
     */
     if ($duplicate) {
         $data['id'] = false;
     }
     if (\CI::input()->post('submit')) {
         //reset the product options that were submitted in the post
         $data['ProductOptions'] = \CI::input()->post('option');
         $data['product_categories'] = \CI::input()->post('categories');
         $data['images'] = \CI::input()->post('images');
     }
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('giftcard_product_form', $data);
     } else {
         \CI::load()->helper('text');
         //first check the slug field
         $slug = \CI::input()->post('slug');
         //if it's empty assign the name field
         if (empty($slug) || $slug == '') {
             $slug = \CI::input()->post('name');
         }
         $slug = url_title(convert_accented_characters($slug), '-', TRUE);
         //validate the slug
         $slug = $id ? \CI::Products()->validate_slug($slug, $product->id) : \CI::Products()->validate_slug($slug);
         $save['id'] = $id;
         $save['sku'] = \CI::input()->post('sku');
         $save['name'] = \CI::input()->post('name');
         $save['seo_title'] = \CI::input()->post('seo_title');
         $save['meta'] = \CI::input()->post('meta');
         $save['description'] = \CI::input()->post('description');
         $save['excerpt'] = \CI::input()->post('excerpt');
         foreach ($data['groups'] as $group) {
             $save['enabled_' . $group->id] = \CI::input()->post('enabled_' . $group->id);
             $save['price_' . $group->id] = '0.00';
             $save['saleprice_' . $group->id] = '0.00';
         }
         $save['is_giftcard'] = 1;
         $save['taxable'] = \CI::input()->post('taxable');
         $save['taxable'] = \CI::input()->post('taxable');
         $post_images = \CI::input()->post('images');
         $save['slug'] = $slug;
         if ($primary = \CI::input()->post('primary_image')) {
             if ($post_images) {
                 foreach ($post_images as $key => &$pi) {
                     if ($primary == $key) {
                         $pi['primary'] = true;
                         continue;
                     }
                 }
             }
         }
         $save['images'] = json_encode($post_images);
         if (\CI::input()->post('related_products')) {
             $save['related_products'] = json_encode(\CI::input()->post('related_products'));
         } else {
             $save['related_products'] = '';
         }
         //save categories
         $categories = \CI::input()->post('categories');
         if (!$categories) {
             $categories = [];
         }
         //(\CI::input()->post('primary_category')) ? \CI::input()->post('primary_category') : 0;
         if (!\CI::input()->post('primary_category') && $categories) {
             $save['primary_category'] = $categories[0];
         } elseif (!\CI::input()->post('primary_category') && !$categories) {
             $save['primary_category'] = 0;
         } else {
             $save['primary_category'] = \CI::input()->post('primary_category');
         }
         // format options
         $options = [];
         array_push($options, ['type' => 'textfield', 'name' => 'from', 'required' => 1, 'values' => ['0' => ['name' => 'from', 'value' => '', 'price' => 0, 'limit' => 0]]]);
         array_push($options, ['type' => 'textfield', 'name' => 'to_email', 'required' => 1, 'values' => ['0' => ['name' => 'to_email', 'value' => '', 'price' => 0, 'limit' => 0]]]);
         array_push($options, ['type' => 'textarea', 'name' => 'personal_message', 'required' => 1, 'values' => ['0' => ['name' => 'personal_message', 'value' => '', 'price' => 0]]]);
         $giftcard_values = [];
         $postedValues = \CI::input()->post('option[giftcard_values]');
         if ($postedValues) {
             foreach ($postedValues as $giftcard_value) {
                 array_push($giftcard_values, ['name' => 'beginning_amount', 'value' => $giftcard_value, 'weight' => '', 'price' => $giftcard_value]);
             }
         }
         array_push($options, ['type' => 'droplist', 'name' => 'beginning_amount', 'required' => 1, 'values' => $giftcard_values]);
         // save product
         $product_id = \CI::Products()->save($save, $options, $categories);
         \CI::session()->set_flashdata('message', lang('message_saved_giftcard_product'));
         //go back to the product list
         redirect('admin/products');
     }
 }
예제 #8
0
 function form($id = false)
 {
     $data['groups'] = \CI::Customers()->get_groups();
     $config['upload_path'] = 'uploads/images/full';
     $config['allowed_types'] = 'gif|jpg|png';
     $config['max_size'] = config_item('size_limit');
     $config['max_width'] = '1024';
     $config['max_height'] = '768';
     $config['encrypt_name'] = true;
     \CI::load()->library('upload', $config);
     $this->category_id = $id;
     \CI::load()->helper('form');
     \CI::load()->library('form_validation');
     \CI::form_validation()->set_error_delimiters('<div class="error">', '</div>');
     $data['categories'] = \CI::Categories()->getCategoryOptionsMenu($id);
     $data['page_title'] = lang('category_form');
     //default values are empty if the customer is new
     $data['id'] = '';
     $data['name'] = '';
     $data['slug'] = '';
     $data['description'] = '';
     $data['excerpt'] = '';
     $data['sequence'] = '';
     $data['image'] = '';
     $data['seo_title'] = '';
     $data['meta'] = '';
     $data['parent_id'] = 0;
     $data['error'] = '';
     foreach ($data['groups'] as $group) {
         $data['enabled_' . $group->id] = '';
     }
     //create the photos array for later use
     $data['photos'] = [];
     if ($id) {
         $category = \CI::Categories()->find($id);
         //if the category does not exist, redirect them to the category list with an error
         if (!$category) {
             \CI::session()->set_flashdata('error', lang('error_not_found'));
             redirect('admin/categories');
         }
         //helps us with the slug generation
         $this->category_name = \CI::input()->post('slug', $category->slug);
         //set values to db values
         $data['id'] = $category->id;
         $data['name'] = $category->name;
         $data['slug'] = $category->slug;
         $data['description'] = $category->description;
         $data['excerpt'] = $category->excerpt;
         $data['sequence'] = $category->sequence;
         $data['parent_id'] = $category->parent_id;
         $data['image'] = $category->image;
         $data['seo_title'] = $category->seo_title;
         $data['meta'] = $category->meta;
         foreach ($data['groups'] as $group) {
             $data['enabled_' . $group->id] = $category->{'enabled_' . $group->id};
         }
     }
     \CI::form_validation()->set_rules('name', 'lang:name', 'trim|required|max_length[64]');
     \CI::form_validation()->set_rules('slug', 'lang:slug', 'trim');
     \CI::form_validation()->set_rules('description', 'lang:description', 'trim');
     \CI::form_validation()->set_rules('excerpt', 'lang:excerpt', 'trim');
     \CI::form_validation()->set_rules('sequence', 'lang:sequence', 'trim|integer');
     \CI::form_validation()->set_rules('parent_id', 'parent_id', 'trim');
     \CI::form_validation()->set_rules('image', 'lang:image', 'trim');
     \CI::form_validation()->set_rules('seo_title', 'lang:seo_title', 'trim');
     \CI::form_validation()->set_rules('meta', 'lang:meta', 'trim');
     foreach ($data['groups'] as $group) {
         \CI::form_validation()->set_rules('enabled_' . $group->id, lang('enabled') . '(' . $group->name . ')', 'trim|numeric');
     }
     // validate the form
     if (\CI::form_validation()->run() == FALSE) {
         $this->view('category_form', $data);
     } else {
         $uploaded = \CI::upload()->do_upload('image');
         if ($id) {
             //delete the original file if another is uploaded
             if ($uploaded) {
                 if ($data['image'] != '') {
                     $file = [];
                     $file[] = 'uploads/images/full/' . $data['image'];
                     $file[] = 'uploads/images/medium/' . $data['image'];
                     $file[] = 'uploads/images/small/' . $data['image'];
                     $file[] = 'uploads/images/thumbnails/' . $data['image'];
                     foreach ($file as $f) {
                         //delete the existing file if needed
                         if (file_exists($f)) {
                             unlink($f);
                         }
                     }
                 }
             }
         }
         if (!$uploaded) {
             $data['error'] = \CI::upload()->display_errors();
             if ($_FILES['image']['error'] != 4) {
                 $data['error'] .= \CI::upload()->display_errors();
                 $this->view('category_form', $data);
                 return;
                 //end script here if there is an error
             }
         } else {
             $image = \CI::upload()->data();
             $save['image'] = $image['file_name'];
             \CI::load()->library('image_lib');
             //this is the larger image
             $config['image_library'] = 'gd2';
             $config['source_image'] = 'uploads/images/full/' . $save['image'];
             $config['new_image'] = 'uploads/images/medium/' . $save['image'];
             $config['maintain_ratio'] = TRUE;
             $config['width'] = 600;
             $config['height'] = 500;
             \CI::image_lib()->initialize($config);
             \CI::image_lib()->resize();
             \CI::image_lib()->clear();
             //small image
             $config['image_library'] = 'gd2';
             $config['source_image'] = 'uploads/images/medium/' . $save['image'];
             $config['new_image'] = 'uploads/images/small/' . $save['image'];
             $config['maintain_ratio'] = TRUE;
             $config['width'] = 300;
             $config['height'] = 300;
             \CI::image_lib()->initialize($config);
             \CI::image_lib()->resize();
             \CI::image_lib()->clear();
             //cropped thumbnail
             $config['image_library'] = 'gd2';
             $config['source_image'] = 'uploads/images/small/' . $save['image'];
             $config['new_image'] = 'uploads/images/thumbnails/' . $save['image'];
             $config['maintain_ratio'] = TRUE;
             $config['width'] = 150;
             $config['height'] = 150;
             \CI::image_lib()->initialize($config);
             \CI::image_lib()->resize();
             \CI::image_lib()->clear();
         }
         \CI::load()->helper('text');
         //first check the slug field
         $slug = \CI::input()->post('slug');
         //if it's empty assign the name field
         if (empty($slug) || $slug == '') {
             $slug = \CI::input()->post('name');
         }
         $slug = url_title(convert_accented_characters($slug), 'dash', TRUE);
         if ($id) {
             $slug = \CI::Categories()->validate_slug($slug, $category->id);
         } else {
             $slug = \CI::Categories()->validate_slug($slug);
         }
         $save['id'] = $id;
         $save['name'] = \CI::input()->post('name');
         $save['description'] = \CI::input()->post('description');
         $save['excerpt'] = \CI::input()->post('excerpt');
         $save['parent_id'] = intval(\CI::input()->post('parent_id'));
         $save['sequence'] = intval(\CI::input()->post('sequence'));
         $save['seo_title'] = \CI::input()->post('seo_title');
         $save['meta'] = \CI::input()->post('meta');
         $save['slug'] = $slug;
         foreach ($data['groups'] as $group) {
             $save['enabled_' . $group->id] = \CI::input()->post('enabled_' . $group->id);
         }
         \CI::Categories()->save($save);
         \CI::session()->set_flashdata('message', lang('message_category_saved'));
         //go back to the category list
         redirect('admin/categories');
     }
 }
예제 #9
0
 public function deleteAddress($customer_id = false, $id = false)
 {
     if ($id) {
         $address = \CI::Customers()->get_address($id);
         //if the customer does not exist, redirect them to the customer list with an error
         if (!$address) {
             \CI::session()->set_flashdata('error', lang('error_address_not_found'));
             if ($customer_id) {
                 redirect('admin/customers/addresses/' . $customer_id);
             } else {
                 redirect('admin/customers');
             }
         } else {
             //if the customer is legit, delete them
             \CI::Customers()->delete_address($id, $customer_id);
             \CI::session()->set_flashdata('message', lang('message_address_deleted'));
             if ($customer_id) {
                 redirect('admin/customers/addresses/' . $customer_id);
             } else {
                 redirect('admin/customers');
             }
         }
     } else {
         //if they do not provide an id send them to the customer list page with an error
         \CI::session()->set_flashdata('error', lang('error_address_not_found'));
         if ($customer_id) {
             redirect('admin/customers/addresses/' . $customer_id);
         } else {
             redirect('admin/customers');
         }
     }
 }
예제 #10
0
 public function contact()
 {
     if (isset($_POST['status']) && isset($_POST['id'])) {
         \CI::Customers()->update_contact($_POST['status'], $_POST['id']);
         echo true;
         return;
     } else {
         $data['contacts'] = \CI::Customers()->get_contacts();
         $data['page_title'] = 'Contact';
         //echo '<pre>'; print_r($data['contacts']);exit;
         $this->view('contact', $data);
     }
 }
예제 #11
0
파일: Login.php 프로젝트: haouach/GoCart3
 private function createGuest()
 {
     //create a temp customer
     $customerID = CI::Customers()->createGuest();
     $customer = CI::db()->where('id', $customerID)->get('customers')->row();
     CI::session()->set_userdata('customer', $customer);
 }
예제 #12
0
 public function delete($id)
 {
     \CI::Customers()->delete_address($id, $this->customer->id);
     echo 1;
 }