Free Open Source Library / Package Shopping Cart For Codeigniter 4
- Masuk ke dalam direktory project/app/ThirdParty
cd app/ThirdParty
- Clone Repository
git clone https://github.com/wildanfuady/WFcart.git
- Aktifkan autoload. Silahkan buka file app/Config/Autoload.php dan cari kode berikut ini:
$psr4 = [
'App' => APPPATH, // To ensure filters, etc still found,
APP_NAMESPACE => APPPATH, // For custom namespace
'Config' => APPPATH . 'Config'
];
Tambahkan 1 baris kode di bawah ini:
$psr4 = [
'App' => APPPATH, // To ensure filters, etc still found,
APP_NAMESPACE => APPPATH, // For custom namespace
'Config' => APPPATH . 'Config',
'Wildanfuady' => APPPATH . 'ThirdParty/WFcart/Wildanfuady'
];
- Tambahkan kode berikut sebelum nama class di Controller
use Wildanfuady\WFcart\WFcart;
class Cart extends BaseController
{
// code
}
- Pada function construct, tambahkan baris kode di bawah ini:
public function __construct() {
$this->cart = new WFcart();
}
- Untuk mendapatkan data total keranjang belanja, gunakan perintah di bawah ini:
$this->cart->totals();
- Untuk mendapatkan data total belanja ( quantity * sub total), gunakan perintah di bawah ini:
$this->cart->count_totals();
- Untuk memasukan suatu product ke dalam keranjang belanja, gunakan perintah di bawah ini:
$id = 1; // ambil dari kode product
$item = [
'id' => $id,
'name' => 'Product 1,
'price' => 1000,
'photo' => 'product1.jpg',
'quantity' => 1
];
$this->cart->add_cart($id, $item);
- Untuk menghapus suatu product berdasarkan id di dalam keranjang belanja, gunakan perintah di bawah ini:
$this->cart->remove($id);
- Untuk mengupdate keranjang belanja, silahkan gunakan perintah di bawah ini:
$this->cart->update();