Giter VIP home page Giter VIP 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

laravelshoppingcart's Issues

How to use newly created cart instance?

Hi,

I needed to create a new cart instance and retain the same one throughout the session. So I created a new service provider and added the code in the register() method. Now how do I use this cart name/ instance while adding or updating my cart contents?

Thank You!

Conditions

Hi,
Its leave the whole conditions of the cart in session? Because I set a condition and on checkout I lose the getConditions() values.

Another thing, I tried something like $condition->getValue ()-> first () without the need to use a foreach. Is there any way?

Thank you.

Type Hinting the Cart

I've tried to type hint the Cart so that I'm not doing static calls. From what I understand better for unit testing.

But the problem is that the _construct requires session, events and so on. Is there any way to do this?

I want to be able to do something like $this->cart-clear() or $this->cart->add()

Time to live for cart.

Hello. How can I set time to live for goods in my cart.
In several hours cart becomes empty.

Unique item identifier

Have you considered to use something other then Item ID for Cart::update() and Cart::remove() functions? In cases where cart holds multiple instances of the same Item ID how do you work with items in the cart?

Simple Instance

Possible to have instance like this?

Cart::instance('shopping')->add(455, 'Sample Item', 100.99, 2, array());

Possibility to have attributes on conditions.

What are you guys thinking of adding the possibility to have attributes on conditions. I have a condition with the name 'discount'. This because I only want to have the option to have one 'discount' rule so I can update the value if they enter another promo code. But I would like to add some more information on this condition due attributes.

Add conditions to existing products in cart

Hi all,

I have a question about adding per-item conditions to already existing products in cart. I have a 'cart' page, which contains a form for coupons, which can be assigned to certain products/categories in the shop, so when the user is filling in his coupon, he might already have the product(s) on sale in the cart. Is there a way to assign a per-item condition to a certain existing product in cart.

Thank you.

Clear all conditions

Hello.

It is possible to clean the all conditions?

Because the Cart::clear() only clean the cart. Even this option is not documented in the readme.

Thank you for your great work.

Issue with add more than three items

Good day. I have a problem with the library and I would like to fix it because I am comfortable with its features, the problem is when I want to add more than 3 items to cart this not stored. Here I leave a link that leads to a picture of the implementation of the method add () http://prntscr.com/b6gqg2

Total Number of Items

This is probably a function you want to add. Most carts these days display the total number of items in the cart. I see no function for this. Not hard for me to write, but thought I'd mention it.

5.2 support

Can you please add laravel 5.2 support? Now getting these errors:

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Installation request for laravel/framework 5.2.* -> satisfiable by laravel/framework[v5.2.0].
    - darryldecode/cart dev-master requires illuminate/validation 5.0.x|5.1.x -> satisfiable by illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.6, v5.1.8].
    - don't install illuminate/validation v5.0.0|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.22|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.25|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.26|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.28|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.33|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.0.4|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.1|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.13|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.16|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.2|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.20|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.22|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.25|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.6|don't install laravel/framework v5.2.0
    - don't install illuminate/validation v5.1.8|don't install laravel/framework v5.2.0
    - Installation request for darryldecode/cart dev-master -> satisfiable by darryldecode/cart[dev-master].

#46

How to access parsedRawValue?

In a condition I have the calculated value from that condition.

object(Darryldecode\Cart\CartCondition)[293]
  private 'args' => 
    array (size=5)
      'name' => string 'Coupon' (length=22)
      'type' => string 'discount' (length=8)
      'target' => string 'subtotal' (length=8)
      'value' => string '-10%' (length=4)
      'attributes' => 
        array (size=3)
          'title' => string 'Lorem ipsum dolor' (length=15)
          'description' => string '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Plane idem, inquit, et maxima quidem, qua fieri nulla maior potest. Dempta enim aeternitate nihilo beatior Iuppiter quam Epicurus; Ubi ut eam caperet aut quando? Hoc est non dividere, sed frangere. Duo Reges: constructio interrete. Eiuro, inquit adridens, iniquum, hac quidem de re;</p>

