Download the PHP package mmdm/sim-cart without Composer

On this page you can find all versions of the php package mmdm/sim-cart. 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 sim-cart

Simplicity Cart

A simple library for shopping cart management.

Install

composer

Or you can simply download zip file from github and extract it, then put file to your project library and use it like other libraries.

Just add line below to autoload files:

and you are good to go.

Features

Architecture

This library use database to have its best performance

Collation:

It should be utf8mb4_unicode_ci because it is a very nice collation. For more information about differences between utf8 and utf8mb4 in general and unicode please see this link from stackoverflow

Table:

How to use

First of all you need a PDO connection like below:

Second you need a cookie class like below:

[Optionally But Highly Recommended] You need two keys to protect stored data in cookie. These two keys should be two base64 coded strings. Just generate two passwords and encode them to base64 strings. For more info about these two keys see this link

Instantiate cart library

Cart methods

setCartName(string $name)

You can name your cart. This will use when you want store a cart in your database. Default name is default.

getCartName(): string

Get cart's name.

setExpiration(int $expire_time)

Note: You need to send duration of cart to be expired like 86400 that is 1 day in seconds. After call store method, current time will add to this expire time.

Note: you must know this expire time is Different from expire time in database fields.

Set cart expiration time.

getExpiration(): int

Get cart expiration time. Default expiration time is 31536000 that is 1 year.

Note: This method just returns the time like 31536000 that is 1 year not how much it has to be expired but if you need to know expiration time until, store cart to database and get expire_at field of carts.

utils(): ICartsUtil

Utilities that can do with current cart and current user.

To see information about this utils, see CartUtil section.

Note: This only works if you pass a pdo connection and a user id to work with.

add(string $item_code, array $item_info = null)

Add an item to cart with product's code from product_property table. You can add extra information to item with $item_info parameter. At last the stored item has all product_property table's columns fields value and qnt parameter and your extra information.

Note: All item's keys are from keys of config file and as commented in config file too, DO NOT CHANGE keys please.

Note: By default items will not store in cookie and you should do it yourself using store method.

update(string $item_code, array $item_info = null)

It is like add method with extra functionality that is checking if item is added or it'll add it internally.

remove(string $item_code): bool

Remove an item from cart.

getItem(string $item_code): array

Get a specific item from cart.

getItems(): array

Get all cart's items.

clearItems()

Delete all items from cart.

hasItemWithCode(string $item_code): bool

Check if an item has been set in cart or not.

totalPrice(): float

Get total price of items.

totalDiscountedPrice(): float

Get total discounted price of items.

totalPriceWithTax(): float

Get total price of items with considering tax of each item.

totalDiscountedPriceWithTax(): float

Get total discounted price of items with considering tax of each item.

totalAttributeValue(string $key): float

Get total of a specific key of all items.

discountedPercentage(string $item_code, int $decimal_numbers = 2, bool $round = false): float

Get discount percentage of an specific item.

totalDiscountedPercentage(int $decimal_numbers = 2, bool $round = false): float

Get discount percentage of all items.

totalDiscountedPercentageWithTax(int $decimal_numbers = 2, bool $round = false): float

Get discount percentage of all items with considering items' tax.

store()

Store cart items to storage(cookie).

restore()

Restore cart items from storage(cookie) to cart items.

destroy()

Destroy cart from storage(cookie).

CartUtil methods

Instantiate

If you need to instantiate utils externally(YOU DON'T NEED)

runConfig()

Create tables structure.

getCart(): ICart

Get used cart in class.

setUserId(int $user_id)

Set user id to work with for database.

getUserId(): int

Get used user id.

save(int $max_stored_cart = PHP_INT_MAX, array $extra_parameters = [], string $extra_where = null, array $bind_values = []): bool

Save cart to database.

You can specify how many cart can store in database for a specific user. Also you can pass extra parameters and parameterized where clause for customize storing (table is carts here).

Note: You should use actual cart table columns name.

Note: Columns below will unset and use cart information instead:

To get exception of max stored cart count, and database errors, put your codes in try {...} catch() {...} block like:

fetch(bool $append_to_previous_items = false)

Fetch cart items from database and store them to provided cart class.

Note: It'll delete all items first, if you want to prevent this default behavior, send true as second parameter.

delete(string $cart_name): bool

Delete specific cart for specific user.

deleteExpiredCarts(string $cart_name): bool

Delete expired cart for specific user.

changeName(string $old_cart_name, string $new_cart_name): bool

Change cart name from old name to new name for a specific user.

getItem(string $item_code, $columns = '*'): array

Get specific item with specific columns.

getStockCount(string $item_code): int

Get stock count for a specific item.

getMaxCartCount(string $item_code): int

Get max cart count for a specific item.

Examples

Create all tables

Add item to cart

Update item in cart

Very Important Note: You can't change an item value that has value in database. Just quantity and your extra information.

Cart and storage

Report

Dependencies

There is some dependencies here including:

Crypt library. With this feature, if any session/cookie hijacking happens, they can't see actual data because it is encrypted.

Cookie library to manipulate cookies.

License

Under MIT license


All versions of sim-cart with dependencies

PHP Build Version
Package Version
Requires ext-pdo Version *
ext-json Version *
mmdm/sim-cookie Version ^3.0
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 mmdm/sim-cart contains the following files

Loading the files please wait ....