Giter Site home page Giter Site logo

freshbitsweb / laravel-cart-manager Goto Github PK

View Code? Open in Web Editor NEW
228.0 11.0 33.0 157 KB

Managing the cart in your Laravel/E-commerce application is a breeze

License: MIT License

PHP 100.00%
php7 laravel laravel-5-package laravel-shopping-cart cart-manager ecommerce laravel-6-package shopping-cart shipping-charges cart-data

laravel-cart-manager's Issues

Remove specific product in all users carts

Is your feature request related to a problem? Please describe.
Let's say a product is no longer available. It has to be removed from all carts immediately so that users' won't buy those items.

Describe the solution you'd like
From the documentation, I cannot find how to update all users' carts with the available methods. Does cart() method apply to all users or just the current user?

Describe alternatives you've considered
I tried fetching all carts that include the given product id. After that, I check the carts but I can't find a way to remove and update the totals etc.

configuration options

Change in configuration options

I want to apply 0% tax. I have updated in cart_manager.php at following lines

'tax_percentage' => 0,

but still it gives 6% tax

can you please tell how i can make tax 0% and shipping 0% and other configurations 0%

thanks

Merging existing cart with guest made cart

I'm looking for a way to merge the carts when a guest logs in to their existing account, with a guest cart active, and already some cart Items that are added when the user was previous logged in.

Is this something that is already considered?

Laravel 8 Support

Is your feature request related to a problem? Please describe.
I cannot upgrade my app to Laravel 8, please update your composer.json dependency file

Describe the solution you'd like
Add Laravel 8, to your composer.json dependency file

Describe alternatives you've considered
None

Additional context
None

Performance issue duplicate query when use cart() helper

Describe the bug
cart() helper hit database query every time.
example:
protected function getCartDetails() { return [ 'items' => cart()->items($displayCurrency = true), 'totals' => cart()->totals(), ]; }
This function will hit database multiple times.
To Reproduce
Steps to reproduce the behavior:

  1. Clone demo
  2. Install debugbar
  3. We will see duplicate query

Expected behavior
No duplicate query during request

Screenshots
1

Additional context
Suguest fix: Change bind to singleton in CartManagerServiceProvider

Can't update or remove cart item, no item at specified index

i attempt to update and remove the cart items, but it's not working, the error message says "There is no item in the cart at the specified index" but i'm sure the index is exist in db.

the error message

"msg": "Cant remove at index 12",
    "detail": "Freshbitsweb\\LaravelCartManager\\Exceptions\\ItemMissing: There is no item in the cart at the specified index....

my composer.json

"php": "^7.1.3",
"freshbitsweb/laravel-cart-manager": "^1.2",
"laravel/framework": "6.0.*",
"laravel/passport": "^8.0",

my cart config

return [
    // The driver that should be used to manage the cart (database/session/custom)
    'driver' => Freshbitsweb\LaravelCartManager\Drivers\DatabaseDriver::class,

    // The authentication guard that should be used to identify the logged in customer
    'auth_guard' => 'api',

    // Shipping charges are applied on order amount (subtotal - discount)
    'shipping_charges' => 0,

    // Specify the minimum order amount to avoid shipping charges
    'shipping_charges_threshold' => 0,

    // Tax amount is applied on net total (subtotal - discount + shipping charges)
    // subtotal, tax, net total and total are rounded to 2 decimals
    'tax_percentage' => 0,

    // Round off the total amount (net total + tax) to nearest (0 or 0.05 or 0.1 or 0.5 or 1)
    // Total amount is rounded off accordingly to come up the payable amount by the customer
    'round_off_to' => 0,

    // Name of the cookie that is used to identify a user session
    'cookie_name' => 'cart_identifier',

    // Number of minutes for which the cart cookie should be valid in user's browser
    'cookie_lifetime' => 10080, // one week

    // We use php's NumberFormatter class to display numbers as a currency value
    // Ref - https://www.php.net/manual/en/class.numberformatter.php
    // Locales list - https://stackoverflow.com/a/3191729/3113599
    'locale' => 'en_US',

    // Currency to display numbers with symbols - The 3-letter ISO 4217 currency code
    'currency' => 'IDR',

    // For Database driver only: Number of hours for which the cart data is considered valid
    // You can run/schedule the lcm_cart:clear command to remove old/invalid data
    'cart_data_validity' => 24 * 7, // a week
    ];

