Giter VIP home page Giter VIP logo

laracart's Introduction

LaraCart - Laravel Shopping Cart Package (http://laracart.lukepolo.com)

Build Status Latest Stable Version Test Coverage Total Downloads License

Features

  • Coupons
  • Session Based System
  • Cross Device Support
  • Multiple cart instances
  • Fees such as a delivery fee
  • Taxation on a the item level
  • Prices display currency and locale
  • Endless item chaining for complex systems
  • Totals of all items within the item chains
  • Item Model Relation at a global and item level
  • Quickly insert items with your own item models

Laravel compatibility

Laravel laracart
5.1 | 5.2 | 5.3 1.1 | 1.2
5.4+ 1.*

Installation

Install the package through Composer. Edit your project's composer.json file by adding:

{
    "require": {
        ........,
        "lukepolo/laracart": "1.11.*"
    }
}

If using 5.4 you will need to include the service providers / facade in app/config/app.php:

	LukePOLO\LaraCart\LaraCartServiceProvider::class,

Include the Facade :

	'LaraCart' => LukePOLO\LaraCart\Facades\LaraCart::class,

Copy over the configuration file by running the command:

    php artisan vendor:publish --provider='LukePOLO\LaraCart\LaraCartServiceProvider'

Documentation

http://laracart.lukepolo.com

To Contribute to documentation use this repo :

https://github.com/lukepolo/laracart-docs

License

MIT

laracart's People

Contributors

aditya-cherukuri avatar ajmariduena avatar basepack avatar bmartus avatar cannonb4ll avatar daniel-zahariev avatar dennisoderwald avatar dontfreakout avatar dsfser avatar fraterblack avatar freekmurze avatar furkanyesil avatar it-can avatar jmarcher avatar juniore avatar laravel-shift avatar lukepolo avatar mhamlet avatar mikeaag avatar paradoxnl avatar roywcm avatar scrutinizer-auto-fixer avatar stylecibot avatar stylejs-bot avatar tyloo avatar wit3 avatar yajra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laracart's Issues

Updating Hash on Item Updates - Price / Qty / Attributes

There are certain attributes we do not want the user to be able to touch.

  • id
  • price
  • qty
  • name

Can influence the hash of an item causing issues if you wish to update qty's if they are the exactly same object .

The plan if an object detects change we will rehash it.

Also will make sure we validate qty and price when updating.

Discount per item

Could you create function discount per item ? discount by cash many qty many discount, calculate at total per item and sum at total

[Question] Product Weight?

Any thoughts on tracking the weight of each item in the cart? At some point during checkout, shipping rates based on product weight and dimensions will need to be calculated.

weight (float)
length (float)
width (float)
height (float)
weight_uom (predefined set of UOMs?)
dimension_uom (predefined set of UOMs?)

How to set the price with the tax already included (question)

Hello,
I would like to bind the price of the item to the price of my model with the tax already included.
I have been able to bind bot price and tax ok, but the total price is the base price with the tax on top pf that.
And what I need is the price of my model to be calculated as the total price with the vat already added.

Thanks!

How to access itemHash?

Hi Lukepolo,

we want to delete an item and check first if we have it. Therefor the code:

$matches = \LaraCart::find(['id' => $item_id, 'name' => $name]);

// if we found the item
if(count($matches) > 0){
    // remove item and return current cart
    \LaraCart::removeItem($matches->getHash());
    return 'success';
}

This won't work because there is no such function on the array. How to I get the itemHash in this case? Would you suggest another approach?

Thank you.

adding products bug

Hey there,

whenever i add a product it works for the first 3 times then the item hash changes.

after 3 times the print_r($this->getItem($itemHash)); does not return a value.

it can not find the item anymore (but still excists) and then adds a new row.

but after 3 times than he removes the second row (first row still excists) and than creates again another row...

very strage bug.

itemModel Bind issues.

In the last update 1.1.20 when using the model binding, the model wasnt loading in the constructor.
The reason was in LaraCart.php line 219,

I changed it to
$itemModel = $itemModel->with($this->itemModelRelations)->find($itemID);

and then line 238 taxable is expecting bool but Mysql wont return bool so I changed it to
$taxable = $itemModel[$bindings[\LukePOLO\LaraCart\CartItem::ITEM_TAXABLE]]?true:false;

Migration published && migrating error

I was kind of suprised I got a migration from this package, then I realized it was actually a very good idea to save the cart to the user, I was bound to use it but I ran into some weird errors.

  • Is there a reason you are giving the migration the year 2000 so it comes first in line? The default laravel user migration is from 2014-10-12 so if you try to add columns to that table, errors occur:

    Nothing to rollback.
    [Illuminate\Database\QueryException]
    SQLSTATE[42S02]: Base table or view not found: 1146 Table 'voormeubels.users' doesn't exist (SQL: alter table users add cart_session_id varchar(255) not null)
    [PDOException]
    SQLSTATE[42S02]: Base table or view not found: 1146 Table 'voormeubels.users' doesn't exist

  • Each time we do php artisan vendor:publish --provider='LukePOLO\LaraCart\LaraCartServiceProvider' it would publish/overwrite the migration, which is kinda weird.

Is it OK if I make a PR for this?

Coupons not clear how to use

It might be me, but im unsure how to use this exactly.

$coupon = new \LukePOLO\LaraCart\Coupons\Fixed($coupon->CouponCode, $coupon->CouponValue, [
    'description' => $coupon->Description
]);

What do I enter @ $coupon->couponValue? Is this a percentage, a amount of the cart? I dont get it.

Update item not working

Hi Lukepolo,

according to your documentation this should work:

    $matches = \LaraCart::find(['id' => 123]);
    foreach($matches as $item){
        \LaraCart::updateItem($item->getHash(), 'title', 'asdd23');
        // $item->title= 'asd';
    }

When I do a print_r of \Laracart::getItems() right after that I get the right result. But that just in the same process. When I do the same afterwards with a different request, I get the old result. Also tried with $item->title with the same result.

Using 1.1.10 with standard settings. Is there any command I am missing to persist the update?
Thank you.

Freeshipping Coupon

Additional coupon to offer free shipping for cart...not sure how this would integrate within context of how coupons are implemented currently, but get this from clients all the time.

InvalidTaxableValue in CartOptionsMagicMethodsTrait.php line 61:

Im not sure if this has anything to do with your latest release, but its currently breaking the complete package on version 1.1.18

Error that I am getting when trying to add a product to the cart (default code from docs generates the same error):

InvalidTaxableValue in CartOptionsMagicMethodsTrait.php line 61:
The tax must be a float less than 1

Middleware can't get cart count

Trying to implement a middleware that redirects to a controller/action based on cart qty. For the handle method in the middleware, it seems that I am always getting a 0 count even with items in the cart. Any idea why this would be?

`public function handle($request, Closure $next)
{
    if (LaraCart::count($withItemQty = false) == 0) {
        return redirect()->action('HomeController@index');
    }

    return $next($request);
}`

...this redirect is always triggering, regardless of actual cart qty

subTotal ability to manage formatMoney on your own

Hello,

I've noticed that whenever you call Cart::subTotal(); it would output like 'Eu 5,00'

Is it possible to disable this? I want to have control of this myself and not have the plugin do it for me. I do not need 'Eu' in front of it.

Relations on Add Item

Would be really cool to have sub relations so you can add items even quicker , would be really robust.

Does cart have option to get the Total price without tax?

as of now the plugin asumes that the product price is without tax and adds the default tax to the item.

any way to turn this into total = total with tax?

so:

product: 100 euro
tax percent: 21%
product ex tax: 79 euro
taxes: 21 euro
cart total: 100 euro

Add item using model

Would be cool if you could add products to the Cart based on an id/sku found in the item_model. This way, instead of passing a bunch of params, an item can be added with a single param, eg.

LaraCart::add('my-item-sku');

If the item_model has cols assigned with appropriate names pertaining to the cart params, then values are inserted from the found item_model.

Maybe this is possible already? I am just getting started with this, thanks for your efforts!

Dont allow taxable to accept non-integers

So it's more a question than a problem, I think.

Lets say that I have an item with a price of 10.000 and I want to apply a 20% tax on it.

If I leave the tax on settings to null so it applies the tax of each item.

//laracart.php
'tax' => null,
\LukePOLO\LaraCart\CartItem::ITEM_TAXABLE => 'tax',

(this is a protected variable inside the model with a fixed value, 0.2)

The result is:

subTotal: £10,000.00
totalDiscount: £0.00
taxTotal: £0.00
total: £10,000.00

    +taxable: 0.2
    +lineItem: false
    +discount: 0
    +subItems: []
    +couponInfo: []
    +internationalFormat: null
    +options: array:5 [▼
      "id" => 14704
      "qty" => 1
      "name" => null
      "price" => 10000.0
      "tax" => null
    ]

So as you can see the taxable has a value but it's not applying it, and aparently it does not apply the item value to it.

So let's try it the other way round. General tax and skip the item related.

'tax' => 0.2,
\LukePOLO\LaraCart\CartItem::ITEM_TAXABLE => 'null',

The result is:

subTotal: £10,000.00
totalDiscount: £0.00
taxTotal: £0.00
total: £10,000.00

 +taxable: null
    +lineItem: false
    +discount: 0
    +subItems: []
    +couponInfo: []
    +internationalFormat: null
    +options: array:5 [▼
      "id" => 14704
      "qty" => 1
      "name" => null
      "price" => 10000.0
      "tax" => 0.2
    ]
  }

