Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Shoppingcart

Shoppingcart Laravel Package

anayarojo/shoppingcart

A flexible shopping cart package for Laravel with a simple API for adding, updating, and removing items, applying conditions and attributes, and persisting carts to session or database storage. Well suited for building e-commerce checkout flows.

View on GitHub
Deep Wiki
Context7

anayarojo/shoppingcart is a lightweight shopping cart package for Laravel with a fluent API for managing cart items, quantities, and totals. It simplifies common cart workflows while keeping price, tax, and subtotal calculations consistent.

  • Fluent add, update, and remove item methods
  • Multiple cart instances for separate baskets
  • Session-based cart persistence
  • Item quantities with automatic total calculations
  • Configurable tax and cart conditions support
Frequently asked questions about Shoppingcart
How do I install the anayarojo/shoppingcart package in Laravel?
Install it with Composer by requiring anayarojo/shoppingcart in your project. The package ships an auto-discovered service provider and a facade, so no manual registration is needed on modern Laravel versions. Publish the config file with the vendor:publish command if you want to adjust storage drivers or calculation defaults. Plan a short spike to exercise the API against your real product shapes before wiring it into checkout.
Which Laravel and PHP versions does this shopping cart package support?
The supported Laravel and PHP ranges are declared in the package's composer.json and README, so verify those constraints against your application before committing to it. The project is actively released, but you should confirm explicitly that your target branch, for example Laravel 12 with PHP 8.3 or newer, is covered by the maintainer's test matrix. If your version is not tested, run the package's own test suite against your framework version inside a throwaway branch.
How do I add products and update quantities with the fluent cart API?
You add a purchasable model or an identifier along with a quantity, then use the same fluent chain to increase, decrease, or remove that line item. Cart contents, item counts, and totals are read back through accessor methods on the cart instance or facade. Quantities are validated rather than trusted blindly, which matters if you accept quantity changes from a form or an AJAX request. Keep the facade calls inside a first-party service class so controllers and views never depend on the package directly.
Can I use multiple shopping cart instances in one Laravel application?
Yes. The package supports multiple named cart instances, so you can keep a default cart alongside separate instances for wishlists, quotes, or per-vendor baskets. Each instance holds its own items, conditions, and totals independently. This is useful for multi-tenant or marketplace scenarios where a single session needs more than one basket. Give each instance a stable name so persistence and retrieval stay predictable.
Does the package support session persistence and database-backed carts?
The package supports both session and database persistence for cart contents, letting you store ephemeral pre-checkout state or a durable cart tied to a user record. If you need carts that follow a customer across devices, verify how rehydration by user identifier is handled and whether the stored payload includes enough product references to rebuild line items. Treat any persisted cart as a snapshot: reprice it against your pricing service at checkout instead of trusting stored amounts.
How do I apply discounts, taxes, and shipping conditions to the cart total?
Conditions are attached to the cart and evaluated when totals are calculated, which lets you model percentage or fixed discounts, tax rates, and shipping charges without editing package internals. Conditions can be layered, so a promotion plus a tax rule plus a shipping fee all roll into the final total. Always compute money in your own pricing layer and use the package only to aggregate what you pass in. That separation keeps cart and checkout totals consistent when promotions change.
Are events fired when items are added, updated, or removed from the cart?
The package dispatches events around cart mutations and calculations, so you can listen for add, update, remove, and clear operations and react with logging, analytics, or inventory holds. Events are the cleanest extension point because they do not require subclassing internal calculators. Register listeners in your own service provider and keep side effects idempotent, since a single request can trigger several cart operations. If you need custom totals, prefer a condition or a decorator over patching the package.
How does the package handle money, floats, or integer minor units?
Money handling is the detail most likely to bite you, so confirm whether amounts are stored as floats or integer minor units and how rounding is applied per line versus per total. For anything beyond a prototype, pass integer minor units into the cart and format only at the presentation layer. Decide on a rounding strategy up front and document it, because per-line rounding and per-total rounding produce different totals on the same basket. Never let the cart hold a price your pricing service would compute differently.
How do I test a Laravel shopping cart integration?
Write feature tests that drive your own CartService wrapper rather than the package facade, so tests survive if you swap the engine later. Cover add, quantity mutation, removal, empty cart totals, stacking conditions, and invalid quantities, since server-side validation of submitted values is a security boundary. Use the package's events to assert that mutations fire as expected. If you maintain a fork or pin a version, run the package's own suite in CI as a smoke test.
Is this package safe to use in production, and what are the risks?
The blast radius is small: the code is MIT licensed, isolated, and replaceable behind an interface, so the main risk is vendor maintenance rather than architecture. The project has a single maintainer and few downstream dependents, which means limited external battle testing and a good chance you will discover the edge cases yourself. Adopt with containment, wrap the facade in a first-party interface on day one, and keep pricing, tax, promotion, and inventory logic in your own services. For a session-first ephemeral cart this is a reasonable trade; for durable, auditable, repriced carts, evaluate a heavier commerce platform or build the cart yourself.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo
bernskioldmedia/laravel-harvest
bernskiold/laravel-data-scrubber
bernskiold/laravel-currency-converter
bernskiold/laravel-campaign-monitor
bernskioldmedia/laravel-autotranslate
siberfx/telegram-bot
roy-sandip/laravel-view-extended
gregsphotography/site-builder-core
roy-sandip/laravel-view
anodyne/blade-fluentui-icons
webx-ui/module-catalog-collections