this is my delete function in controller

public function delete(Request $request)
    {
        $validator = Validator::make($request->all(), [
            'cartid' => 'required | exists:carts,auth_user',
            'item_id' => 'required | integer | exists:cart_items,id',
        ]);

        if ($validator->fails()) {
            return response()->json(['message' => 'Gagal mendapatkan keranjang belanja!'], 442);exit;
        }
        
        // set user to cart
        $cart = cart()->setUser($request->cartid);
        try {
            // trying to remove item
            $cart = cart()->removeAt($request->item_id);
            return response()->json(['cart' => $cart, 'cart_id' => $request->cartid], 200);
        } catch (\Throwable $th) {
            return response()->json(['msg' => 'Cant remove at index '.$request->item_id, 'detail' => ''.$th,'cart_id' => $request->cartid, 'cart_items' => cart()->toArray()], 200);
        }
    }

at last, this is my sample response (get all items from cart)

"cart_items": {
        "subtotal": "2.00",
        "discount": "0.00",
        "discountPercentage": "0.00",
        "couponId": null,
        "shippingCharges": "0.00",
        "netTotal": "2.00",
        "tax": "0.00",
        "total": "2.00",
        "roundOff": "0.00",
        "payable": "2.00",
        "items": [
            {
                "modelType": "App\\Product",
                "modelId": 7,
                "name": "Autem aut voluptas e",
                "price": "1.00",
                "image": "/userfile/5/Selection_006.png",
                "quantity": 1,
                "id": 9
            },
            {
                "modelType": "App\\Product",
                "modelId": 8,
                "name": "asdasdff",
                "price": "1.00",
                "image": "/userfile/5/Selection_006.png",
                "quantity": 1,
                "id": 12
            }
        ]
    }

in the response above, i have 1 item with id of 12, but still i have this error no item at specified index 12

Undefined function money_format()

Describe the bug
A clear and concise description of what the bug is.

I'm using your official repository demo project. I'm installing packages, setup .env config & startup local server using Laravel server php artisan serve, but I get on root page next error from Laravel.
Call to undefined function Freshbitsweb\LaravelCartManager\Core\money_format()

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Add any other context about the problem here.

instalation on laravel 6 for api (guard name = api)

not installing this error is showing on composer require freshbitsweb/laravel-cart-manager.

error

In CartManagerServiceProvider.php line 49:

Trying to access array offset on value of type null ,

Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1

Installation failed, reverting ./composer.json to its original content.

How to update the card

Hello, I have a question. I want to add a coupon id to the card but I can't. How do I add a coupon id and update my card?

User input to update cart quantity

Is your feature request related to a problem? Please describe.
If the user want to update the cartItems quantity at big number, it's good to have a method to update the quantity with input instead of one by one.

Describe the solution you'd like

/**
     * Set the quantity of a cart item.
     *
     * @param int Index of the cart item
     * @param int quantity to be increased
     * @return array
     */
    public function setQuantityAt($cartItemIndex, $quantity = 1)
    {
        $this->existenceCheckFor($cartItemIndex);

        $this->items[$cartItemIndex]->quantity = $quantity;

        $this->cartDriver->setCartItemQuantity(
            $this->items[$cartItemIndex]->id,
            $this->items[$cartItemIndex]->quantity
        );

        return $this->cartUpdates();
    }

Describe alternatives you've considered
Add a new method in CartItemsManager to let user update the quantity

incrementQuantityAt There is no item in the cart at the specified index.

protected function existenceCheckFor($cartItemIndex)
{
    if (! $this->items->has($cartItemIndex)) {
        throw new ItemMissing('There is no item in the cart at the specified index.');
    }
}

Why do I always get false? Where does has() function come from?
$this->items returns array of object, doesn't it?
And $cartItemIndex is id column of cart_items table, isn't it?

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.