Now it seems like the item has the tax but again it's not apllyint it.

Applying it to both:

'tax' => 0.2,
\LukePOLO\LaraCart\CartItem::ITEM_TAXABLE => 'tax',
subTotal: £10,000.00
totalDiscount: £0.00
taxTotal: £2,000.00
total: £12,000.00

    +taxable: 0.2
    +lineItem: false
    +discount: 0
    +subItems: []
    +couponInfo: []
    +internationalFormat: null
    +options: array:5 [▼
      "id" => 14704
      "qty" => 1
      "name" => null
      "price" => 10000.0
      "tax" => 0.2
    ]
  }

So if we apply the setting in both sides it does work. Is that the intended way to work? It does seems wrong to me. :|

Destroy / empty cart when cross browser is enabled

Executing any of the following commands do not clear my cart.
$cart = LaraCart::get();
$cart->emptyCart();
$cart->destroyCart();
LaraCart::emptyCart();
LaraCart::destroyCart();

If I delete the files in the sessions folder obv. I get a clean cart. Am I missing any instruction? Or doing something wrong?

How to retrieve session cart?

So my question is how do you retrieve the cart that is in session for the current user?

If i do
$tmp = Model::find($id); LaraCart::add($tmp); dd(LaraCart::getItems());

I get the items in the cart without a problem. But if I try to get dd(LaraCart::getItems()); from enywherelse in my app it does not return anything.

