/** * 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); }
function testAddtoCart() { $this->shopping_cart->empty_cart(); $_POST['product_id'] = $this->product_id; $_GET['hook'] = 'catalogue_items'; $this->shopping_cart->add_item_to_cart(); $_GET['page'] = 'shopping'; // Static setting to indentify the module in payment form payment_form(); }