Tengo un carrito de compra en el que los articulos son gratis pero el cargo por manejo(shipping) aumenta por cada 20 productos. Edite la libreria Cart para que haga este calculo pero cuando se selecciona mas de 1 articulo en el ultimo subtotal suma el primer subtotal con el 2do o el 3ro. Lo que necesito es que cada subtotal lo sume por separado con su respectiva cantidad y al final sumarlo en el total. El total lo suma todo bien pero los subtotales no hacen el calculo por separado.
Aqui les dejo el metodo _save_cart()
Código PHP:
function _save_cart()
{
// Unset these so our total can be calculated correctly below
unset($this->_cart_contents['total_items']);
unset($this->_cart_contents['cart_total']);
// Lets add up the individual prices and set the cart sub-total
$total = 0;
$items = 0;
$shippCount = '';
$shipping = 19.99;
$counter = 1;
$qty = array();
foreach ($this->_cart_contents as $key => $val)
{
// We make sure the array contains the proper indexes
if ( ! is_array($val) OR ! isset($val['price']) OR ! isset($val['qty']))
{
continue;
}
$items += $val['qty'];
// Set the subtotal
$r = range(1, $items);
foreach($r as $v)
{
if($counter % 20 - 1 === 0)
{
$shippCount += count($counter);
}
$counter++;
}
$this->_cart_contents[$key]['subtotal'] = ($this->_cart_contents[$key]['price'] * $this->_cart_contents[$key]['qty']);
$total += $this->_cart_contents[$key]['subtotal'];
}
// Set the cart total and total items.
$this->_cart_contents['total_items'] = $items;
$this->_cart_contents['cart_total'] = $total;
// Is our cart empty? If so we delete it from the session
if (count($this->_cart_contents) <= 2)
{
$this->CI->session->unset_userdata('cart_contents');
// Nothing more to do... coffee time!
return FALSE;
}
// If we made it this far it means that our cart has data.
// Let's pass it to the Session class so it can be stored
$this->CI->session->set_userdata(array('cart_contents' => $this->_cart_contents));
// Woot!
return TRUE;
}