Bagisto Forum

    Bagisto

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

    How to Override CartResource

    Modules
    2
    2
    268
    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.
    • S
      suyashcyber94 last edited by

      Hello Team,

      I have added a custom field in Cart for which I need to override CartResource to return my custom field, however, the resource is not injected in Webkul\API\Http\Controllers\Shop\CartController instead it is instantiated directly.

      return response()->json([
          'data' => $cart ? new CartResource($cart) : null,
      ]);
      

      Currently, I am overriding API routes and directing them to my custom CartController where I am using my Custom CartResource. This works fine but the issue is, I need to identify and override all the routes where cart is being return. Additionally, it is also not good if I will upgrade bagisto in the future as it will keep using the custom controller instead of core's (in case it is updated).

      What is the right approach to this?

      1 Reply Last reply Reply Quote 0
      • devansh-webkul
        devansh-webkul last edited by

        You are already doing with the right approach and this does not impact your upgrade unless and until you are changing the package's structure.

        So, you need to handle the customization and also check the compatibility if you upgrade.

        1 Reply Last reply Reply Quote 0
        • First post
          Last post