承接 gabrieljmj/cart 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gabrieljmj/cart

Composer 安装命令:

composer require gabrieljmj/cart

包简介

Simple shopping cart system

README 文档

README

Total Downloads Latest Unstable Version License Build Status Scrutinizer Code Quality

Simple shopping cart system.

##Usage ####Adding product to cart Use the method \Gabrieljmj\Cart\Cart::add(ProductInterface $product) to add a product. If previously the same product was added, will be add one more to cart.

use Gabrieljmj\Cart\Product\Product;
use Gabrieljmj\Cart\Cart;

$product = new Product(1, 'TV', 499.90, ['tv', 'led']);
$cart = new Cart();
$cart->add($product);

####Removing product of a cart Using \Gabrieljmj\Cart\Cart::remove($product[, $amount = 0]) you can remove products of a cart. If $amount be 0, all products of that products will be removed. The argument $product can be an instance of \Gabrieljmj\Cart\Product\ProductInterface or product id.

$cart->remove(1);

####Clearing the cart To this use the method \Gabrieljmj\Cart\Cart::clear.

$cart->clear();

####Verifying if the cart has a product The $product argument can be the product id or an instance of \Gabrieljmj\Cart\Product\ProductInterface. The return will be boolean.

$cart->has($product);

####Counting how many products has in the cart The method \Gabrieljmj\Cart\Cart::count() will return how many items has in the cart.

$cart->count();

####Counting how many products of a type has in the cart Use the method \Gabrieljmj\Cart\Cart::getTotalOfAProduct($product) and like others, $product can be an instance of \Gabrieljmj\Cart\Product\ProductInterface or product id.

$cart->getTotalOfAProduct($product);

####Counting how many types of products has in the cart And this method (\Gabrieljmj\Cart\Cart::countUniqueItems()) counts how many types of products has in the cart.

$cart->countUniqueItems();

####Calculating total price of the cart The method \Gabrieljmj\Cart\Cart::getTotalPrice() returns how much costs the cart.

$cart->getTotalPrice();

####Iterating with all products Each product will return an instance of \Gabrieljmj\Cart\Product\ProductInterface:

$iterator = $cart->getIterator();

while ($iterator->valid()) {
    $curr = $iterator->current();
    echo '<li><b>Product:</b>' . $curr->getProduct()->getName() . ' / <b>Total:</b> ' . $cart->getTotalOfAProduct($curr) . '</li>';
    $iterator->next();
}

####Storaging The instance of the cart usually is save on a session or a cookie.

$_SESSION['cart'] = $cart;
//or
setcookie('cart', $cart);

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-12-29