Update event fire to laravel 5.2

Laravel 5.2 fire event

Event::fire(new PodcastWasPurchased($podcast));

in previous versions of laravel, the events listeners were defined in this way

protected $listen = [
    'event.name' => [
        'EventListener',
    ],
];

Now in 5.2 :

protected $listen = [
    'App\Events\UserSignup' => [
        'App\Handlers\Events\EmailTheAccountCreatorConfirmationLink',
        'App\Handlers\Events\NotifyTheAdminThatNewAccountHasBeenCreated',
    ],
];

Please update the event firing

Adding a model as option

Hi,

I would like to add a complete model record from my database, as following:

Cart::add(2, 'Product', 1, 20.00, [
   'model' => $product
]);

Getting an error like this:

 Exception in LaraCartServiceProvider.php line 48:
 Failed calling App\Models\Auction::jsonSerialize()

Is the Sesssion Type Database?

I see your adding a cart_session_id in the users table,
is there an option to use other session driver?
if none , is it possible to use the sessions table and add the column there...
looking for ur feedback thanks

How to get itemHash?

Whenever I do like this:

$item = LaraCart::add(1, 'Burger', 5, 2.00, [
    // Notice this is an array of arrays,
    // this allows us to further expand the cart functions to the options
    [
        'Description' => 'Bacon',
        'Price' => 1.00
    ]
]);

