Download the PHP package lombervid/shoppingcart without Composer

On this page you can find all versions of the php package lombervid/shoppingcart. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package shoppingcart

[![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/lombervid/shoppingcart?display_name=tag&sort=semver)](https://github.com/lombervid/shoppingcart/releases/latest) [![Packagist](https://img.shields.io/packagist/v/lombervid/shoppingcart)](https://packagist.org/packages/lombervid/shoppingcart) ![PHP Version](https://poser.pugx.org/lombervid/shoppingcart/require/php) [![tests](https://github.com/lombervid/shoppingcart/actions/workflows/tests.yml/badge.svg)](https://github.com/lombervid/shoppingcart/actions/workflows/tests.yml?query=branch%3Amain) [![GitHub](https://img.shields.io/github/license/lombervid/shoppingcart)](https://github.com/lombervid/shoppingcart/blob/main/LICENSE)

ShoppingCart PHP Class

ShoppingCart is a simple PHP package that provides you with a simple shopping cart implementation stored in session.

Installation

Composer

You can install it using composer:

Usage

Create an instance of ShoppingCart class.

Add items

You can add items calling the method add() passing an Item instance as parameter.

at this point your $cart->items() will look like this:

Add extra fields to your item

You can also add extra fields (such as price, name, etc) to your item. The Item constructor receives a parameter fields which is an Array with the following structure:

when you provide the $fields param, each field of the array is added to your item.

with the above code your $cart->items() will look line:

Then you can access any extra field as if they were properties:

Remove items

You can remove an item from the cart calling the method remove($id) which receive item's $id as parameter.

Clear the cart

You can clear the cart calling the method clear() which removes all the items from the cart.

Advanced options

ShoppingCart

Cart options

It is an array of options. The default value is:

Option Type Default Description
name string shopping_cart Cart's name. Used to save the cart in storage
autosave bool true If set to true, cart is saved when object is destroyed
tax int\|float 0 Porcentaje to be used as tax (0 - 100)
shipping.amount int\|float 0 Shipping cost
shipping.free int\|float 0 Value after which shipping will be free. 0 to disable

Constructor

Parameter Type Default Required Description
$options array See Cart options false Cart options
$storage StorageInterface NativeSessionStorage false Storage driver

Methods

Name Description
add(Item $item, bool $append = true): void Add an item to the cart
remove(string $id): bool Remove an item from the cart
subtotal(): float Get subtotal
shipping(): float Get shipping cost
tax(): float Get tax
total(): float Get total
inCart(string $id): bool Check if an item is in the cart
items(): array Return the items in the cart
clear(): static Remove all items from the cart
isEmpty(): bool Check if the cart is empty
totalItems(): int Return the total (distinct) items in the cart
save(): void Save items in the storage
toArray(): array Return items as array

Item

Constructor

Parameter Type Default Required Description
$id string N/A true Identifier
$name string N/A true Name / description
$price float N/A true Price (>= 0)
$qty int 1 false Quantity (> 0)
$fields array [] false Extra fields
$discount float 0 false Discount (>= 0)

Methods

Name Description
add(int $qty): void Increase item's quantity by $qty
update(int $qty): void Update item's quantity to $qty
get(string $name, mixed $default = null): mixed Get $name property/field
hasDiscount(): bool Check if has a discount
price(): float Get item's price
total(): float Get total
toArray(): array Return item as array

Contributing

Refer to CONTRIBUTING for information.

License

MIT


All versions of shoppingcart with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package lombervid/shoppingcart contains the following files

Loading the files please wait ....