a4anthony/cartavel

E-commerce cart system

v1.1.1 2021-01-16 19:40 UTC

This package is auto-updated.

Last update: 2024-11-17 04:01:49 UTC


README

Total Downloads Latest Stable Version License

Prerequisite

To use this package, migration files for users and items/inventory/products table must have been set up.

Installation Steps

After creating your new Laravel application you can include the cartavel package with the following command:

composer require a4anthony/cartavel

Laravel ^5.5 uses Package Auto-Discovery, so it doesn't require you to manually add the ServiceProvider/Facade.

After updating composer, add the ServiceProvider to the providers array in config > app.php

A4anthony\Cartavel\CartavelServiceProvider::class

Optionally you can use the Facade for shorter code. Add this to your facades in the aliases array in config > app.php:

"Cartavel" => \A4anthony\Cartavel\Facades\Cartavel::class

To configure this package to suit your project, publish the cartavel config file

 php artisan vendor:publish --tag=config

Go to config > cartavel.php and adjust the settings to suit your project

<?php

return [
    /*
    |--------------------------------------------------------------------------
    | Users Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the users table name.
    |
    */

    'users_table_name' => 'users',

    /*
    |--------------------------------------------------------------------------
    | User Table Unique Column
    |--------------------------------------------------------------------------
    |
    | Here you can specify the unique column to be used from your users table
    |
    */

    'users_table_unique_column' => 'id',

    /*
    |--------------------------------------------------------------------------
    | Cart Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the cart table name.
    |
    */

    'cart_table_name' => 'carts',

    /*
    |--------------------------------------------------------------------------
    | Items/Products Table Name
    |--------------------------------------------------------------------------
    |
    | Here you can specify the table name for your items/products
    |
    */

    'items_table_name' => 'products',

    /*
    |--------------------------------------------------------------------------
    | Items/Products Table Name Unique Column
    |--------------------------------------------------------------------------
    |
    | Here you can specify the unique column to be used from your items/products table
    |
    */

    'items_table_unique_column' => 'id',
];

Next make sure to create a new database and add your database credentials to your .env file:

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

Run migrations

php artisan migrate

To seed the cart with dummy data, it will require that you first seed your users and items/inventory/products table first and the run

php artisan cartavel:seed

To use this package, import the cartavel package

use A4anthony\Cartavel\Facades\Cartavel;

List of all available methods

Cartavel::get($userId, true); //gets users cart items

Cartavel::add($userId, $itemId, $quantity); //adds item to user's cart

Cartavel::update($userId, $itemId, $quantity); //updates quantity o item in user's cart

Cartavel::delete($userId, $itemId); //deletes item from user's cart

Cartavel::clear($userId); //clears user's cart

ENJOY!!!

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

MIT