野丹福ady / wfcart
此包的最新版本(v1.0.0)没有提供许可证信息。
Codeigniter 4 中的购物车免费开源库/包
v1.0.0
2020-05-17 18:09 UTC
Requires
- php: ^7.2
- wildanfuady/wfcart: 1.*
This package is auto-updated.
Last update: 2024-09-18 19:54:23 UTC
README
免费开源库/包购物车 For Codeigniter 4
安装方法
- 进入项目目录/app/ThirdParty
cd app/ThirdParty
- 克隆仓库
git clone https://github.com/wildanfuady/WFcart.git
- 激活autoload。请打开文件 app/Config/Autoload.php 并查找以下代码
$psr4 = [
'App' => APPPATH, // To ensure filters, etc still found,
APP_NAMESPACE => APPPATH, // For custom namespace
'Config' => APPPATH . 'Config'
];
在此处添加一行代码
$psr4 = [
'App' => APPPATH, // To ensure filters, etc still found,
APP_NAMESPACE => APPPATH, // For custom namespace
'Config' => APPPATH . 'Config',
'Wildanfuady' => APPPATH . 'ThirdParty/WFcart/Wildanfuady'
];
使用方法
- 在Controller类名之前添加以下代码
use Wildanfuady\WFcart\WFcart;
class Cart extends BaseController
{
// code
}
- 在构造函数中,添加以下代码行
public function __construct() {
$this->cart = new WFcart();
}
- 要获取购物车商品总数,请使用以下命令
$this->cart->totals();
- 要获取购物车总金额(数量 * 单价),请使用以下命令
$this->cart->count_totals();
- 要将商品添加到购物车,请使用以下命令
$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);
- 要根据id删除购物车中的商品,请使用以下命令
$this->cart->remove($id);
- 要更新购物车,请使用以下命令
$this->cart->update();