Giter Club home page Giter Club logo

laravelshoppingcart's People

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  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

laravelshoppingcart's Issues

search method expects exact order for correct md5 string

while adding item to cart if i added like

        $where = array (
            'id'   => $product['product_id'],
            'options' => array (
                'type'=>'physical',   //  at index 0
                'language'=>$product['language'], // at index 1
                'image'=>$product['image'], // at index 2
                'name'=>$product['product_name'], // at index 3
            )

        );

then while searching i have to repeat same order cause

in Cart.php at line :234 serialize would create a different string and hence unmatched md5 string ,
i guess we have to modify that logic of generateRowId()..

may be create options array before feeding to serialize..

also we need to remember that we are searching with some handful of parameters not complete set which was used while adding item to cart.

Events

It would be really awesome if the cart fired off some custom events upon certain actions. Things like:

Event::fire('cart.add', $item)
Event::fire('cart.addBatch', $items)
Event::fire('cart.update', $item)
Event::fire('cart.remove', $item)
Event::fire('cart.destroy')

Problem with multiple instance of Cart

Hi guys,
i've a problem i these last few days. I dont know why. But when i try to use multiple instance of cart the last new goes to overwritten by first instance and i dont understand why this happened. Maybe i just add the new package with new methods ?

using search

Hi
With the search feature is it possible to search on more than one criteria in options, if so how do it?

I have set types in the options and want to return all items of a specific type.

If I need to do multiple searches how can join the results back together?

Cart::addRow bug

There is a bug, it seems, where Cart::addRow throws an exception if the 'id' argument is an integer.
Casting the int to a string solves the issue.

Running PHP 5.4.12 on Win 7, using WAMP.

ErrorException after Laravel update to 4.2

Hello,
After updating to Laravel 4.2 I got this error:

exception 'ErrorException' with message 'Declaration of Gloudemans\Shoppingcart\CartRowCollection::search() should be compatible with Illuminate\Support\Collection::search($value, $strict = false)'

update item attribute instead of only qty

instead of updating only quantity of item in cart we can make

Cart::update() 

do change attribute of item whose rowid we specify, it will make it more powerfull to update items attributes.
eg

Cart::update($rowid,'quantity',3)

Incompatible with Laravel 4.1

Needs upgrade for Laravel 4.1

Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - gloudemans/shoppingcart dev-master requires illuminate/support 4.0.x -> satisfiable by laravel/framework[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9], illuminate/support[4.0.x-dev, v4.0.0, v4.0.0-BETA2, v4.0.0-BETA3, v4.0.0-BETA4, v4.0.1, v4.0.10, v4.0.2, v4.0.3, v4.0.4, v4.0.5, v4.0.6, v4.0.7, v4.0.8, v4.0.9].

Destroy method doesn't return boolean!

Hi guys

// lets delete user cart
\Cart::destroy(); // return null,

But phpdoc says boolean..

    /**
     * Empty the cart
     *
     * @return boolean
     */
    public function destroy()
    {
        // Fire the cart.destroy event
        $this->event->fire('cart.destroy');

        $result = $this->updateCart(NULL);

        // Fire the cart.destroyed event
        $this->event->fire('cart.destroyed');

        return $result;
    }

[Feature] idea for adding cart-weight related methods etc.

Ideas for adding weight related features

  • cart item 'weight' while adding item to cart
  • Cart::weight() // total weight of cart
  • update weight of cart item

weight attribute is important for physical items in cart for calculating shipping amount etc.

should we make it optional or make it default
as not all items need weight;
as in case of digital items (track downloads) etc.

Remove returns update which returns null/void.

Remove method returns null. Quick fix should be the following:

return $this->get($rowId) == null;

Same deal with destroy method, but instead you can do the following:

return $this->count() <= 0;

Cart relation to product table

Hi,
From the id of the product in cart collection, is there any way I can do like:
foreach(Cart::content() as $item){
echo $item->product->image;
}
So I would like to link the id of the cart row to product table.

Many thanks for your help..

Regards,
Ferry

Output order

Current order is (A,B,C,D and so on) but there is no method to output cart items in order (D,C,B,A) without making a huge mess into code.
For instance - If i want to show only last 3 items into cart there is no option for that.

