Download the PHP package divineomega/laravel-extendable-basket without Composer

On this page you can find all versions of the php package divineomega/laravel-extendable-basket. 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 laravel-extendable-basket

🛒 Laravel Extendable Basket

Build Status Coverage Status StyleCI

Laravel Extendable Basket provides several abstract classes that implement basic ecommerce basket functionality. These classes must be extended by your application.

Installation

Just install the latest version using composer.

Setup

You need to perform various setup steps in order to make use of this package.

Database tables

Two database tables are required to store basket and basket item data. By default these are called baskets and basket_items. This package provides database migrations to create these tables.

To run these migrations, enter the following artisan command.

Models

Now you need to create two related models, one to hold basket details and one to hold basket items details. Two example models are shown below. They can be modified or added to as necessary.

Create a Basket model.

Create a BasketItem model.

Basketable interface

Anything that can be placed in the basket provided by this library is considered 'basketable'. You can make any existing Eloquent model basketable simply by making it implement the Basketable interface.

For example, if you had a Product model, you can change it as follows.

Note that any basketable models must have a getPrice() and a getName() method that returns a numeric price and textual name of the basketable, respectively.

Usage

This section describes the use of the basket and basket item functionality provided by this package. It assumes you have performed the required installation and setup, in the manner specified above.

Remember to use the basket and/or basket item models you have created, where necessary.

Getting the current basket

From anywhere in your application, you can get the current basket. If no basket currently exists in the session, one will be created.

Getting a new basket

If you need to discard the current basket and create a new one, such as after a user has placed an order, you can use the getNew method.

This method essentially doubles as emptying the basket.

Manual basket management

The static methods getCurrent and getNew store the current basket ID in the session. If you do not want this, you can manage baskets yourself, as you would with any Eloquent model.

Add item(s) to the basket

After getting the current basket, you can easily add items to it using the basket's add method. You need to provide it with a quantity and any basketable model.

Optionally, you can also provide an array of basket item meta data, which could be used to store information about variations on a product.

Getting basket items

Getting items from the basket and the basketable model they contain can be easily done. See the example below.

Changing the quantity of a basket item

Each basket item has a quantity associated with it. It is set when an item is added to the basket, but can be modified later via the setQuantity method.

Removing a basket item

Basket items can easily be removed simply by deleting them. See the following example.

Getting the unit cost of a basket item

Getting the unit cost of a basket item just involves calling the getPrice method of the basketable model associated with the basket item. See the example below.

Getting the line total of a basket item

The basket item class provides a getPrice method that gets the line total. This is simply the basketable's price multiplied by the basket item quantity. The example code below shows how to use this method.

Getting the total number of items in the basket

There is a single method in the basket class that can sum up all the basket item quantities. Just call the getTotalNumberOfItems method, as follows.

Getting the basket subtotal

A getSubtotal method is provided in the basket class that provides the total of all items in the basket. See the following example.

If you wish to add delivery costs or discounts, you can create a new getTotal method in your basket class. This method can call the getSubtotal method, and then modify and return it, in whatever way you wish.

An example Basket class implementing this idea is shown below.


All versions of laravel-extendable-basket with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
laravel/framework Version ^5.5||^6.0||^7.0||^8.0||^9.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 divineomega/laravel-extendable-basket contains the following files

Loading the files please wait ....