' (length=348)
          'valid until' => string '2016-06-15' (length=10)
  private 'parsedRawValue' => float 1.045

How can I use it?

Cart namespace

Hi , what namespace "use" at the top of controller for this cart module?

Thank you

How add one item twice with different attributes ?

Hello,
I would like add the same item, but with different attributes.
e.g.:
item in cart has attribute = ['color' => 'red'],
and I would like to add the same item with attribute = ['color' => 'blue'].

I except two items with different arguments in cart, but old item`s attributes are overwritten with new attributes and quantity is updated to 2.
I didn't find this in documentation, maybe I missed it.
Is there any way how to achieve this, please ?

...Thank You.

Problem getTotal() method

Problem with getTotal method, if there are no conditions the total returns 0, I think convenient to put the condition: if $conditions->count() is false $newTotal = $subTotal

Database support.

Do you mind adding database support beside session only?
we've encountered several session problems because of ajax calls adding and removing from the cart.

we'd like to have a backup to the database without having to do it manually on each call.
(preferable to do both sides, sessions and db, or make it optional)

Great work on the project though, we've been using it for quiet a while now!

kind regards,
Jurien Hamaker.

The quantity is increasing on page refresh

Hi,

After I add a product and refresh the page, the quantity is increasing and is affecting the total price. It affects the quantity of only the last added product and not the ones before that.
Is this something that can be rectified?

Quantity as a decimal

I'm trying to adapt this very nice cart you've created on a project where the quantities are services based in time broken down by half hour. So a quantity could be 1.5 (1 and 1/2 hours). When I add 1.5 as a quantity it rounds down. I thought perhaps if I changed the validation but doing so didn't seem to have any effect.

Any tips on how I might make this adjustment?

Weight, how can deal with this?

Hey,

First all, sorry about my english.
Make any sense if we can allow to put another argument on Cart::add for weight?

/**
     * add item to the cart, it can be an array or multi dimensional array
     *
     * @param string|array $id
     * @param string $name
     * @param float $price
     * @param int $quantity
     * @param array $attributes
     * @param CartCondition|array $conditions
     * @return $this
     * @throws InvalidItemException
     */
    public function add($id, $name = null, $price = null, $quantity = null, $attributes = array(), $conditions = array(), $weight = 0)
    {
        // if the first argument is an array,
        // we will need to call add again
        if( is_array($id) )
        {
            // the first argument is an array, now we will need to check if it is a multi dimensional
            // array, if so, we will iterate through each item and call add again
            if( Helpers::isMultiArray($id) )
            {
                foreach($id as $item)
                {
                    $this->add(
                        $item['id'],
                        $item['name'],
                        $item['price'],
                        $item['quantity'],
                        Helpers::issetAndHasValueOrAssignDefault($item['attributes'], array()),
                        Helpers::issetAndHasValueOrAssignDefault($item['conditions'], array()),
                        Helpers::issetAndHasValueOrAssignDefault($item['weight'], 0)
                    );
                }
            }
            else
            {

                $this->add(
                    $id['id'],
                    $id['name'],
                    $id['price'],
                    $id['quantity'],
                    Helpers::issetAndHasValueOrAssignDefault($id['attributes'], array()),
                    Helpers::issetAndHasValueOrAssignDefault($id['conditions'], array()),
                    Helpers::issetAndHasValueOrAssignDefault($item['weight'], 0)
                );
            }

            return $this;
        }

        // validate data
        $item = $this->validate(array(
            'id' => $id,
            'name' => $name,
            'price' => Helpers::normalizePrice($price),
            'quantity' => $quantity,
            'attributes' => new ItemAttributeCollection($attributes),
            'conditions' => $conditions,
            'weight' => $weight
        ));

        // get the cart
        $cart = $this->getContent();

        // if the item is already in the cart we will just update it
        if( $cart->has($id) )
        {
            $this->events->fire($this->getInstanceName().'.updating', array($item, $this));

            $this->update($id, $item);

            $this->events->fire($this->getInstanceName().'.updated', array($item, $this));
        }
        else
        {
            $this->events->fire($this->getInstanceName().'.adding', array($item, $this));

            $this->addRow($id, $item);

            $this->events->fire($this->getInstanceName().'.added', array($item, $this));
        }

        return $this;
    }

Next we can add"tax" by weight? Or get total weight? Or even calculating shipping cost?

What you think about this?

[Laravel 5.2] Class 'Cart' not found

Hello,

Code in config/app.php

`'providers' => [

    Darryldecode\Cart\CartServiceProvider::class,        

],

