Welcome Guest, Not a member yet? Register   Sign In
Cart whith TAX
#1

[eluser]Dzemail[/eluser]
Please someone help me to in the cart have tax and to sum total tax ,sum total price with out tax and ,sum total with tax ,,,,,,,
please
#2

[eluser]CroNiX[/eluser]
Does that need to be done in the cart library itself or can you just calculate it using the totals in the cart upon checkout? Usually that stuff is presented upon final checkout and it should be easy to just multiply the total by the sales tax to get the tax, and then add that to the final price to get the final price with tax.
#3

[eluser]bgreene[/eluser]
our site has products at various tax rates eg food, stationery etc so my approach was to use the following code when inserting an item (pardon the mess, i'm no expert but if might help you along the way.
Code:
function _packadd($pack,$qty){
   $rowid = false;
   if (! $qty) $qty = 1;
   else
   if ($qty <= 0) $qty = 1;
   $data = array(
      'id'      => $pack->id,
      'price'   => $pack->rate,
      'name'    => $pack->code, // eg CF214
      'qty'     => $qty,
      'options' => array(
         'title' => $pack->caption, // eg cat food, very tasty
         'vatcodeid' => $pack->vatcode_id, // eg 316
         'vatcode' => $pack->vatcode, //  eg S,
         'vatrate' => $pack->vatrate, //  eg 21.5
         'weight' => $pack->weight,
         'thumb' => $pack->thumb, // thumbnail for the trolley
         'prodid' => $pack->prod_id
      )
   );
   foreach ($this->cart->contents() as $items){
      if ($items['id'] == $data['id']) {
         $rowid = $items['rowid'];
         $this->cart->update(
            array('rowid'=>$items['rowid'], 'qty' => $items['qty']+$data['qty'] )
         );
         break;
      }
   }
   if (! $rowid) {$rowid = $this->cart->insert($data);}
   return $rowid;
}

and then, i created a MY_Cart as follows
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Cart extends CI_Cart {

public $showreverseorder = true;

   public function __construct() {
      parent::__construct();
   }

   function vatinclusive(){
      return $this->CI->session->userdata('showvatinc');
   }

   public function deleteall(){
      $ar = array();
      foreach ($this->contents() as $item){
         $ar[] = array('rowid'=>$item['rowid'],'qty'=> 0);
      }
      $this->update($ar);
   }

   public function trolleySummary(){
      if ($this->total_items() == 0)
         return '<a href="'. site_url('trolley') .'">Trolley<br/>Products:&nbsp;'.'0'.
         '<br/>Total:&nbsp;&nbsp;&euro;&nbsp;'.money_str(0) .'<br/><span>View Contents</span></a>';
      else
         if ($this->vatinclusive())
    return '<a href="'. site_url('trolley') .'">Trolley<br/>Products:&nbsp;'.$this->total_items().
       '<br/>Total:&nbsp;&nbsp;&euro;&nbsp;'
.money_str($this->nett()+$this->nettVat() ).'<br/><span>View Contents</span></a>';
else
return '<a href="'. site_url('trolley') .'">Trolley<br/>Products:&nbsp;'.$this->total_items().
     '<br/>Total:&nbsp;&nbsp;&euro;&nbsp;'.money_str($this->nett()).'<br/><span>View Contents</span></a>';
   }

   public function trolleyTable($id,$readonly=false){
      $s = '
       <table class="seltbl" id="'.$id.'">
<thead> <tr>   <th>Code</th>    <th>Description</th>
    <th>Image</th>
    <th>Qnty</th>
    <th>Rate</th>
    <th>VAT</th>
    <th>Amount</th>
  </tr>
  </thead><tbody id="trolleyItems">';
  $b = false;
  $ar = $this->contents();
  if ($this->showreverseorder) $ar = array_reverse($ar);
  foreach ($ar as $items){
   if ($b) $sx .= 'class="altrow"';
   else $sx = '';
   $b = !$b;
   $s .= '<tr
   <td class="pack_code" >'.$items['name'].'<br/><span>(details...)</span></td>
   <td class="pack_title">'.$items['options']['title'].'</td>
   <td><img src="'. static_url('images/products/small/'.$items['options']['thumb']) .'"
       class="prod_thumbnail" alt="thumbnail" /></td>
   <td class="pack_qnty">';
   if ($readonly) $s .= $items['qty'];
   else
    $s .= '&lt;input class="pack_qntyedit" id="'.$items['rowid'].'" name="Qty" value="'.$items['qty'].'" maxlength="4"/ &gt;';
    
   $s .='</td>
   <td class="pack_rate">'.money_str($items['price']).'</td><td class="pack_vat">'.$items['options']['vatcode'].'</td>
   <td class="pack_amt">'.money_str($items['subtotal']).'</td></tr>';
  }
  if ($this->total_items() > 0)
   $s .= '<tr><td class="pack_code">'.'DLVRY'.'</td>
   <td class="pack_title">'.'Delivery Charge'.'</td>
   <td>&nbsp;</td>
   <td class="pack_qnty">1</td>
   <td class="pack_rate">'.money_str($this->freight()).'</td><td class="pack_vat">'.$this->CI->config->item('freight_vat_code').'</td>
   <td class="pack_amt">'.money_str($this->freight()).'</td></tr>';
  $s .= '
   <tr>
     <td colspan="5"></td>
     <td class="trolley_totalname">Nett</td>
     <td class="trolley_totalamt">&euro;&nbsp;'.money_str($this->nett()+$this->freight()) .'</td>
   </tr>
   <tr>
     <td colspan="5"></td>
     <td class="trolley_totalname">VAT</td>
     <td class="trolley_totalamt">&euro;&nbsp;'.money_str($this->nettVat()+$this->freightVat()) .'</td>
   </tr>
   <tr>
     <td colspan="5"></td>
     <td class="trolley_totalname">Total</td>
     <td class="trolley_totalamt">&euro;&nbsp;'.money_str($this->gross()) .'</td>
   </tr>
   </tbody>
   </table>';
  return $s;
}


   public function freight(){
      if ($this->total_items() == 0) return 0;
      else
if (($this->nett()+$this->nettVat()) >= $this->CI->config->item('freight_freeabove')) return 0;
  else return $this->CI->config->item('freight_dfltrate');
   }

   public function freightVat(){
      return $this->freight()*$this->CI->config->item('freight_vat_rate')/100;
   }

   public function gross(){
      return $this->nett()+$this->nettVat()+$this->freight()+$this->freightVat();
   }

   public function nett(){
      return $this->total();
   }

   public function nettVat(){
      $vatrates = array();
      foreach ($this->contents() as $item){
$vr = $item['options']['vatrate'];
if (! array_key_exists($vr,$vatrates)) $vatrates[$vr] = 0;
    $vatrates[$vr] += ($item['price']*$item['qty']);
}
$result = 0;
foreach ($vatrates as $vr=>$nett) $result += $nett*$vr/100;
return $result;
   }
}
#4

[eluser]Dzemail[/eluser]
Thank you very much for the code ,but i have one more anser .My_Cart i must change whith the Cart.php or ?
or if u can send some soucure project for this if u can thank you.
io a beginer in this platform
#5

[eluser]bgreene[/eluser]
i placed "My_Cart.php" in libraries. code exactly as pasted. btw, showreverseorder means the last item in the cart appears at the top of the list, first at bottom. this is because just above the table i have a quickadd facility which allows to simply enter code, qnty and hit ok rather than traipse around the site looking for something. by having the items in reverse order, you have the visual confirmation of what you just quickadded immediately below the edit box so you dont have to keep scrolling down. im also a beginner so its the blind leading the blind 8=) - check my code with a jaundiced eye
#6

[eluser]Dzemail[/eluser]
Message: Undefined property: CI_Loader::$My_Cart

this error i get
#7

[eluser]bgreene[/eluser]
u dont need to load it, it extends cart so just load cart. btw im using ci2
#8

[eluser]Dzemail[/eluser]
please do not do it if you can send me a project if you do not have hard, thank you all one
in an email [email protected]




Theme © iAndrew 2016 - Forum software by © MyBB