此包的最新版本(v1.0.0)没有提供许可证信息。

Codeigniter 4 中的购物车免费开源库/包

v1.0.0 2020-05-17 18:09 UTC

This package is auto-updated.

Last update: 2024-09-18 19:54:23 UTC


README

免费开源库/包购物车 For Codeigniter 4

安装方法

  1. 进入项目目录/app/ThirdParty
cd app/ThirdParty
  1. 克隆仓库
git clone https://github.com/wildanfuady/WFcart.git
  1. 激活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'
];

使用方法

  1. 在Controller类名之前添加以下代码
use Wildanfuady\WFcart\WFcart;

class Cart extends BaseController
{
    // code
}
  1. 在构造函数中,添加以下代码行
public function __construct() {

	$this->cart = new WFcart();

}
  1. 要获取购物车商品总数,请使用以下命令
$this->cart->totals();
  1. 要获取购物车总金额(数量 * 单价),请使用以下命令
$this->cart->count_totals();
  1. 要将商品添加到购物车,请使用以下命令
$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);
  1. 要根据id删除购物车中的商品,请使用以下命令
$this->cart->remove($id);
  1. 要更新购物车,请使用以下命令
$this->cart->update();

支持教程

  1. https://ilmucoding.com/shopping-cart-codeigniter-4/ (第1部分)
  2. https://ilmucoding.com/cart-codeigniter-4/ (第2部分)