[ASK] limit item cart - El Forum - 12-02-2009
[eluser]jshot[/eluser]
i have problem with CI cart class, the inserted item with cart limited on my web,
i am confused, anyone can help me,
my DB :
Code: CREATE TABLE IF NOT EXISTS `part_mobil` (
`no` int(10) NOT NULL auto_increment,
`kode_part` varchar(50) NOT NULL,
`merk_mobil` varchar(50) NOT NULL,
`kode_mobil` varchar(50) NOT NULL,
`kategori` varchar(50) NOT NULL,
`gambar` varchar(50) NOT NULL,
`nama` varchar(50) NOT NULL,
`keterangan` varchar(1000) NOT NULL,
`part_number` varchar(50) NOT NULL,
`type` varchar(50) NOT NULL,
`stok` int(10) NOT NULL,
`harga` bigint(50) NOT NULL,
`tgl_input` varchar(30) NOT NULL,
PRIMARY KEY (`no`),
UNIQUE KEY `kode_part` (`kode_part`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=61 ;
harga = price
kode part = product id
nama = name
keterangan = short description
my controller standard with CI cart
Code: function index()
{
// show a couple products
$products = $this->db->get('part_mobil');
foreach ($products->result() as $product)
{
echo '<h3>' . anchor('shop/detail/' . $product->kode_part, $product->nama) . '</h3>';
echo '<p><b>' . $product->harga. '</b></p>';
echo '<p>' . $product->keterangan . '</p>';
echo '<hr>';
}
}
function detail()
{
// show the product and an "add to cart" link
$product_id = $this->uri->segment(3);
$product = $this->db->where('kode_part', $product_id)->get('part_mobil')->row();
echo '<h1>' . $product->nama . '</h1>';
echo '<p>' . $product->keterangan . '</p>';
echo '<p><b>' . $product->harga . '</b></p>';
echo form_open('shop/add_to_cart');
echo form_hidden('product_id',$product->kode_part);
echo form_hidden('product_name', $product->nama);
echo form_hidden('product_price', $product->harga);
echo form_input('qty', '1');
echo form_submit('', 'Add to Cart');
echo form_close();
}
function add_to_cart()
{
// add the selected product to the cart
$data = array(
'id' => $this->input->post('product_id'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('product_price'),
'name' => $this->input->post('product_name'),
'options' => array()
);
$this->cart->insert($data);
redirect('shop/show_cart');
}
function update_cart()
{
$total = $this->cart->total_items();
for ($i = 1; $i <= $total; $i++)
{
$item = $this->input->post($i);
$data = array(
'rowid' => $item['rowid'],
'qty' => $item['qty']
);
$this->cart->update($data);
}
redirect('shop/show_cart');
}
//continue
[ASK] limit item cart - El Forum - 12-02-2009
[eluser]jshot[/eluser]
My insert DB
Code: INSERT INTO `part_mobil` (`no`, `kode_part`, `merk_mobil`, `kode_mobil`, `kategori`, `gambar`, `nama`, `keterangan`, `part_number`, `type`, `stok`, `harga`, `tgl_input`) VALUES
(41, '118b5f485617ad8d4864c08a48061a3c', 'KIA', 'CEED', 'Spareparts', '6.JPG', 'ceed sp', 'sedyset', 'ssp2', '3rw', 5, 500002, '03 November 2009 - 18:31:42'),
(42, 'e222b294c0d4d8e44e1b06c82ffec30d', 'KIA', 'SPECTRA', 'Exteriors', '4.JPG', 'spect', '45622', 'rt5422', 'se45y22', 50222, 20000221, '03 November 2009 - 18:32:22'),
(43, 'f44f297b37d1ef8fb582e48ed322eff4', 'KIA', 'FORTE', 'Wheel', '3.JPG', 'velg 19', 'velg aa bb cco', '192254o2', 'rimm22o', 1602, 250022, '03 November 2009 - 18:42:17'),
(44, 'a4efd0901c0051d5e1cb357698b9203e', 'HONDA', 'ACCORD', 'Spareparts', '9hq1pc.jpg', 'lampu spion accord', 'aa3', 'aa2', 'aa4', 2, 50000, '03 November 2009 - 21:13:17'),
(51, 'a5987d332a332b1b4fa99257f72ab860', 'KIA', 'CARENS', 'Spareparts', 'Vector_Wallpapers_by_mneti__61_.jpg', 'sdgh', 'asgsdf', 'hgfh', 'rty', 8, 345231, '04 November 2009 - 20:32:01'),
(35, 'ef3efc883935571f210c33aac44f6bc9', 'KIA', 'CEED', 'Engine', '02va8.jpg', 'fsad', 'w23rw', 'ghd', 'ewrt', 23, 23234, '03 November 2009 - 18:05:23'),
(46, 'c048749492430808b43e07c6a80c205b', 'HONDA', 'ACCORD', 'Wheel', 'Slide131.JPG', 'velg 20', 'ydtyj', 'asdf', 'ewrt', 10, 750000, '03 November 2009 - 21:28:07'),
(50, '9f3ae09ecd8194d91e317c9fc28e4c7b', 'KIA', 'CARENS', 'Spareparts', '015583277.jpg', 'spareparts carens', 'sfvbs', '123', '432', 4, 443322, '04 November 2009 - 20:30:58'),
(52, '8336523715e2f5c61cd78c07d53592d8', 'KIA', 'CARENS', 'Spareparts', '1ibxv6.jpg', 'ersatz', 'uhluyiyuil" kj\n', '345', 'tyfddu', 456, 67676, '04 November 2009 - 20:32:33'),
(53, 'a0c6804bb70ad87b1f55a15bf6bbc15b', 'KIA', 'CARENS', 'Spareparts', '2h7klyb.jpg', 'uyiyujf', 'guikgyik" d sdf sdf sdf dsf sdf sdf sdf sdf sdf sd f', '67', '7676', 60, 686868, '04 November 2009 - 20:33:31'),
(56, '00e632cf17c4f2ce34e177ba517aee88', 'HONDA', 'CRV', 'Exteriors', '2ngegs4.jpg', 'afgsdg', 'sdfgsdfg sdf asdf sdf', 'dsfgsdfg', 'sdfg', 43, 3433, '05 November 2009 - 01:38:40');
Code: function show_cart()
{
if( $this->cart->contents() != NULL )
{
//$this->load->view('public/shop/cart');
?>
<?php echo form_open('shop/update_cart'); ?>
<table cellpadding="6" cellspacing="1" style="width:100%" border="0">
<p><?php echo anchor('shop', 'Continue Shopping'); ?></p>
<tr>
<th width="50">Jumlah</th>
<th>Nama Part</th>
<th style="text-align:right">Harga Satuan</th>
<th style="text-align:right">Sub-Total</th>
</tr>
<?php $i = 1; ?>
<?php foreach($this->cart->contents() as $items): ?>
<?php echo form_hidden($i.'[rowid]', $items['rowid']); ?>
<tr>
<td><?php echo form_input(array('name' => $i.'[qty]', 'value' => $items['qty'], 'maxlength' => '5', 'size' => '5' , 'style' => 'border:solid 1px #000000;' )); ?></td>
<td>
<?php echo $items['name']; ?>
<?php if ($this->cart->has_options($items['rowid']) == TRUE): ?>
(
<?php foreach ($this->cart->product_options($items['rowid']) as $option_name => $option_value): ?>
<?php echo $option_value; ?>
<?php endforeach; ?>
)
<?php endif; ?>
</td>
<td style="text-align:right">Rp <?php echo $this->cart->format_number($items['price']); ?></td>
<td style="text-align:right">Rp <?php echo $this->cart->format_number($items['subtotal']); ?></td>
</tr>
<?php $i++; ?>
<?php endforeach; ?>
<tr>
<td colspan="2"> </td>
<td style="text-align:right; background:#999999;"><strong>Total</strong></td>
<td style="text-align:right; background:#999999;">Rp <?php echo $this->cart->format_number($this->cart->total()); ?></td>
</tr>
</table>
<p><?php echo form_submit('', 'Update your Cart'); ?></p>
<?php
}
else
{
echo "Data belum ada!";
}
}
function clear_cart()
{
$this->cart->destroy();
redirect('shop');
}
}
when I add many data to cart, it just limited 4 datas session from my DB
[ASK] limit item cart - El Forum - 01-12-2010
[eluser]Unknown[/eluser]
This should solve your problems:
Important: The Cart class utilizes CodeIgniter's Session Class to save the cart information to a database, so before using the Cart class you must set up a database table as indicated in the Session Documentation , and set the session preferences in your appliction/config/config.php file to utilize a database.
Read user guide on Shopping Cart Class in details.
[ASK] limit item cart - El Forum - 01-12-2010
[eluser]Ben Edmunds[/eluser]
That profile picture is incredibly distracting...
yet entertaining, haha
|