function checkout() { use_ssl(TRUE); $cart_id = $this->session->userdata('cart_id'); if ($this->Order_model->is_cart_empty($cart_id)) { redirect('/shop/cart'); exit; } elseif (!$this->Order_model->is_delivery_entered($cart_id)) { redirect('/shop/delivery'); exit; } elseif (!$this->Order_model->is_billing_entered($cart_id)) { redirect('/shop/billing'); exit; } else { $this->load->model('Group_model'); $cart = $this->Order_model->get_fullcart($this->session->userdata('cart_id')); $totals = array('itemtotal' => 0, 'shipping' => 0, 'service' => 0, 'surcharge' => 0, 'tax' => 0, 'discount' => 0, 'coupon' => 0, 'coupon_code' => '', 'companyless' => 0, 'grandtotal' => 0); $order_items = ''; $oformat = file_get_contents('assets/email_items.html'); $aoformat = $itemformat = ''; $aitemformat = ''; $icnt = 0; $itemprc = 0; $this->load->model('Company_model'); $this->load->model('Customer_model'); $conversion = ''; $cartitems = array(); foreach ($cart as $item) { $itemprc = 0; $ptotal = $item->product_price; $icnt++; $itemf = $oformat; $itemf = str_replace('{counter}', $icnt, $itemf); $itemf = str_replace('{firstname}', $item->firstname, $itemf); $itemf = str_replace('{lastname}', $item->lastname, $itemf); $itemf = str_replace('{address1}', $item->address1, $itemf); $itemf = str_replace('{address2}', $item->address2, $itemf); $itemf = str_replace('{city}', $item->city, $itemf); $itemf = str_replace('{postalcode}', $item->postalcode, $itemf); $itemf = str_replace('{province}', $item->province, $itemf); $itemf = str_replace('{country}', $item->country_id, $itemf); $itemf = str_replace('{phone}', $item->dayphone . ' ' . $item->evephone, $itemf); $itemf = str_replace('{message}', $item->card_message, $itemf); // $itemf = str_replace('{delivery_date}',date('d M Y',strtotime($item->delivery_date)),$itemf); $itemf = str_replace('{delivery_date}', date('d M Y', strtotime($item->delivery_date)) . ' - ' . $item->delivery_time, $itemf); $itemf = str_replace('{shipping_method}', $item->infotext, $itemf); $itemf = str_replace('{delivery_info}', $item->delivery_description, $itemf); $itemf = str_replace('{product_image}', '<img src="' . $this->config->item('base_url') . img_format('productres/' . $item->product_picture, 'thumb') . '" />', $itemf); $itemf = str_replace('{product_code}', $item->product_code, $itemf); $itemf = str_replace('{product_name}', $item->product_name . '<br/><small>(' . $item->price_name . ')</small>', $itemf); $itemf = str_replace('{price}', '$' . number_format($item->product_price, 2), $itemf); $itemf = str_replace('{quantity}', '1', $itemf); $itemprc += $item->product_price; if ($item->delivery_method_id == 1) { $itemf = str_replace('{delivery_by}', 'Delivery by Local', $itemf); } else { $itemf = str_replace('{delivery_by}', 'This bouquet comes to via UPS.', $itemf); } $itemf = str_replace('{total}', '$' . number_format($item->product_price, 2), $itemf); $totals['itemtotal'] += $item->product_price; if (array_key_exists($item->product_id, $cartitems)) { $cartitems[$item->product_id]['sku'] = $item->product_code; $cartitems[$item->product_id]['qty'] = $cartitems[$item->product_id]['qty'] + 1; $cartitems[$item->product_id]['amt'] = $cartitems[$item->product_id]['amt'] + $item->product_price * 100; $cartitems[$item->product_id]['name'] = urlencode($item->product_name); $cartitems[$item->product_id]['category'] = urlencode($item->category); } else { $cartitems[$item->product_id]['sku'] = $item->product_code; $cartitems[$item->product_id]['qty'] = 1; $cartitems[$item->product_id]['amt'] = $item->product_price * 100; $cartitems[$item->product_id]['name'] = urlencode($item->product_name); $cartitems[$item->product_id]['category'] = urlencode($item->category); } $addontot = 0; if (count($item->addons)) { $order_items = ''; foreach ($item->addons as $addon) { $order_items .= '+(' . $addon->addon_name . " " . $addon->addon_quantity . 'x$' . number_format($addon->addon_price, 2) . ") \$" . number_format($addon->addon_price * $addon->addon_quantity, 2) . "<br/>\n"; $totals['itemtotal'] += $addon->addon_price * $addon->addon_quantity; $itemprc += $addon->addon_price * $addon->addon_quantity; $addontot += $addon->addon_price * $addon->addon_quantity; $ptotal += $addon->addon_price * $addon->addon_quantity; if (array_key_exists($addon->addon_id, $cartitems)) { $cartitems[$addon->addon_id]['sku'] = $addon->addon_id; $cartitems[$addon->addon_id]['qty'] = $cartitems[$addon->addon_id]['qty'] + $addon->addon_quantity; $cartitems[$addon->addon_id]['amt'] = $cartitems[$addon->addon_id]['amt'] + $addon->addon_price * 100; $cartitems[$addon->addon_id]['name'] = urlencode($addon->addon_name); $cartitems[$item->product_id]['category'] = urlencode($item->category); } else { $cartitems[$addon->addon_id]['sku'] = $addon->addon_id; $cartitems[$addon->addon_id]['qty'] = $addon->addon_quantity; $cartitems[$addon->addon_id]['amt'] = $addon->addon_price * 100; $cartitems[$addon->addon_id]['name'] = urlencode($addon->addon_name); $cartitems[$item->product_id]['category'] = urlencode($item->category); } //echo $order_items; } //echo $order_items; } else { $order_items .= 'None'; } $conversion .= 'bta.addConversionLegacy("$", "' . $item->product_name . '", "' . number_format($itemprc, 2) . '");' . "\n"; $itemf = str_replace('{addons}', $order_items, $itemf); $itemf = str_replace('{addon_price}', '$' . number_format($addontot, 2), $itemf); $addition = $this->Order_model->get_add_charges($item->orderitem_id); if (!($waiver = $this->Company_model->checkWaiver($this->session->userdata('customer_id')))) { $totals['shipping'] += $addition['shipping']; $totals['service'] += $addition['service']; $totals['surcharge'] += $addition['surcharge']; } $totals['tax'] += $addition['tax'] * $ptotal / 100; $aitemformat .= str_replace('{product_description}', '', $itemf); $itemf = str_replace('{product_description}', substr($item->product_description, 0, 50), $itemf); $itemformat .= $itemf; } $ggitems = ''; foreach ($cartitems as $citem) { $productids[] = $citem['sku'] . ':' . str_replace('+', '', $citem['name']); $itemvalues[] = $citem['amt']; $units[] = $citem['qty']; $skulist[] = $citem['sku']; $qlist[] = $citem['qty']; $amtlist[] = $citem['amt']; $namelist[] = $citem['name']; } $coupon_discount = 0; if ($user_discount = $this->Customer_model->getDiscount($this->session->userdata('customer_id'))) { $totals['discount'] = $totals['itemtotal'] * $user_discount / 100; } else { if ($this->session->userdata('coupon')) { $coupon = get_coupon_discount($this->session->userdata('coupon'), $totals['itemtotal']); $totals['coupon_code'] = $coupon->discount_name; $totals['coupon'] = $coupon->discount_amount ? $coupon->discount_amount : $coupon->discount_percentage * $totals['itemtotal'] / 100; } $totals['discount'] = get_discount($totals['itemtotal']); $totals['companyless'] = get_company_discount($totals['itemtotal'], $this->session->userdata('customer_id') ? $this->session->userdata('customer_id') : '0'); } if ($totals['discount'] > 0) { $skulist[] = 'Discount'; $qlist[] = 0; $amtlist[] = $totals['discount'] * -100; $namelist[] = 'Discount'; $productids[] = 'Discount'; $itemvalues[] = round($totals['discount'] * 100); $units[] = 1; } else { $productids[] = 'Discount'; $itemvalues[] = 0; $units[] = 1; } $totals['grandtotal'] = $totals['itemtotal'] + $totals['shipping'] + $totals['service'] + $totals['surcharge'] + $totals['tax'] - $totals['discount'] - $totals['coupon'] - $totals['companyless']; $invoiceTotal = number_format($totals['grandtotal'], 2); $customer_id = $this->session->userdata('customer_id') ? $this->session->userdata('customer_id') : '0'; $affiliate_id = $this->session->userdata('referer') ? $this->session->userdata('referer') : ''; $this->form_validation->set_rules("cardnumber", 'Credit Card Number', 'required|numeric|min_length[15]|max_length[16]'); $this->form_validation->set_rules("expiry_month", 'Expiry Month', 'required|min_length[2]|max_length[5]'); $this->form_validation->set_rules("expiry_year", 'Expiry Year', 'required|min_length[2]|max_length[5]'); $this->form_validation->set_rules("cvv", 'CVV2', 'required|min_length[3]|max_length[5]'); $this->form_validation->set_error_delimiters('<span class="error error_span">', '</span>'); if ($this->form_validation->run() == TRUE) { $eformat = file_get_contents('assets/email_format.html'); $eheader = file_get_contents('assets/email_header.html'); $this->load->library('plugnpay'); $order = unserialize(base64_decode($_POST['data'])); $country = $this->Country_model->get_country($order->country_id); $order->country = $country->country_name; $order->ipaddress = $_SERVER['REMOTE_ADDR']; $order->nameoncard = $this->input->post('nameoncard'); $order->cardnumber = $this->input->post('cardnumber'); $order->cvv = $this->input->post('cvv'); $order->expiry = $this->input->post('expiry_month') . '/' . $this->input->post('expiry_year'); $order->total = $totals['grandtotal']; $order->affiliate_id = $this->session->userdata('referer') ? $this->session->userdata('referer') : '0'; $eheader = str_replace('{firstname}', $order->firstname, $eheader); $eformat = str_replace('{firstname}', $order->firstname, $eformat); $eformat = str_replace('{lastname}', $order->lastname, $eformat); $eformat = str_replace('{address1}', $order->address1, $eformat); $eformat = str_replace('{address2}', $order->address2, $eformat); $eformat = str_replace('{city}', $order->city, $eformat); $eformat = str_replace('{postalcode}', $order->postalcode, $eformat); $eformat = str_replace('{country}', $order->country, $eformat); $eformat = str_replace('{email}', $order->email, $eformat); $eformat = str_replace('{dayphone}', $order->dayphone, $eformat); $eformat = str_replace('{evephone}', $order->dayphone, $eformat); $eformat = str_replace('{product_price}', '$' . number_format($totals['itemtotal'], 2), $eformat); $eformat = str_replace('{delivery_charge}', '$' . number_format($totals['shipping'], 2), $eformat); $eformat = str_replace('{service_charge}', '$' . number_format($totals['service'], 2), $eformat); $eformat = str_replace('{surcharge}', '$' . number_format($totals['surcharge'], 2), $eformat); $eformat = str_replace('{discount}', '$' . number_format($totals['discount'] - $totals['coupon'] - $totals['companyless'], 2), $eformat); $eformat = str_replace('{tax}', '$' . number_format($totals['tax'], 2), $eformat); $eformat = str_replace('{grand_total}', '$' . number_format($totals['grandtotal'], 2), $eformat); if ($_SERVER['REMOTE_ADDR'] == '127.0.0.1' && ENVIRONMENT == 'development') { $result['FinalStatus'] = 'success'; $payment_method = 'credit_card'; } else { $result = $this->plugnpay->pay($order); /* echo 'Website on Test...<br/>'; echo $result['MErrMsg']; echo '<pre>'; die(print_r($result)); echo '</pre>'; */ $payment_method = 'credit_card'; } if ($result['FinalStatus'] == 'success') { if ($oid = $this->Order_model->create_Order($this->session->userdata('cart_id'), $totals, $customer_id, $affiliate_id, $payment_method)) { //$linkimg = '<img src="http://track.linksynergy.com/ // ep?mid=xxxx&ord=xx&skulist=xxxx // &qlist=xxx&amtlist=xxxx&cur=xxx&namelist=xxxxx">'; $cart_id = $this->session->userdata('cart_id'); $this->db->where('cart_id', $cart_id); $this->db->update('carts', array('completed' => '1')); $this->session->set_userdata('cart_id', '0'); $temptot = $totals['itemtotal'] - $totals['discount'] - $totals['coupon']; $linkimg = '<img src="http://track.linksynergy.com/ep?mid=37609&ord=' . $oid; $linkimg .= '&skulist=' . implode('|', $skulist); $linkimg .= '&qlist=' . implode('|', $qlist); $linkimg .= '&amtlist=' . implode('|', $amtlist); $linkimg .= '&cur=CAD'; $linkimg .= '&namelist=' . implode('|', $namelist) . '">'; $tsa = '<script src="https://thesearchagency.net/tsawaypoint.php?siteid=855&wayid=7685&'; $tsa .= 'value=' . round($totals['grandtotal'] * 100); $tsa .= '&units=1|' . implode('|', $units) . '|1'; $tsa .= '&productID=order|' . implode('|', $productids) . '|Shipping'; $tsa .= '&itemValues=' . round($totals['grandtotal'] * 100) . '|' . implode('|', $itemvalues) . '|' . ($totals['shipping'] + $totals['service'] + $totals['surcharge']) * 100; $tsa .= '&backref=' . $oid . '" language="JavaScript" type="text/javascript"></script>'; $emlimg = '<img src="http://email.1800florists.ca/public/?q=direct_add&fn=Public_DirectAddForm&id=bvvqnvtvffundtrubmhhrsjocigpbmg&email='; $emlimg .= $order->email . '&field1=lastorderdate,set,'; $emlimg .= date('Y-m-d', time()) . '&field2=lastordertotal,set,'; $emlimg .= number_format($temptot, 2) . '&list1=0bba03ec00000000000000000000000492e6" width="0" height="0" border="0" alt=""/>'; $ggtrans = 'pageTracker._addTrans('; $ggtrans .= '"' . $oid . '",'; $ggtrans .= '"1-800-Flowers Canada",'; $ggtrans .= '"' . $temptot . '",'; $ggtrans .= '"' . number_format($totals['tax'], 2) . '",'; $ggtrans .= '"' . number_format($totals['shipping'] + $totals['service'] + $totals['surcharge'], 2) . '",'; $ggtrans .= '"Toronto",'; $ggtrans .= '"Ontario",'; $ggtrans .= '"Canada");'; $ggitems = ''; foreach ($cartitems as $citem) { $skulist[] = $citem['sku']; $qlist[] = $citem['qty']; $amtlist[] = $citem['amt']; $namelist[] = $citem['name']; $ggitems .= 'pageTracker._addItem('; $ggitems .= '"' . $oid . '",'; $ggitems .= '"' . $citem['sku'] . '",'; $ggitems .= '"' . $citem['name'] . '",'; $ggitems .= '"' . $citem['category'] . '",'; $ggitems .= '"' . number_format($citem['amt'] / 100, 2) . '",1'; $ggitems .= ');' . "\n"; } $data['googlecode'] = $ggtrans . "\n\n" . $ggitems; $data['linkimg'] = $linkimg; $data['tsa'] = $tsa; $data['emlimg'] = $emlimg; $data['conversion'] = $conversion; $data['invoiceTotal'] = $invoiceTotal; $eformat = str_replace('{invoice_num}', $oid, $eformat); $admin_format = $eformat; $admin_format = str_replace('{items}', $aitemformat, $admin_format); $admin_format = str_replace('{email_header}', 'User Type:' . strtoupper($this->session->userdata('user_role')), $admin_format); $eformat = str_replace('{items}', $itemformat, $eformat); $eformat = str_replace('{email_header}', $eheader, $eformat); $this->load->library('email'); $email_config['mailtype'] = 'html'; $this->email->initialize($email_config); $this->email->from('*****@*****.**', '1-800-Flowers'); //$this->email->to($order->email); $this->email->to($order->email); $this->email->subject('1-800-Flowers Order Confirmation'); $this->email->message($eformat); if ($this->email->send()) { $success = true; } $this->email->from('*****@*****.**', '1-800-Flowers'); $this->email->to('*****@*****.**'); $this->email->subject('1-800-Flowers Order Confirmation'); $this->email->message($admin_format); if ($this->email->send()) { $success = true; } $this->unset_cart(); $data['items'] = $this->Order_model->getDelivery($cart_id); $data['message'] = 'Your order completed successfully'; $data['invoice_number'] = $oid; $data['totals'] = $totals; $data['billing'] = $this->Order_model->getBilling($cart_id); $data['page'] = $this->Pages_model->return_page('order-thanks'); $data['paths'] = array('Home' => path(), 'Checkout' => '#', 'Thank you' => ''); $this->load->view('thankyou', $data); exit; } } else { $elist = '<ul class="elist">'; if ($cerrors = explode('|', $result['MErrMsg'])) { foreach ($cerrors as $ce) { if (!empty($ce)) { $elist .= '<li>' . $ce . '</li>'; } } } else { $elist = '<li>' . $result['MErrMsg'] . '<li>'; } $elist .= '</ul>'; $elist = '<div class="show_errors"><h3>' . 'Error in Payment' . '</h3>' . $elist . '</div>'; } } $this->load->Model('Occasion_model'); $data['elist'] = isset($elist) ? $elist : ''; $data['countries'] = $this->Country_model->get_countries(); $data['items'] = $this->Order_model->getDelivery($cart_id); $data['occasions'] = $this->Occasion_model->get_occasions_array(); $data['billing'] = $this->Order_model->getBilling($cart_id); if ($this->session->userdata('user_role') == 'company') { $this->load->model('Company_model'); $pmethod = $this->Company_model->get_pmethod($this->session->userdata('customer_id')); if ($pmethod == 1) { $data['on_account'] = 1; } else { $data['on_account'] = 0; } } else { $data['on_account'] = 0; } $data['encoded'] = base64_encode(serialize($data['billing'])); $data['totals'] = $totals; $data['current_page'] = 'revieworder'; $data['page'] = $this->Pages_model->return_page('checkout'); $data['paths'] = array('Home' => path(), 'Checkout' => '#', 'Review & Pay' => ''); $this->load->View('checkout', $data); } }
public function cartsummary() { $this->load->model('Memorial_model'); $this->load->model('Affiliate_model'); $comm = $this->Affiliate_model->get_affiliate($this->session->userdata('affiliate_id')); $this->load->model('Group_model'); $cart = $this->Order_model->get_cart($this->session->userdata('cart_id')); $totals = array('itemtotal' => 0, 'shipping' => 0, 'service' => 0, 'surcharge' => 0, 'tax' => 0, 'coupon' => 0, 'coupon_code' => '', 'discount' => 0, 'grandtotal' => 0, 'discount_type' => 'percentage', 'coupon_type' => 'percentage'); $coupon_discount = 0; $this->load->model('Company_model'); $this->load->model('Customer_model'); $cartdiscount = 0; $cartcoupon = 0; $cartdiscounttype = 'percentage'; $cartcoupontype = 'percentage'; foreach ($cart as $item) { $totals['itemtotal'] += $item->product_price; foreach ($item->addons as $addon) { $totals['itemtotal'] += $addon->addon_price * $addon->addon_quantity; } } if ($user_discount = $this->Customer_model->getDiscount($this->session->userdata('customer_id'))) { $totals['discount'] = $totals['itemtotal'] * $user_discount / 100; } else { if ($this->session->userdata('coupon')) { if ($coupon = get_coupon_discount($this->session->userdata('coupon'), $totals['itemtotal'])) { $totals['coupon_code'] = $coupon->discount_name; if ($coupon->discount_amount > 0) { $cartcoupon = $coupon->discount_amount; $cartcoupontype = 'amount'; } else { $cartcoupon = $coupon->discount_percentage; $cartcoupontype = 'percentage'; } } } if ($cartcoupon <= 0) { if ($discount = get_discount($totals['itemtotal'])) { if ($discount->discount_amount > 0) { $cartdiscount = $discount->discount_amount; $cartdiscounttype = 'amount'; } else { $cartdiscount = $discount->discount_percentage; $cartdiscounttype = 'percentage'; } } } } $itemscount = count($cart); foreach ($cart as $item) { $ptotal = $item->product_price; foreach ($item->addons as $addon) { $ptotal += $addon->addon_price * $addon->addon_quantity; } $addition = $this->Order_model->get_add_estimate($item->orderitem_id); //$addition = $this->Group_model->get_add_charges($item->product_id,$item->postalcode); //san has changed on 13-7-2013 //$totals['shipping'] += 10; ///$addition['shipping']; $totals['shipping'] += $addition['shipping']; $totals['service'] += $addition['service']; $totals['surcharge'] += $addition['surcharge']; if ($cartcoupon > 0) { if ($cartcoupontype == 'percentage') { $totals['coupon'] += $cartcoupon * $ptotal / 100; $ptotal -= $cartcoupon * $ptotal / 100; } else { $part = $cartcoupon / $itemscount; $totals['coupon'] += $part; $ptotal -= $part; } } else { if ($cartdiscounttype == 'percentage') { $totals['discount'] += $cartdiscount * $ptotal / 100; $ptotal -= $cartdiscount * $ptotal / 100; } else { $part = $cartdiscount / $itemscount; $totals['discount'] += $part; $ptotal -= $part; } } $ptotal += $addition['shipping']; $ptotal += $addition['service']; $ptotal += $addition['surcharge']; $totals['tax'] += $addition['tax'] * $ptotal / 100; //$addition['tax'] } $totals['grandtotal'] = number_format($totals['itemtotal'], 2) + number_format($totals['shipping'], 2) + number_format($totals['service'], 2) + number_format($totals['surcharge'], 2) + number_format($totals['tax'], 2) - number_format($totals['discount'], 2) - number_format($totals['coupon'], 2); $data['p'] = (object) $_POST; $data['totals'] = $totals; $data['cart'] = $cart; //$data['commission'] = ($this->cart->total() * $comm->commission)/100; $result = array('cartsummary' => $this->load->view('mymemorial/summary', $data, true), 'shipping' => $totals['shipping'], 'tax' => $totals['tax'], 'commission' => 0); echo json_encode($result); }
function get_tiny_cart() { $ci =& get_instance(); $cart_id = $ci->session->userdata('cart_id'); $cart_id = $cart_id > 0 ? $cart_id : 0; $cart = $ci->db->query("SELECT * FROM order_items WHERE cart_id={$cart_id}"); $items = 0; $value = 0; foreach ($cart->result() as $row) { $value += $row->product_price; $items++; $addons = $ci->db->query("SELECT * FROM order_addons WHERE orderitem_id=" . $row->orderitem_id); foreach ($addons->result() as $addon) { $value += $addon->addon_quantity * $addon->addon_price; } } $result->total = $value; if ($ci->session->userdata('coupon') && $items > 0) { $coupon = get_coupon_discount($ci->session->userdata('coupon'), $value); $value -= $coupon->discount_amount ? $coupon->discount_amount : $coupon->discount_percentage * $value / 100; } $result->items = $items; $result->gtotal = $value; return $result; }
function get_totals($cartid) { $cart = $this->Order_model->get_fullcart($this->session->userdata('cart_id')); $totals = array('itemtotal' => 0, 'shipping' => 0, 'service' => 0, 'surcharge' => 0, 'tax' => 0, 'discount' => 0, 'coupon' => 0, 'coupon_code' => '', 'companyless' => 0, 'grandtotal' => 0); $cartdiscount = 0; $cartcoupon = 0; $cartdiscounttype = 'percentage'; $cartcoupontype = 'percentage'; foreach ($cart as $item) { $totals['itemtotal'] += $item->product_price; $ptotal = $item->product_price; foreach ($item->addons as $addon) { $totals['itemtotal'] += $addon->addon_price * $addon->addon_quantity; } } if ($this->session->userdata('coupon')) { if ($coupon = get_coupon_discount($this->session->userdata('coupon'), $totals['itemtotal'])) { $totals['coupon_code'] = $coupon->discount_name; if ($coupon->discount_amount > 0) { $cartcoupon = $coupon->discount_amount; $cartcoupontype = 'amount'; } else { $cartcoupon = $coupon->discount_percentage; $cartcoupontype = 'percentage'; } } } if ($cartcoupon <= 0) { if ($discount = get_discount($totals['itemtotal'])) { if ($discount->discount_amount > 0) { $cartdiscount = $discount->discount_amount; $cartdiscounttype = 'amount'; } else { $cartdiscount = $discount->discount_percentage; $cartdiscounttype = 'percentage'; } } } $addition = $this->Order_model->get_add_charges($item->orderitem_id); $totals['shipping'] += $addition['shipping']; $totals['service'] += $addition['service']; $totals['surcharge'] += $addition['surcharge']; if ($cartcoupon > 0) { if ($cartcoupontype == 'percentage') { $totals['coupon'] += $cartcoupon * $ptotal / 100; $ptotal -= $cartcoupon * $ptotal / 100; } else { $part = $cartcoupon / $itemscount; $totals['coupon'] += $part; $ptotal -= $part; } } else { if ($cartdiscounttype == 'percentage') { $totals['discount'] += $cartdiscount * $ptotal / 100; $ptotal -= $cartdiscount * $ptotal / 100; } else { $part = $cartdiscount / $itemscount; $totals['discount'] += $part; $ptotal -= $part; } } $ptotal += $addition['shipping']; $ptotal += $addition['service']; $ptotal += $addition['surcharge']; $totals['tax'] += $addition['tax'] * $ptotal / 100; $affid = $this->session->userdata('referer'); if ($affid != '') { $totals['grandtotal'] = round($totals['itemtotal'], 2) + round($totals['shipping'], 2) + round($totals['service'], 2) + round($totals['surcharge'], 2) + round($totals['tax'], 2) - round($totals['discount'], 2) - round($totals['coupon'], 2); } else { $totals['grandtotal'] = round($totals['itemtotal'], 2) + round($totals['shipping'], 2) + round($totals['service'], 2) + round($totals['surcharge'], 2) + round($totals['tax'], 2) - round($totals['discount'], 2) - round($totals['coupon'], 2); } return $totals; }