• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Register
  • Login
Bagisto Forum

Bagisto

  • Register
  • Login
  • Search
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups

Remove specific product from cart Not Working

Bug Report
3
3
507
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R
    RehamALraee last edited by 7 Apr 2021, 09:35

    This post is deleted!
    1 Reply Last reply Reply Quote 0
    • devansh-webkul
      devansh-webkul last edited by 7 Apr 2021, 13:52

      Hi @RehamALraee,

      Can you share with me more steps and info so that I can further investigate?

      1 Reply Last reply Reply Quote 0
      • about a year later
      • P
        prashant2408 last edited by prashant2408 31 May 2022, 07:00 28 May 2022, 11:44

        Facing same issue.
        API call
        http://127.0.0.1:8000/api/checkout/cart/remove-item/10
        Bug:
        No product remove
        Solution that I try:

        1. I open file 'packages/Webkul/API/Http/routes.php'.
          In this file route is related to this: cart/remove-item/{id}', 'CartController@destroyItem'
        2. I open destroyItem function in CartController class.
        public function destroyItem($id)
            {
                $id = request('id');
                Event::dispatch('checkout.cart.item.delete.before', $id);
        
                Cart::removeItem($id);
        
                Event::dispatch('checkout.cart.item.delete.after', $id);
        
                Cart::collectTotals();
        
                $cart = Cart::getCart();
        
                return response()->json([
                    'message' => __('shop::app.checkout.cart.item.success-remove'),
                    'data'    => $cart ? new CartResource($cart) : null,
                ]);
            }
        
        • removeItem() in 'packages/Webkul/Checkout/src/Cart.php'
            public function removeItem($itemId)
            {
                Event::dispatch('checkout.cart.delete.before', $itemId);
                if (! $cart = $this->getCart()) {
                    return false;
                }
                if ($cartItem = $cart->items()->find($itemId)) {
                    $cartItem->delete();
        
                    if ($cart->items()->get()->count() == 0) {
                        $this->cartRepository->delete($cart->id);
        
                        if (session()->has('cart')) {
                            session()->forget('cart');
                        }
                    }
        
                    Shipping::collectRates();
        
                    Event::dispatch('checkout.cart.delete.after', $itemId);
        
                    $this->collectTotals();
        
                    return true;
                }
        

        Problem: It is not very much intuitive to understand how this code work.

        • 'Cart::removeItem($id);' this line may not work properly.

        • there is no effect on 'quantity' of item even if I remove one . It should be decrease by one.

        • I can't able to find which table is use to save quantity of item in database.

        • the level of abstraction is to much high and unclear for simple work like removing item form cart,and it is quite complicated to understand how it works even if I have more then year of experince on laravel and php and I am using Bagisto for a long time.

        • Response of api but no item remove cart
          'http://127.0.0.1:8000/api/checkout/cart/remove-item/10'

        {
            "message": "Item was removed successfully from the cart.",
            "data": {
                "items": [
                    {
                        "quantity": "3",
                        "product": {
                            "id": 7,
                            "sku": "4",
                            "type": "simple",
                            "name": "Sugar Control RNR15048 Rice",
                            "url_key": "sugar-control-rnr15048-rice",
                            "price": "15.0000",
                            "formated_price": "₹15.00",
                            "short_description": "<p>Sugar Control RNR15048 Rice</p>",
                            "description": "<p>Sugar Control RNR15048 Rice</p>",
                            "images": [
                                {
                                    "id": 27,
                                    "path": "product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                    "url": "http://mlmshop-env.eba-cgpjvqw8.ap-south-1.elasticbeanstalk.com//storage/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                    "original_image_url": "http://mlmshop-env.eba-cgpjvqw8.ap-south-1.elasticbeanstalk.com//storage/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                    "small_image_url": "http://127.0.0.1:8000/cache/small/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                    "medium_image_url": "http://127.0.0.1:8000/cache/medium/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                    "large_image_url": "http://127.0.0.1:8000/cache/large/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg"
                                }
                            ],
                            "videos": [],
                            "base_image": {
                                "small_image_url": "http://127.0.0.1:8000/cache/small/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                "medium_image_url": "http://127.0.0.1:8000/cache/medium/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                "large_image_url": "http://127.0.0.1:8000/cache/large/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg",
                                "original_image_url": "http://127.0.0.1:8000/cache/original/product/7/yS6rwYkuafpi2AQMY487hKfOf23yDylj4NvZgQ1m.jpg"
                            },
                            "created_at": "2021-07-07T11:39:50.000000Z",
                            "updated_at": "2021-07-07T11:39:50.000000Z",
                            "reviews": {
                                "total": 0,
                                "total_rating": 0,
                                "average_rating": 0,
                                "percentage": []
                            },
                            "in_stock": true,
                            "is_saved": false,
                            "is_wishlisted": true,
                            "is_item_in_cart": true,
                            "show_quantity_changer": true,
                            "special_price": "15.0000",
                            "formated_special_price": "₹15.00",
                            "regular_price": "20.0000",
                            "formated_regular_price": "₹20.00"
                        }
                    }
                ],
                "created_at": "2022-05-31T05:32:21.000000Z",
                "updated_at": "2022-05-31T06:43:28.000000Z"
            }
        }
        
        • there is 3 quantity and it does not change.
          Can anyone please help. I urgently need help. I you need more detail then contact.
        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          3/3
          Last post