0byt3m1n1
Path:
/
data
/
17
/
1
/
18
/
11
/
1670011
/
user
/
1801231
/
htdocs
/
marketting
/
system
/
application
/
controllers
/
[
Home
]
File: cart.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* | ------------------------------------------------------------------------- | COPYRIGHT NOTICE | Copyright 2008 JROX Technologies, Inc. All Rights Reserved. | ------------------------------------------------------------------------- | This script may be only used and modified in accordance to the license | agreement attached (license.txt) except where expressly noted within | commented areas of the code body. This copyright notice and the | comments above and below must remain intact at all times. By using this | code you agree to indemnify JROX Technologies, Inc, its corporate agents | and affiliates from any liability that might arise from its use. | | Selling the code for this program without prior written consent is | expressly forbidden and in violation of Domestic and International | copyright laws. | | ------------------------------------------------------------------------- | FILENAME - cart.php | ------------------------------------------------------------------------- | | This controller file manages the shopping cart for the user | */ class Cart extends Public_Controller { function __construct() { parent::Public_Controller(); //load css body style $this->config->set_item('css_body', 'jroxCart'); //load required models $this->load->model('init_model', 'init'); $this->load->model('products_model', 'prod'); $this->load->model('shipping_model', 'ship'); $this->load->model('zones_model', 'zones'); $this->load->model('coupons_model', 'coupons'); $this->load->model('checkout_model', 'checkout'); $this->load->model('credits_model', 'credits'); //load country helper $this->load->helper('country'); $this->load->helper('xml'); //create pagination links $this->config->set_item('uri', $this->config->item('base_folder_path') . '/' . $this->uri->segment(1)); $this->config->set_item('uri_string', str_replace('/', ':', trim_slashes($this->uri->uri_string()))); //set the encrypted session //$enc_session = $this->encrypt->encode($this->session->userdata('session_id')); } // ------------------------------------------------------------------------ function load_regions() { //set data array $data = $this->security_model->_load_config('public'); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); echo '[ {optionValue:0, optionDisplay: \'' . $this->lang->line('all_regions') . '\'}'; $cid = $this->input->post('id') == false ? $this->config->item('sts_store_default_country') : (int)$this->input->post('id'); $regions = _load_regions_array($cid); if (!empty($regions)) { foreach ($regions as $v) { echo ',{optionValue:' . $v['region_id'] . ', optionDisplay: \'' . $v['region_name'] . '\'}'; } } echo ']'; } // ------------------------------------------------------------------------ function estimate_shipping() { //set data array $data = $this->security_model->_load_config('public'); //customers_region jroxPostalCode //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); //check if we ship to this country first $country_data = _get_country_name((int)$this->input->post('customers_country')); $data['lang_shipping_estimate'] = $this->lang->line('shipping_estimate'); if (_check_ship_to($country_data['country_id']) == true) { $data['show_error'] = 0; //first get the shipping amounts $types = $this->ship->_get_all_shipping(); if (!empty($types)) { //set the currency $num_options = get_default_currency($this->config->item('sts_store_default_currency')); //get all cart items $this->cart_items = $this->cart->_get_vendor_items(); //format shipping data array $ship_data = array('weight' => $this->input->post('jroxTotalWeight'), 'amount' => $this->input->post('jroxTotalPrice'), 'quantity' => $this->input->post('jroxTotalQuantity'), 'country' => $this->input->post('customers_country'), 'region' => $this->input->post('customers_region'), 'postal_code' => $this->input->post('jroxPostalCode'), 'country_data' => $country_data ); //first calculate the tax $taxes = '0'; $get_taxes = $this->zones->_calculate_tax($ship_data); if (!empty($get_taxes)) { $taxes = $this->input->post('jroxTotalPrice') * $get_taxes['tax_amount']; } $shipping_options = array(); foreach ($types as $v) { //load the model $model = 'modules/module_shipping_' . $v['module_file_name'] . '_model'; $this->load->model($model, $v['module_file_name']); //run the function $function = '_generate_shipping_amount_' . $v['module_file_name']; $ship_amount = $this->$v['module_file_name']->$function($ship_data, $v, $num_options); //shipping data array if (!empty($ship_amount)) { foreach ($ship_amount as $v) { $calc_tax = $v['taxes'] + $taxes; $v['est_amount'] = $v['amount'] . '_' . $calc_tax; array_push($shipping_options, $v); } } } $a = array(); $b = array(); foreach ($shipping_options as $v) { if (!empty($v)) { array_push($a, $v['est_amount']); array_push($b, $v['name']); } } $shipping_types = combine_array($a, $b); asort($shipping_types); $this->session->set_userdata('user_estimate_shipping_set', serialize($shipping_types)); $data['shipping_dropdown'] = form_dropdown('shipping_option', $shipping_types, '', 'class="jroxDropDown" id="jroxEstimateShipping"'); $data['lang_update_totals'] = $this->lang->line('update_totals'); $data['ship_country'] = $ship_data['country']; $data['ship_region'] = $ship_data['region']; $data['ship_postal_code'] = $ship_data['postal_code']; $data['lang_shipping_options_text'] = $this->lang->line('shipping_options_text'); } else { $data['show_error'] = 1; $data['lang_no_shipping_country'] = $this->lang->line('no_shipping_available'); $data['lang_shipping_options_text'] = ''; } } else { $data['show_error'] = 1; $data['lang_no_shipping_country'] = $this->lang->line('we_dont_ship_to_country'); $data['lang_shipping_options_text'] = ''; } echo $this->parser->_JROX_parse('tpl_estimate_shipping', APPPATH . 'views/main', $data, true); } // ------------------------------------------------------------------------ function remove_coupon() { //set data array $data = $this->security_model->_load_config('public'); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); $this->session->unset_userdata('user_coupon_code_set'); redirect('cart'); } // ------------------------------------------------------------------------ function index() { //view item(s) in the cart //set data array $data = $this->security_model->_load_config('public'); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); //set up the languages array $data['languages'] = $sdata['languages']; //set all text foreach ($sdata['text'] as $key => $val) { $data[$key] = $val; } $data['lang_no_items_in_cart'] = $this->lang->line('no_items_in_cart'); $data['lang_your_shopping_cart'] = $this->lang->line('your_shopping_cart'); $data['lang_calculate_shipping_costs'] = $this->lang->line('calculating_shipping_costs'); $data['lang_cart'] = $this->lang->line('cart'); $data['lang_remove'] = $this->lang->line('remove'); $data['lang_qty'] = $this->lang->line('qty'); $data['lang_unit_price'] = $this->lang->line('unit_price'); $data['lang_product_name'] = $this->lang->line('product_name'); $data['lang_subtotal'] = $this->lang->line('subtotal'); $data['lang_continue_shopping'] = $this->lang->line('continue_shopping'); $data['lang_update_shopping_cart'] = $this->lang->line('update_shopping_cart'); $data['lang_recommended_products'] = $this->lang->line('recommended_products'); $data['lang_enter_coupon_code'] = $this->lang->line('enter_coupon_code'); $data['lang_apply_coupon'] = $this->lang->line('apply_coupon'); $data['lang_coupon_code_text'] = $this->lang->line('coupon_code_text'); $data['lang_cart_totals'] = $this->lang->line('cart_totals'); $data['lang_subtotal_cart_price'] = $this->lang->line('subtotal'); $data['lang_grandtotal_cart_price'] = $this->lang->line('grand_total'); $data['lang_discounts'] = $this->lang->line('discounts'); $data['lang_estimate_shipping'] = $this->lang->line('estimate_shipping'); $data['lang_estimate_shipping_text'] = $this->lang->line('estimate_shipping_text'); $data['lang_country'] = $this->lang->line('country'); $data['lang_remove_coupon_text'] = $this->lang->line('remove_coupon_text'); $data['lang_get_quote'] = $this->lang->line('get_quote'); $data['lang_region'] = $this->lang->line('region'); $data['lang_postal_zip_code'] = $this->lang->line('postal_code'); $data['lang_shipping_options'] = $this->lang->line('shipping_options'); $data['lang_update_totals'] = $this->lang->line('update_totals'); $data['lang_shipping_options_text'] = $this->lang->line('shipping_options_text'); //set referral info foreach ($sdata['aff_cfg'] as $key => $val) { $data[$key] = $val; } //set the message text $data['show_message'] = ''; if ($this->session->flashdata('user_message')) { $data['show_message'] = $this->session->flashdata('user_message'); } //set the currency $num_options = get_default_currency($this->config->item('sts_store_default_currency')); //set the meta tags $data['page_title'] = $data['layout_design_header_tag_line'] . ' - ' . $this->lang->line('your_shopping_cart'); $data['meta_keywords'] = $data['sts_store_default_keywords']; $data['meta_description'] = $data['sts_store_description']; //set template ifs $data['no_items'] = 1; $data['show_recommended'] = 0; $data['show_shipping_options'] = 0; $data['show_ship_estimator'] = 0; //set public URL $data['jrox_public_url'] = _jrox_public_url(); //get products from cart $cart_items = $this->cart->_get_cart_items($num_options); if (!empty($cart_items)) { $data['no_items'] = 0; //calculate the total amounts $data['shopping_cart_items'] = $cart_items['items']; $data['total_cart_weight'] = $cart_items['total_cart_weight']; $data['total_cart_quantity'] = $cart_items['total_cart_quantity']; $data['subtotal_cart_price'] = $cart_items['subtotal_cart_price']; //calculate the grand totals $data['grandtotal_cart_price'] = $cart_items['subtotal_cart_price']; //get any product discounts $data['show_discount_amount'] = ''; $data['discount_totals'] = ''; $data['discount_totals_text'] = ''; $data['discounts'] = ''; $data['taxes'] = ''; $data['shipping_handling'] = ''; $data['total_conversion'] = ''; //get discount group discounts $data['show_discount_amount'] = $this->checkout->_calculate_discounts($num_options, $data['grandtotal_cart_price'], $cart_items['items']); if (!empty($data['show_discount_amount'])) { $data['discount_totals'] = $data['show_discount_amount']['discount']; $data['discount_group_totals'] = $data['show_discount_amount']['discount']; $data['grandtotal_cart_price'] = $data['grandtotal_cart_price'] - $data['show_discount_amount']['discount']; } /* |------------------------- | get any coupons |------------------------- */ if (!empty($_POST) && $this->uri->segment(3) == 'update_coupon') { $coupon_data = array('name' => $this->input->post('jroxCouponCode'), 'order_amount' => $data['grandtotal_cart_price'], ); $verify_coupon = $this->coupons->_verify_coupon($coupon_data, $num_options, '1'); //set the session coupon data if the coupon is valid if ($verify_coupon['valid'] == true) { $this->session->set_userdata('user_coupon_code_set', $this->input->post('jroxCouponCode')); //check if the coupon is affiliate referral if (!empty($verify_coupon['member_id'])) { $this->session->set_userdata('user_product_affiliate_coupon_referral_set', $verify_coupon['member_id']); } $data['show_message'] = '<div id="successMessage" class="successMessage jroxCartMsg">' . $verify_coupon['msg'] . '</div>'; } else { $data['show_message'] = '<div class="errorMessage jroxCartMsg">' . $verify_coupon['msg'] . '</div>'; } } if ($this->session->userdata('user_coupon_code_set')) { //get current coupon $coupon_code = $this->session->userdata('user_coupon_code_set'); $coupon_data = array('name' => $coupon_code, 'order_amount' => $data['grandtotal_cart_price'], ); $verify_coupon = $this->coupons->_verify_coupon($coupon_data, $num_options, '1'); } if (!empty($verify_coupon['valid'])) { $data['discount_totals'] = $data['discount_totals'] + $verify_coupon['coupon_amount']; $data['grandtotal_cart_price'] = $data['grandtotal_cart_price'] - $verify_coupon['coupon_amount']; } if (!empty($_POST) && $this->uri->segment(3) == 'update_shipping_totals') { $ship_array = explode('_', $this->input->post('shipping_option')); $data['taxes'] = '<tr id="jroxDiscountText"> <td align="right">' . $this->lang->line('taxes') . ':</td> <td align="right"><span>' . format_amounts($ship_array[1], $num_options) . '</span></td> </tr>'; $data['shipping_handling'] = '<tr id="jroxDiscountText"> <td align="right">' . $this->lang->line('s_and_h') . ':</td> <td align="right"><span>' . format_amounts($ship_array[0], $num_options) . '</span></td> </tr>'; $data['grandtotal_cart_price'] = $data['grandtotal_cart_price'] + $ship_array[0] + $ship_array[1]; } //get final price //check if total amount is less than zero if ($data['grandtotal_cart_price'] < 0) { $data['grandtotal_cart_price'] = '0'; } $data['grandtotal_cart_price_text'] = format_amounts($data['grandtotal_cart_price'], $num_options); $data['discount_totals_text'] = '-' . format_amounts($data['discount_totals'], $num_options); $data['subtotal_cart_price_text'] = format_amounts($cart_items['subtotal_cart_price'], $num_options); if (!empty($data['discount_totals'])) { $data['discounts'] = '<tr id="jroxDiscountText"> <td align="right">' . $data['lang_discounts'] . ':</td> <td align="right"><span>' . $data['discount_totals_text'] . '</span></td> </tr>'; if (!empty($data['discount_group_totals'])) { $data['discounts'] .= '<tr id="jroxGroupDiscountText"> <td align="right" colspan="2"><span>' . $this->lang->line('group_discount') . ': -' . format_amounts($data['discount_group_totals'], $num_options) . '</span></td> </tr>'; } if (!empty($verify_coupon['valid'])) { $data['discounts'] .= '<tr id="jroxCouponDiscountText"> <td align="right" colspan="2"><span>' . $this->lang->line('coupon') . ': (<a href="javascript:RemoveCoupon()" alt="' . $this->lang->line('remove_coupon') . ' ">' . $verify_coupon['coupon_code'] . '</a>) -' . format_amounts($verify_coupon['coupon_amount'], $num_options) . '</span></td> </tr>'; } } //check for currency total conversion $site_currency = get_site_currency(); if ($this->config->item('sts_store_default_currency') != $site_currency['settings_value']) { $default_num = get_default_currency($site_currency['settings_value']); $data['total_conversion'] = '<tr id="jroxCouponDiscountText"> <td align="right" colspan="2"><span>' . $this->lang->line('equivalent_to') . ': ' . format_amounts($data['grandtotal_cart_price'], $default_num) . '</span></td> </tr>'; } /* //calculate shipping if ($this->session->userdata('user_estimate_shipping_set')) { $ship_array = unserialize($this->session->userdata('user_estimate_shipping_set')); $data['show_shipping_options'] = 1; $data['shipping_options'] = form_dropdown('shipping_option', $ship_array, '', 'class="jroxDropDown"'); } */ //get recommended products if ($data['sts_cart_recommend_products'] == 1) { $data['show_recommended'] = 1; if ($data['sts_cart_recommended_products_keywords'] == 1) { $data['recommended_products'] = $this->prod->_get_similar_products($cart_items['items'][0]['product_keywords'], $cart_items['items'][0]['pid'], $num_options, $data['sts_cart_number_recommended_products']); } else { $data['recommended_products'] = $this->prod->_get_similar_products($cart_items['items'][0]['product_keywords'], $cart_items['items'][0]['pid'], $num_options, $data['sts_cart_number_recommended_products'], 'recommended'); } if (empty($data['recommended_products'])) { $data['show_recommended'] = 0; } } //check if there is a physical product in the cart first foreach ($cart_items['items'] as $item) { if ($item['product_type'] == 'physical') $data['show_ship_estimator'] = 1; } //initialize shipping estimator $country_options = _load_countries_dropdown($countries = _load_countries_array(true)); $select_country = $this->input->post('customers_country') == false ? $this->config->item('sts_store_default_country') : $this->input->post('customers_country'); $data['form_countries'] = form_dropdown('customers_country', $country_options, $select_country, 'id="jroxCartCountryDropdown" class="jroxDropDown"'); $regions = _load_regions_array($select_country); $region_options = format_array($regions, 'region_id', 'region_name', true, 'all_regions'); $select_region = $this->input->post('customers_region') == false ? '' : $this->input->post('customers_region'); $data['form_regions'] = form_dropdown('customers_region', $region_options, $select_region, 'id="jroxCartRegionDropdown" class="jroxDropDown"'); $data['jroxPostalCode'] = $this->input->post('jroxPostalCode') == false ? '' : $this->input->post('jroxPostalCode'); } $this->parser->_JROX_load_view('tpl_cart', 'cart', $data); } // ------------------------------------------------------------------------ function add() { //add item(s) to the cart //set data array $data = $this->security_model->_load_config('public'); //set the product id first if (!$this->uri->segment(3)) redirect(); $s_pid = (int)$this->uri->segment(3); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); //set up the languages array $data['languages'] = $sdata['languages']; //set all text foreach ($sdata['text'] as $key => $val) { $data[$key] = $val; } //set referral info foreach ($sdata['aff_cfg'] as $key => $val) { $data[$key] = $val; } //first get the product details $sdata = $this->prod->_get_product_info($s_pid, true); if ($sdata == false) redirect(); //merge the product data $data = array_merge($data, $sdata['info']); //now check for required attributes $attributes_array = $this->input->post('attributes'); $check_attrib = $this->attrib->_get_product_attributes($s_pid); if (!empty($check_attrib)) { $data['product_attributes'] = array(); $this->load->model('modules_model'); foreach ($check_attrib as $k => $v) { if ($v['attribute_required'] == 1) { $aid = $v['attribute_id']; //first check if the array exists if (empty($attributes_array)) { $this->session->set_flashdata('user_error', $this->lang->line('please_select_required_attributes')); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '/' . $aid . '/#attributes'); exit(); } //now check if the values are empty foreach ($attributes_array as $key => $val) { if (empty($attributes_array[$aid])) { $this->session->set_flashdata('user_error', $this->lang->line('please_select_required_attributes')); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '/' . $aid . '/#attributes'); exit(); } } //now check for any callbacks if ($v['attribute_type'] == 'text') { if (!empty($v['attribute_callback'])) { //run the callback $module_data = $this->_run_callback_module($v['attribute_callback']); if ($module_data['status'] == false) { $this->load->helper('inflector'); $this->session->set_flashdata('user_error', humanize($v['attribute_name']) . ' - ' . $module_data['lang']); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '/' . $aid . '/#attributes'); exit(); } } } } //$new_attrib = $this->attrib->_format_attribute($v); array_push($data['product_attributes'], $v); } } //check physical products if ($data['product_type'] == 'physical') { //check inventory first if ($this->config->item('sts_products_enable_inventory') == 1) { if ($data['product_type'] == 'physical' && $data['enable_product_inventory'] != '0') { if (empty($data['product_inventory'])) { redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name'])); } } } //check for minimum and maximum amount if (!empty($data['min_quantity_ordered'])) { $item = $this->cart->_get_item($s_pid); if (!empty($item)) { $qty = $item->quantity + (int)$this->input->post('quantity'); } else { $qty = (int)$this->input->post('quantity'); } if ($qty < $data['min_quantity_ordered']) { $this->session->set_flashdata('user_error', $this->lang->line('minimum_quantity_required') . ' - ' . $data['min_quantity_ordered']); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '#attributes'); exit(); } } //check max ordered if (!empty($data['max_quantity_ordered'])) { if ($qty > $data['max_quantity_ordered']) { $this->session->set_flashdata('user_error', $this->lang->line('maximum_quantity_allowed') . ' - ' . $data['max_quantity_ordered']); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '#attributes'); exit(); } } //check if login is required first if ($data['login_for_price'] == 1) { if (!$this->session->userdata('userid')) { $this->session->set_flashdata('user_error', $this->lang->line('login_required')); redirect(PRODUCTS_ROUTE . '/details/' . $s_pid . '/' . url_title($data['product_name']) . '#attributes'); exit(); } } } elseif ($data['product_type'] == 'membership') { redirect_301($data['checkout_url'] . $this->config->slash_item('checkout_index_page') . 'membership/registration/' . $s_pid . '/' . $this->config->item('enc_id'), true); exit(); } //now add the product to the cart $this->cart->_add_item($s_pid, $_POST); $msg = $data['product_name'] . ' ' . $this->lang->line('successfully_added_to_cart'); $msg = '<div class="successMessage jroxCartMsg" id="successMessage">' . $msg . '</div>'; $this->session->set_flashdata('user_message', $msg); redirect('cart'); } // ------------------------------------------------------------------------ function update_cart() { //update item(s) in the cart //set data array $data = $this->security_model->_load_config('public'); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); //set up the languages array $data['languages'] = $sdata['languages']; //set all text foreach ($sdata['text'] as $key => $val) { $data[$key] = $val; } //set referral info foreach ($sdata['aff_cfg'] as $key => $val) { $data[$key] = $val; } if (!empty($_POST['jroxItems'])) { $msg = $this->cart->_update_cart($_POST['jroxItems']); if (!empty($msg)) { $msg = '<div class="errorMessage jroxCartMsg">' . $msg . '</div>'; $this->session->set_flashdata('user_message', $msg); } } redirect('cart'); } // ------------------------------------------------------------------------ function delete() { //remove item(s) in the cart //set data array $data = $this->security_model->_load_config('public'); //initialize site with required db config $sdata = $this->init->_initialize(__CLASS__, __FUNCTION__); $this->cart->_delete_item((int)$this->uri->segment(3)); redirect('cart'); } // ------------------------------------------------------------------------ /* | ------------------------------------------------------------------------- | supporting functions - these are used to support the main functions above | ------------------------------------------------------------------------- */ // ------------------------------------------------------------------------ function _run_callback_module($id = '') { //run modules $data = $this->modules_model->_run_module($id); if (!empty($data)) { //module_attribute_callback_domain_whois_model $module_model = 'modules/module_' . $data['module_type'] . '_' . $data['module_file_name'] . '_model'; $this->load->model($module_model, $v['module_file_name']); /* return array $module_data['status'] = false; $module_data['data'] = 'data for module'; $module_data['lang'] = 'enter a valid domain name'; */ return $this->$v['module_file_name']->_run_module('attribute_callback'); } return false; } } ?>