'aliases' => [

    'Cart'      => Darryldecode\Cart\Facades\CartFacade::class,

],`

In Controller

tried Cart::add() got error Class 'Cart' not found

tried \Cart:add() got the same error

In header I used both

use Cart;

and use Darryldecode\Cart\Facades\CartFacade; with this I got another error:

Class 'App\Http\Controllers\Cart' not found

tried 'use Darryldecode\Cart\Cart;' as well. Same error

Cart total or discount total display incorrect

cart conditions
Hi
I have configure cart and applied few condition for testing purpose but cart total or discount total is not display correctly can you please help me below is my code?

$condition1 = new \Darryldecode\Cart\CartCondition(array(
'name' => 'VAT',
'type' => 'tax',
'target' => 'subtotal',
'value' => '10%',
));

$itemCondition3 = new \Darryldecode\Cart\CartCondition(array(
'name' => 'Discount',
'type' => 'misc',
'target' => 'subtotal',
'value' => '-5%',
));

Cart::condition([$condition1,$itemCondition3]);

        <table class="table">
            <tbody>
                <tr>
                    <td>Order subtotal</td>
                    <th align="right">${{number_format(Cart::getSubTotal(),2)}}</th>
                </tr>
                @foreach(Cart::getConditions() as $condition)
                    <tr>
                        <td>{{$condition->getName()}} ({{$condition->getValue()}})</td>
                        <th align="right">${{number_format($condition->getCalculatedValue(Cart::getSubTotal()),2)}}</th>
                    </tr>                       
                @endforeach
                <tr class="total">
                    <td>Total</td>
                    <th align="right">${{number_format(Cart::getTotal(),2)}}</th>
                </tr>
            </tbody>
        </table>

Item price lower than zero?

Hi,

I've noticed that if you add an item with a condition which ends up substracting more than the item's price, the item price ends up negative (e.g. price 15, value -20 results with -5 product price). Is that something that should be allowed? In my case, I would never want a negative product price. Please let me know and I can make a PR.

Test code:

$product = [
    'id' => 123,
    'name' => 'Sample Item 1',
    'price' => 15,
    'quantity' => 1,
    'conditions' => new \Darryldecode\Cart\CartCondition([
        'name' => 'Substract 20',
        'type' => 'shipping',
        'target' => 'item',
        'value' => '-20',
    ]),
];

\Cart::add($product);

dd(\Cart::getTotal()); // -5

Cart::getTotal() in view

When I want to echo out the total value in the view, I get the following error:

ErrorException
Trying to get property of non-object.. {view file name}
/­vendor/­darryldecode/­cart/­src/­Darryldecode/­Cart/­Cart.php510
Line: $originalPrice = $item->price;

Of course I have some items in the cart, and all items have price set.

CartCollection {#401 ▼
  #items: array:2 [▼
    21 => array:6 [▼
      "quantity" => 6
      "id" => "21"
      "name" => "******************"
      "price" => 7800.0
      "attributes" => ItemAttributeCollection {#341 ▶}
      "conditions" => []
    ]
    31 => array:6 [▼
      "quantity" => 6
      "id" => "31"
      "name" => "**************"
      "price" => 1.0
      "attributes" => ItemAttributeCollection {#342 ▶}
      "conditions" => []
    ]
  ]
}

EDIT: its not always, when I clear the cart, no error happens. It's something with adding to the cart...

EDIT 2: some way one of my item differs from others:

CartCollection {#386 ▼
  #items: array:2 [▼
    21 => ItemCollection {#341 ▶}
    31 => array:6 [▶]
  ]
}

this is why error happens.. any idea?

EDIT 3:
When I constantly add, remove items to the cart, sometimes one of the items randomly will be saved as array, and not as ItemCollection. Of course I use the same code all the way..

CartCollection {#435 ▼
  #items: array:4 [▼
    21 => ItemCollection {#341 ▶}
    27 => ItemCollection {#343 ▶}
    22 => ItemCollection {#345 ▶}
    20 => array:6 [▶]
  ]
}

Sum value of individual item (quantity * price).

One idea:

Would put a field with the sum total of each item (quantity * price).

Example:

Cart::get($itemId);

[id] => 23
[name] => Item Name
[price] => 5.00
[quantity] => 3
[sum] => 15.00

Thank you!

getPriceSumWithConditions with specific types of conditions

I have an item in my cart with two conditions. One of them is shipping, the other one is Vat.

   $shippingCondition = new \Darryldecode\Cart\CartCondition(array(
      'name'       => 'shipping costs',
      'type'       => 'shipping',
      'target'     => 'item',
      'value'      => '3.95',
    ]
    ));
    $vatCondition      = new \Darryldecode\Cart\CartCondition(array(
       'name'       => 'vat 6%',
       'type'       => 'tax',
       'target'     => 'item',
       'value'      => '6%',
     ));

Items can be 6% or 21% vat in the Netherlands.

What I like to have is the possiblity to use specific conditions when showing the item in my cart:

   $item->getPriceSumWithConditions($vatCondition);

This way I can show the price with VAT per Item on a line in my cart and use the shipping at the end with the Cart totals summary.

And while mentioning this, it would be nice to have the possibility to sum up the totals per item condition too with a specific function. This way I can show the sum of the 6% en 21% Vat items separately, as well as the total shipping costs, which can vary per item.

Updating laravel to 5.3

Hi,
I'm using darryldecode/cart in my code, I'm using currently laravel 5.2, and i want to upgrade to 5.3.
when i run composer update, i get the following error:
Problem 1
- darryldecode/cart dev-master requires illuminate/validation 5.0.x|5.1.x|5.2.x -> satisfiable by laravel/framework[v5.2.39], illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.33, v5.0.4, v5.1.1, v5.1.13, v5.1.16, v5.1.2, v5.1.20, v5.1.22, v5.1.25, v5.1.28, v5.1.30, v5.1.31, v5.1.41, v5.1.6, v5.1.8, v5.2.0, v5.2.19, v5.2.21, v5.2.24, v5.2.25, v5.2.26, v5.2.27, v5.2.28, v5.2.31, v5.2.32, v5.2.37, v5.2.43, v5.2.6, v5.2.7].

Is the cart compatible with laravel 5.3 ?
Thanks!

Order of the items in the cart

When I am updating the cart by adding or subtracting quantities (and loading the page with the cart again) the order of the items is changing. Is there a way to set the order? By example alphabetically on the items names? Or simply by the order the items are originally added to the cart?

Laravel 5.1

Will you be updating the cart for Laravel 5.1? I can't update to 5.1 until the cart will accept it.

Problem 1
- Installation request for darryldecode/cart dev-master -> satisfiable by darryldecode/cart[dev-master].
- Conclusion: remove laravel/framework v5.1.1
- Conclusion: don't install laravel/framework v5.1.1
- darryldecode/cart dev-master requires illuminate/validation 5.0.@dev -> satisfiable by illuminate/validation[v5.0.0, v5.0.22, v5.0.25, v5.0.26, v5.0.28, v5.0.4].
- don't install illuminate/validation v5.0.0|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.22|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.25|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.26|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.28|don't install laravel/framework v5.1.0
- don't install illuminate/validation v5.0.4|don't install laravel/framework v5.1.0
- Installation request for laravel/framework 5.1.
-> satisfiable by laravel/framework[v5.1.0, v5.1.1].

Rename clearCartConditions() to clearConditions()

Because the class is already called "Cart", it's superfluous to have "cart" in method names.

// Instead of:
Cart::clearCartConditions();

// It should be:
Cart::clearConditions();

This is a consistency issue which bugs me personally. I keep forgetting to add Cart whenever I want to call that specific method. If you want to keep "cart" in the method name, at least make it consistent by changing Cart::clear() to Cart::clearCart().

But again, I recommend just renaming Cart::clearCartConditions() to Cart::clearConditions(). Cart::clearCartConditions() should be deprecated in the next version or just removed.

->totalquantity() in addition of count()

Of course not so difficult to calculate myself but it would be nice to have a function to get the total quantity of all items in the cart. Now I have a quantity of 14 and stil just 1 when I use count().

Cart does not return items in 5.2.*

I have installed package successfully ,

Cart::add(455, 'Sample Item', 100.99, 2, array());

Works , but get empty response when trying to retrieve the cart :

return Cart::getContent() ;

Cart session empty

Hi,

I'm having a problem.

In one route i add an item tot the cart with "Cart::add(455, 'Sample Item', 100.99, 2, array());" and in another route i get the items with "Cart::getContent()".

The problem is that Cart::getContent() always return empty.

I checked the session with Session::get() (and the session id) and the items appear but Cart::getContent always return an empty array.

Can you help me please?

Thanks.

Ability to find and remove conditions by type

I think it would be nice to be able to find and remove conditions by the type they are e.g.

$condition = new CartCondition([
    'name' => 'Discount 10%',
    'type' => 'promo',
    'target' => 'subtotal',
    'value' => '-10%',
]);


Cart::findCartConditionType('promo');
Cart::removeCartConditionType('promo');

Ability to fetch the Monetary Value from Cart Condition

Could you add the ability to fetch the actual value from the condition rather than what you supply it:

for example:

Name Value
cart sub total £10
vat @ 20% £2
total £12

Currently when you do $condition->getValue() it only returns the value you supplied in the condition.

// add condition single condition
$condition = new CartCondition([
    'name'      => 'VAT 20%',
    'type'      => 'tax',
    'target'    => 'total',
    'value'     => '20%',
]);

What we really need is another method like $condition->getCalculateValue() will return the value that targets the sub total, or whatever value you have applied the condition to.

Cart::update()

Hi ,

Cart::update(456, array(
'quantity' => array(
'relative' => false,
'value' => 5
),
));

give me this :

ErrorException in Cart.php line 204:

preg_match() expects parameter 2 to be string, array given

Condition lives on after removing

When a new condition is added using the Cartcondition like below, the discount is calculated over the price, which is good.

$discountCondition = new \Darryldecode\Cart\CartCondition([
        'name' => 'discount-code',
        'type' => 'discount-code',
        'target' => 'subtotal',
        'value' => $discountValue, // (-30%)
        'attributes' => [
            'code' => $code
        ]
]);

\Cart::condition($discountCondition);

But when a customer removes the discount code, and I remove the condition (\Cart::removeCartCondition('discount-code');), the condition is removed after the code is executed, but when I reload the page, the condition is still applied. The condition is also shown in the \Cart::getConditions(); array.

Could you please take a look at it :)

Updating quantity issue

Hello,
first of all, thank you for the nice implementation.

I was quite surprised that the cart quantity update method actually adds quantity.
Is there a way to easy update the quantity with a certain value, e.g. if the quantity is 5 to make it 7 right away, and not 5+7=12?

Thanks

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.