noahenrik/cart2go
Composer 安装命令:
composer require noahenrik/cart2go
包简介
A simple shopping cart.
README 文档
README
This is a simple cart system made for PHP that will allow you to save item IDs to add to your cart. Saving prices is risky and should always be checked in the back-end.
Installation
Use composer to install cart2go.
composer require noahenrik/cart2go
Make sure to update your autoloader. For composer:
composer dump-autoload
Usage
Import the namespace with class:
$cart = new \Cart\Cart();
Add items to cart:
The addItemToCart method takes 2 paramaters, itemId and $amount. Amount is an optional paramater.
If the user clicks on an item that's already in the cart, the amount will automatically be incremented by 1.
If you specify an amount, the existing amount will be updated to the amount given and not incremented by 1.
$cart->addItemToCart($itemId, $amount); //OR $cart->addItemToCart($itemId);
Grab all items currently in the cart:
This method will grab all the items currently in the cart.
$allCartItems = $cart->grabAllItems();
Example
$allCartItems = $cart->grabAllItems(); foreach ($allCartItems as $key => $cartItem) { echo "Amount: " . $allCartItems[$key]['amount'] . " ItemId: " . $allCartItems[$key]['itemId']; }
Reset a cart:
This will remove all items within the cart.
$cart->reset();
Grab single item:
This will grab only the selected item from the cart.
$cart->grabItem($itemId);
Remove item from cart:
This will remove a selected item from the cart.
$cart->removeItem($itemId);
License
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2020-08-04