Giter Site home page Giter Site logo

mycart's Introduction

MyCart for Laravel

An open source, simple in syntax, and ready to use package for Shopping Carts managing with Sessions from Backend, with Laravel.

Requirements

  • Laravel 8 or above

Installation

composer require sebacarrasco93/mycart

Usage

Adding item(s):

$itemOne = [
    'uuid' => '111AAA',
    'name' => "Lemon Waffle by SoloWaffles",
    'price' => '8.99'
];
$itemTwo = [
    'uuid' => '222BBB',
    'name' => "Mixed Waffle by SoloWaffles",
    'price' => '9.95'
];

MyCart::add($itemOne);
MyCart::add($itemTwo);

Getting item(s):

return MyCart::get(); // returns an array [$itemOne, $itemTwo]

Counting item(s):

return MyCart::count(); // returns 2

Calculating total:

return MyCart::total(); // returns 18.94

Finding by UUID:

return MyCart::findByUuid('222BBB'); // returns $itemOne

Example

You can find a Laravel implementation here

Default configuration

MyCart uses 3 names:

Name Default value What does it
SESSION_NAME mycart Name of the mycart's session
ITEMS_NAME items Name of the key's session
PRICE_NAME price Name of an item's price

Custom configuration

Depending on what you need, you can prefer one or another solution. However, there are two ways to do this:

By setting .env keys

You need to copy and change these values:

MYCART_SESSION_NAME=your_custom_session_name
MYCART_ITEMS_NAME=your_custom_items_name
MYCART_PRICE_NAME=your_custom_price_field_name

By publishing a config file

Simply run:

php artisan vendor:publish --provider="SebaCarrasco93\MyCart\MyCartServiceProvider"

Laravel will publish a configuration file in config/mycart.php, so you can change the values by opening it.

'session_name' => env('MYCART_SESSION_NAME', 'your_custom_session_name'),

'items_name' => env('MYCART_ITEMS_NAME', 'your_custom_items_name'),

'price_name' => env('MYCART_PRICE_NAME', 'your_custom_price_field_name'),

Changing My Cart's lifetime

Since behind the scenes it works with Laravel's sessions, MyCart will work as another Laravel session.

So, for example, if you want to increase the maximum lifetime from default, 2 hours (120 minutes) to 24 hours (1440 minutes), the only thing you need to change is the SESSION_LIFETIME value in your project's .env file

Before (2 hours):

SESSION_LIFETIME=120

After (one day):

SESSION_LIFETIME=1440

Easy Peasy!

mycart's People

Contributors

sebacarrasco93 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.