/** * The UI to show shopping cart * * @return tempcode The UI */ function view_shopping_cart() { $pro_ids = array(); $pro_ids_val = NULL; require_code('templates_results_table'); require_code('form_templates'); require_css('shopping'); require_javascript('javascript_shopping'); $title = get_page_title('SHOPPING'); log_cart_actions('View cart'); breadcrumb_set_parents(array(array('_SELF:catalogues:misc:ecommerce=1', do_lang_tempcode('CATALOGUES')))); $where = array('ordered_by' => get_member(), 'is_deleted' => 0); if (is_guest()) { $where['session_id'] = get_session_id(); } else { $where['ordered_by'] = get_member(); } $result = $GLOBALS['SITE_DB']->query_select('shopping_cart', array('*'), $where); $max_rows = count($result); if ($max_rows > 0) { $shopping_cart = new ocp_tempcode(); $checkout_details = new ocp_tempcode(); $fields_title = results_field_title(array('', do_lang_tempcode('PRODUCT_NAME'), do_lang_tempcode('UNIT_PRICE'), do_lang_tempcode('QUANTITY'), do_lang_tempcode('ORDER_PRICE_AMT'), do_lang_tempcode('TAX'), do_lang_tempcode('SHIPPING_PRICE'), do_lang_tempcode('TOTAL_PRICE'), do_lang_tempcode('REMOVE_FROM_CART')), NULL); $i = 1; $sub_tot = 0.0; $shipping_cost = 0.0; foreach ($result as $value) { $pro_ids[] = $value['product_id']; $_hook = $value['product_type']; $value['sl_no'] = $i; require_code('hooks/systems/ecommerce/' . filter_naughty_harsh($_hook)); $object = object_factory('Hook_' . filter_naughty_harsh($_hook)); if (method_exists($object, 'show_cart_entry')) { $object->show_cart_entry($shopping_cart, $value); } if (method_exists($object, 'calculate_tax')) { $tax = $object->calculate_tax($value['price'], $value['price_pre_tax']); } else { $tax = 0; } //Shipping if (method_exists($object, 'calculate_shipping_cost')) { $shipping_cost = $object->calculate_shipping_cost($value['product_weight']); } else { $shipping_cost = 0; } $sub_tot += round($value['price'] + $tax + $shipping_cost, 2) * $value['quantity']; $i++; } $width = NULL; //array('50','100%','85','85','85','85','85','85','85'); $results_table = results_table(do_lang_tempcode('MEMBERS'), 0, 'start', $max_rows, 'max', $max_rows, $fields_title, $shopping_cart, NULL, NULL, NULL, 'sort', NULL, $width, 'cart'); $update_cart = build_url(array('page' => '_SELF', 'type' => 'update_cart'), '_SELF'); $empty_cart = build_url(array('page' => '_SELF', 'type' => 'empty_cart'), '_SELF'); $checkout = build_url(array('page' => '_SELF', 'type' => 'pay'), '_SELF'); $payment_form = payment_form(); $proceed_box = do_template('SHOPPING_CART_PROCEED', array('SUB_TOTAL' => float_format($sub_tot), 'SHIPPING_COST' => float_format($shipping_cost), 'GRAND_TOTAL' => float_format($sub_tot), 'CHECKOUT_URL' => $checkout, 'PROCEED' => do_lang_tempcode('PROCEED'), 'CURRENCY' => ecommerce_get_currency_symbol(), 'PAYMENT_FORM' => $payment_form)); } else { $update_cart = new ocp_tempcode(); $empty_cart = new ocp_tempcode(); $checkout = new ocp_tempcode(); $results_table = do_lang_tempcode('CART_EMPTY'); $proceed_box = new ocp_tempcode(); } $ecom_catalogue = $GLOBALS['SITE_DB']->query_value_null_ok('catalogues', 'c_name', array('c_ecommerce' => 1)); $cont_shopping = is_null($ecom_catalogue) ? new ocp_tempcode() : build_url(array('page' => 'catalogues', 'type' => 'category', 'catalogue_name' => $ecom_catalogue), get_module_zone('catalogues')); //Product id string for hidden field in Shopping cart $pro_ids_val = is_array($pro_ids) ? implode(',', $pro_ids) : ''; $allow_opt_out_tax = get_option('allow_opting_out_of_tax'); $allow_opt_out_tax_value = get_order_tax_opt_out_status(); return do_template('SHOPPING_CART_SCREEN', array('TITLE' => $title, 'RESULT_TABLE' => $results_table, 'CONTENT' => '', 'FORM_URL' => $update_cart, 'CONT_SHOPPING' => $cont_shopping, 'MESSAGE' => '', 'BACK' => $cont_shopping, 'PRO_IDS' => $pro_ids_val, 'EMPTY_CART' => $empty_cart, 'EMPTY' => do_lang_tempcode('EMPTY_CART'), 'UPDATE' => do_lang_tempcode('UPDATE'), 'CONTINUE_SHOPPING' => do_lang_tempcode('CONTINUE_SHOPPING'), 'PROCEED_BOX' => $proceed_box, 'ALLOW_OPTOUT_TAX' => $allow_opt_out_tax, 'ALLOW_OPTOUT_TAX_VALUE' => strval($allow_opt_out_tax_value)), NULL, false); }
/** * Payment step. * * @return tempcode The result of execution. */ function payment_form() { require_code('ecommerce'); $title = get_page_title('PAYMENT_HEADING'); $cart_items = find_products_in_cart(); $purchase_id = NULL; $tax_opt_out = get_order_tax_opt_out_status(); if (count($cart_items) > 0) { $insert = array('c_member' => get_member(), 'session_id' => get_session_id(), 'add_date' => time(), 'tot_price' => 0, 'order_status' => 'ORDER_STATUS_awaiting_payment', 'notes' => '', 'purchase_through' => 'cart', 'transaction_id' => '', 'tax_opted_out' => $tax_opt_out); if (is_null($GLOBALS['SITE_DB']->query_value_null_ok('shopping_order', 'id'))) { $insert['id'] = hexdec('1701D'); // Start offset } $order_id = $GLOBALS['SITE_DB']->query_insert('shopping_order', $insert, true); } else { $order_id = NULL; } $total_price = 0; foreach ($cart_items as $item) { $product = $item['product_id']; $hook = $item['product_type']; require_code('hooks/systems/ecommerce/' . filter_naughty_harsh($hook), true); $object = object_factory('Hook_' . filter_naughty_harsh($hook), true); if (is_null($object)) { continue; } $temp = $object->get_products(false, $product); if ($temp[$product][0] == PRODUCT_SUBSCRIPTION) { continue; } //Subscription type skipped. $price = $temp[$product][1]; $item_name = $temp[$product][4]; if (method_exists($object, 'set_needed_fields')) { $purchase_id = $object->set_needed_fields($product); } else { $purchase_id = strval(get_member()); } $length = NULL; $length_units = ''; if (method_exists($object, 'calculate_product_price')) { $price = $object->calculate_product_price($item['price'], $item['price_pre_tax'], $item['product_weight']); } else { $price = $item['price']; } if (method_exists($object, 'calculate_tax') && $tax_opt_out == 0) { $tax = round($object->calculate_tax($item['price'], $item['price_pre_tax']), 2); } else { $tax = 0.0; } $GLOBALS['SITE_DB']->query_insert('shopping_order_details', array('p_id' => $item['product_id'], 'p_name' => $item['product_name'], 'p_code' => $item['product_code'], 'p_type' => $item['product_type'], 'p_quantity' => $item['quantity'], 'p_price' => $price, 'included_tax' => $tax, 'order_id' => $order_id, 'dispatch_status' => ''), true); $total_price += $price * $item['quantity']; } $GLOBALS['SITE_DB']->query_update('shopping_order', array('tot_price' => $total_price), array('id' => $order_id), '', 1); if (!perform_local_payment()) { $result = make_cart_payment_button($order_id, get_option('currency')); } else { if (!tacit_https() && !ecommerce_test_mode()) { warn_exit(do_lang_tempcode('NO_SSL_SETUP')); } if (is_null($order_id)) { $fields = new ocp_tempcode(); $hidden = new ocp_tempcode(); } else { list($fields, $hidden) = get_transaction_form_fields(NULL, strval($order_id), $item_name, float_to_raw_string($price), NULL, ''); } /*$via =get_option('payment_gateway'); require_code('hooks/systems/ecommerce_via/'.filter_naughty_harsh($via)); $object=object_factory('Hook_'.$via); $ipn_url=$object->get_ipn_url();*/ $finish_url = build_url(array('page' => 'purchase', 'type' => 'finish'), get_module_zone('purchase')); $result = do_template('PURCHASE_WIZARD_STAGE_TRANSACT', array('FIELDS' => $fields, 'HIDDEN' => $hidden)); require_javascript('javascript_validation'); return do_template('PURCHASE_WIZARD_SCREEN', array('TITLE' => $title, 'CONTENT' => $result, 'URL' => $finish_url)); } return $result; }
/** * Calculate tax of catalogue product. * * @param float Gross cost of product. * @param float Tax in percentage * @return float Calculated tax for the product. */ function calculate_tax($gross_cost, $tax_percentage) { if (addon_installed('shopping')) { require_code('shopping'); if (get_order_tax_opt_out_status() == 1) { return 0.0; } } $tax = $gross_cost * $tax_percentage / 100.0; return $tax; }