Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142454

Update shopping cart quantity using SweetAlert in Ajax and CodeIgniter to

$
0
0

I need help for updating qty in cart. if the quantity < the product stock, a sweetalert will appear. But, in my project, it did not happen. Anyone can help me ?

Some code update cart in controller

    foreach ($barang as $item) {
        if ($mana_outstok <> '') {
            $pesan = 'The product is not enough!';
            $msg = [
                'validasi' =>  $pesan
            ];
            echo json_encode($msg);
        } else {
            $data = [
                'c_price' => $item['qty'] * $item['barang_harjul'],
                'qty' => $item['qty']
            ];

            // $cid = implode($c_cart_id);
            $where = [
                'c_cart_id' => $c_cart_id,
                'barang_id' => $item['barang_id']
            ];

            $this->db->where($where);
            $this->db->update('tbl_cart_detail', $data);
        }
    }

and this my code js and ajax

            e.preventDefault();
            $.ajax({
                url: "<?php echo base_url(); ?>toko/cart/updatecart",
                method: "POST",
                data: {
                    c_cart_id: c_cart_id,
                    barang_id: barang_id,
                    qty: qty,
                    barang_harjul: barang_harjul
                },
                success: function(data) {
                    if (data.validasi) {
                        Swal.fire({
                            icon: 'error',
                            title: 'Oops...',
                            text: $pesan,
                        });
                    } else {
                        console.log(data);
                    }

                }
            });
            // window.location.reload();

and in view, i using class updatecart in button update to call into js


Viewing all articles
Browse latest Browse all 142454

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>