Best way to find if particular product is in cart

cart has these items

$cart = array(
   array(
      'id'=>1,
      'name'=>'Prod 1',
      'price'=>11,
      'qty'=>1,
      'options'=array(
         'type'=>'physical'
      ),
   array(
      'id'=>2,
      'name'=>'Prod 2',
      'price'=>22,
      'qty'=>2,
      'options'=array(
         'type'=>'digital'
      )


);

how can we find for an item using its attributes

Cart::has(array('name'=>'Prod 2','options'=>array('type' => 'digital')));  // determines if cart has item matching the mentioned parameters

i guess i should move 'type' key to level-up in array so i dont have to search it within options array, then it would be

Cart::has(array('name'=>'Prod 2','type'=>'digital'));  // determines if cart has item matching the mentioned parameters

cart only works after "main" is instantiated.

Hi ..
I have this code :
Cart::instance($instance)->associate('Product')->add(array('id' => $id, 'name' => $name, 'qty' => $qty, 'price' => $price));

if the instance is 'wishlist' the very first time it does not work.. the wishlist instance is not save. But if the instance is "main" first time and second time its "wishlist" then only the wishlist is instantiated.

How can i fix this?

Cart::associate

I'm having an issue with the Cart::associate method. With this code, I'm trying to add items to the DB. I'm not getting any errors and it doesnt store anything to the db

$item = array(
'id' => 1,
'qty' => 1,
'name' => 'htc',
'price' => 50
);

    //Add item ID to cart
    Cart::associate('cart')->add($item);

screen shot 2014-07-18 at 10 51 09 pm

payment

Hi,

Is there any payment in the Shoppingcart?

Thanks,
Jeremy

Using $this when not in object context

when using it in env where php is
php 5.3.10 as l4 req atleast 5.3.7
it must be ok to run

but it shows this error in ShoppingcartServiceProvider.php at line 17
may be its expecting a more latest php version

Only able to add 3 items to cart

Unable to add more than three items to the cart, using Laravel 4.2.6

I just tested Store() changing it to:

public function store() {

        echo 'Previous count: ' . Cart::count(false) . '<br />';
        $input = Input::all();

        $product = Product::find($input['id']);
        $quantity = $input['quantity'];

Cart::associate('Product')->add($product->id,$product->description,$quantity,$product->retail_price);
        echo 'Post count: ' . Cart::count(false) . '<br />';

        return;
    }

I destroyed the cart first then added different products 1 at a time
1st product addition produced
Previous count: 0 Post count: 1
and checked the cart, there was now 1 item in the cart
2nd product addition produced
Previous count: 1 Post count: 2
and checked the cart, there was now 2 items in the cart
3rd product addition produced
Previous count: 2 Post count: 3
and checked the cart, there was now 3 items in the cart
4th product addition produced
Previous count: 3 Post count: 4
and checked the cart, there was only 3 items in the cart (the 1st 3 I added)

I checked Cart::content() in Store() and it did indeed have 4 items in it.

checking Cart::content() in index() of /cart and it only had 3 items.

Form displaying add to cart , quantity input and hidden product id. Displayed on the product page

{{ Form::open(['url' => '/orders'], ['enctype' => 'multipart/form-data' ] ) }}
<div class="row">
    <div class="form-group">
        <p>{{ $product->code }} - {{ $product->description }} <strong>{{ money($product->retail_price) }} each</strong></p>
    </div>
</div>
<div class="row">
    <div class="form-group col-md-3 col-md-offset-2">
        {{ Form::hidden('id', $product->id) }}
        {{ Form::label('quantity', 'Quantity') }}
        {{ Form::text('quantity', Input::old('quantity'), ['placeholder' => '0', 'required' => 'required', 'class' => 'form-control input-lg'] ) }}
        <p class="text-danger">{{ $errors->first('quantity') }}</p>
    </div>
</div>
<div class="form-group">
    {{ Form::submit('Add To Cart', ['class' => 'btn btn-success btn-block'] ) }}
</div>
{{ Form::close() }}

STORE handling the above form in the orders controller

public function store() {
        $input = Input::all();
        $product = Product::find($input['id']);
        $quantity = $input['quantity'];
Cart::associate('Product')->add($product->id,$product->description,$quantity,$product->retail_price);
        return Redirect::to('cart')->with('flash_message','Successfully added to cart');
    }

INDEX handling redirect to 'cart' from STORE in the /cart controller

public function index() {
        if(!Auth::check()) {
            return Redirect::to('join?next=' . $_SERVER['REQUEST_URI']);
      }
        $content = Cart::content();
        return View::make('cart.cart')->with('content',$content);
    }

Cart contents disappearing

Hi
I've been using this package for a while now but have a problem.

I add items to my cart, I can see the items there if I dump the cart and do a couple of tests. However If I then try to retrieve the cart contents from another function the cart is empty.

Products are added to the cart from an ajax call.

try {

        Cart::instance('main')->add( 
        $product->id, 
        $product->name, 
        $people, 
        $salePerHead, 
        array( 
            'cost'=>$costValue, 
            'type'=>$product->type, 
            'mealQty'=>$mealQuantity
            ) 
        );

    } catch (Exception $e) {

        return "Error P002: Failed to Add Item";

    }

This works

Once added another jquery ajax call from the page gets the cart content to display on the page:

$cart = Cart::content(); $cartCount = Cart::count(); $cartTotal = Cart::total();

These calls don't work - all returning an empty cart. I dont empty the cart between calls.

I'm confused - I've had this working.

I've recently upgraded my project to 4.1 but convinced it was working. I've just done a composer update to make sure I have the latest build

Cart options

Hi there,

Is it possible to add prices as options?
For example:

Pizza $10.00 (default)
options:
extra cheese $1.00,

extra spicy $1.50

and then add this as a single product to the basket, so with a total product price of
12.50

Fire events after operation execution

What about fire events when operations was executed?

I propose:

cart.added
cart.batched
cart.updated
cart.removed
cart.destroyed

For example I can listen on "cart.added", retrieve the new cart row and save this information in a database record.

Extra options not being added

Extra options other than quantity, price, id, name aren't being added to the session. Just returns a zero length array.

use cart without Facade

I'm trying to use the cart class without making use of the facade. What i've done so far is the following :
A class like so :

use Gloudemans\Shoppingcart\Cart;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\Session\Session;

class LaravelShoppingCart implements CartInterface {
    protected $cart;

    public function __construct(Session $session,Event $event){
        $this->cart = new Cart($session,$event);
    }

And then in the controller

class HomeCtrl extends  \BaseController {
    protected $cart;

    function __construct(CartInterface $cart)
    {
        $this->cart = $cart;
    }

.....

    public function testCart()
    {
       $this->cart->add(array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('size' => 'large')));
        print_r($this->cart->content());
    }

but this gives the following error

Call to undefined method Symfony\Component\EventDispatcher\Event::fire() 

Any ideas? using L4.2

Shipping

How could I go about adding a shipping row to the cart? My situation is that I dont know shipping costs until the user enters in details and I calculate the weight of the shipment.

Thoughts?

Data no persisting in session

After i add product in the cart and var_dump the content of the cart everything works fine but after refreshing the page when i var_dump the it shows empty cart..

Using cart instance in Cart::search

Hi Crinsane.

Thank you for the shopping cart.
i have a question :

search(array('id' => $product->id)); ?>

Should this work or not ? is it possible to use cart instance with search? I am getting nothing with it. Please let me know if it works or any work around for this.

Thanks again,
Prajwol.

Get rowid of last added item

Hi
I'm trying to get the rowid of the last inserted item but not having much luck. I've tried checking the return value of Cart::add() but this returns a null value.

I need to use the rowid in an associated cart instance - a bit like a one to many relationship but can't see a method or way of obtaining.

I thought Cart::add() would return a row collection?

Is this intended behaviour to return null after an add?

Adding multiple items into cart

Can we add multiple items into cart

$items = array(
array(
'id' => 1,
'name' => 'Audio CD',
'qty' => 1,
'price' => 49,
'options'=>array()
),
array(
'id' => 2,
'name' => 'Video CD',
'qty' => 1,
'price' => 69,
'options'=>array()
)
);
- Cart::addItems($items);   // adding multiple items into cart  , return generated rowid if item is one or return it from Cart::add() only

maintaining a cart instance for a current user

This is a great package, thanks. I would have asked this on the L4 forum but couldn't find any mention of your package there..
It seems I can only maintain a logged-in users cart instance (by using their id) within a single script. What would be the best way to keep their cart instance current whenever they are logged-in? I have tried an event listener, but couldn't get it to work. Any ideas?
Thanks.

Methods return Null instead of Boolean

Could we have add(), addBatch(), destroy() etc return a boolean which enables us to check for success? It seems to be returning Null every time now, or am I completely missing something?

$options values that affect the price

I needed to add to the product additive with different price. I used the optional array of options (id, name, price for additive). How do I correct this when calculating the total amount?

Track abandoned cart

Using LaravelShoppingcart, what is the recommended method to track abandoned carts? Are cart instances persisted on the database with a timestamp?

[enhancement] Accept array in add() method

Is it better if the add() method could accept array, e.g.,

$data = [
    'id' => 58,
    'name' => 'Long Sleeve Shirt',
    'price' => 98.99,
    'qty' => 5,
    'options' => [
        'size' => 'M'
    ],
];

Since addbatch() is accepting array, add() should also accept array for consistency. Thought?

can i count weight?

Cart::add(array('id' => '293ad', 'name' => 'Product 1', 'qty' => 1, 'price' => 9.99, 'options' => array('weight' => 22)));

i dont wanna using foreach to do it
any good method for count the weight in options array
i have to create method myself?

Cart::associate

I'm having an issue with storing the cart items to the DB. I data dumped the cart and the object is set but when I check the DB the item is not inserted. Here is a snippet of my code:

    $item = array(
        'id' => '293ad',
        'name' => $this->input['condition'],
        'qty' => 1,
        'price' => 24
    );
    //Add item ID to cart
    Cart::associate('cart')->add($item);

    $content = Cart::content();

    dd($content);

and here is my my DB migration

   <?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCartTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('cart', function($t) {
        $t->string('id');
        $t->string('qty');
        $t->string('name');
        $t->string('price');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::drop('cart');
}

}

screen shot 2014-07-18 at 4 48 28 pm

Discounts - taxes

What is the recomended method to apply discounts or taxes to the cart? Could be per product (discount/tax) or to the entire cart (coupon maybe) or even adding extra charges (like shipping costs)

how to save cart link, reopen later

ref: https://github.com/moltin/laravel-cart

    // Identifier
    // With a requestcookie (choose for storage: cache, the session will be expired), the cart could be reloaded from a http request, example: the customer could save his cart link (email, hyperlink) and reopen this later.
    // If there is no request, the cookie will be loaded.
    'identifier' => 'cookie', //cookie, requestcookie

    //Request Cookie
    'requestid' => 'CartID', //http input request identifier, example: your customer/backoffice could reload the cart in your shop controller, /public/shop?CartID=871f0bc18ca76e68bf7c3adf8f9426ef

in case, when using Cart::content();
we can also get a session id .

  1. so can i just use that session id to save cart link ?
    like: /cart/871f0bc18ca76e68bf7c3adf8f9426ef
  2. is it safely to do it?
  3. can make a method to get the session id?
  4. how can save a array or value in that cart?

thanks

Store cart in database separate from session

Is there any way to store a user's cart in the database separately from the session? I'd like to leave my session lifetime relatively short so they don't stay logged in, but would love their cart to persist indefinitely.

Gloudemans \ Shoppingcart \ Exceptions \ ShoppingcartInvalidRowIDException

I'm getting the above message when trying to remove an item from my cart.

< a href="/cart/remove/{{ $cart_item->rowid }}">Remove

Which is wrapped in a foreach that comes from:

$carts = Cart::content();

And i'm adding content like so:

$cartContents = Cart::add(array('id' => randomNumber(), 'name' => $input['product_name'], 'qty' => 1, 'price' => $price));

But when I do Cart::remove($cart_item->rowid) i get the above error?

Any idea's?

Search doesn't work

I have a product in my cart with an ID of 10, for example, and the following returns false:

Cart::search(array('id' => 10));

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.