And I dump the $item, I see a itemHash, but how do I get this hash? $item->itemHash; returns null.

I would like to add an item to my cart and afterwards add a option to this item if a certain condition is met.

Middleware issue continues...

Hmmm....still not getting correct result. I'm trying this:

`public function handle($request, Closure $next)
{
    LaraCart::get();

    if (LaraCart::count($withItemQty = false) == 0) {
        return redirect()->action('HomeController@index');
    }

    return $next($request);
}`

Checking if item exists in cart

Hi,

Is there a way to check wether an item has already been added to the cart, or exists?

For example, if I go:

Cart::add(15, 'Product', 1, 20.00 [
  'details' => 'Test'
]);

And re-execute this, it would just +1 the quantity, but I need to check wether the item was already added to the cart (so I can prevent it beeing added again)

Something like:

Cart::hasItem(15); (15 == the product ID or something custom sortaspeak)

Which would return true or false

getPrice() vs getSubtotal()

Hey Luke, starting to use this on a project. I had a question and wasn't sure the best place to ask, let me know if you'd prefer these elsewhere.

Should getPrice() be the line item price and getSubtotal() be price*qty on the CartItem class? Or am I missing how I'd get the unit price to display somewhere (besides just $line->price, which isn't formatted).

Adding sub items qty's increase the wrong item

add x1 (shows qty_x = 1)
add x1 with sub y1 (shows qty_xy = 1)
add x1 with sub y1 again and all of a sudden qty_x = 2
qty_xy should = 2

The solution would be to change the qty of x1. And re-add x2 as a new item with the sub item (which is no problem). The problem is x2 is no longer x2. For instance

    $x1 = $this->addItem();
    // $x2 is really just $x1 now since we increased the qty to 2
    $x2 = $this->addItem();
    // $x2 is now with the sub item
    $x2->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);
    // and $x2 should be its own item but its attached to x1

The TEST :

public function testSubItemQtys()
{
    $item_1 = $this->addItem();

    $item_2 = $this->addItem();

    $subItem = $item_2->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);

    $this->assertEquals(1, $item_1->qty);
    $this->assertEquals(1, $item_2->qty);

    $item_3 = $this->addItem();

    $subItem = $item_3->addSubItem([
        'size' => 'XXL',
        'price' => 2.50
    ]);

    $this->assertEquals(1, $item_2->qty);
    $this->assertEquals(2, $item_2->qty);
}

This test fails because of these issues.

Model related

First of all great job with this library looks brilliant.

So i'm having problems relating the model with the items for the cart.

//Config
'item_model' => \App\Models\Model::class,
'item_model_bindings' => [
\LukePOLO\LaraCart\CartItem::ITEM_ID => 'stock_vendor_number',
\LukePOLO\LaraCart\CartItem::ITEM_PRICE => 'price_pc',
\LukePOLO\LaraCart\CartItem::ITEM_OPTIONS => []
],

//test controller
$item = LaraCart::add($diamond_id);
dd($item);

//Output
CartItem {#311
#itemHash: "982822b0db28724a0911f76f96ddf53f"
#itemModel: "App\Models\Model"
#itemModelRelations: []
+locale: null
+taxable: true
+lineItem: false
+discount: 0
+subItems: []
+couponInfo: []
+internationalFormat: null
+options: array:5 [▼
"id" => "14297"
"qty" => 1
"name" => null
"price" => 0.0
"tax" => null
]
}

I would expect the price to be the same as the model has. Am I missing something?

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.