marshmallow / cart
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Installs: 5 398
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 0
Open Issues: 21
Requires
- php: ^8.0
- laravel/nova: ^4.0
- marshmallow/addressable: ^v1.6.1
- marshmallow/dataset-country: ^v1.2.2
- marshmallow/nova-field-string-generator: ^v2.0.0
- marshmallow/nova-flexible: ^v2.0.0
- marshmallow/nova-tabs: ^2.0.3
- marshmallow/payable: ^v2.0.0
- marshmallow/priceable: ^v3.0.0
- marshmallow/products: ^v3.0.0
- dev-master
- v2.x-dev
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.4
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.x-dev
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.14
- v1.0.13
- v1.0.12
- v1.0.11
- v1.0.10
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-feature/livewire-3-support
- dev-dependabot/npm_and_yarn/minimist-1.2.8
- dev-dependabot/npm_and_yarn/dns-packet-5.4.0
- dev-dependabot/npm_and_yarn/sass-1.58.3
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/bootstrap-5.2.3
- dev-dependabot/github_actions/overtrue/phplint-8.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/minimatch-3.1.2
- dev-dependabot/npm_and_yarn/sass-loader-13.2.0
- dev-dependabot/npm_and_yarn/vue-template-compiler-2.7.14
- dev-dependabot/github_actions/actions/checkout-3.1.0
- dev-dependabot/npm_and_yarn/terser-4.8.1
- dev-feature/update-for-mollie-orders
- dev-nova4
- dev-development
- dev-dependabot/npm_and_yarn/resolve-url-loader-5.0.0
- dev-dependabot/npm_and_yarn/nanoid-3.3.1
- dev-beta
This package is auto-updated.
Last update: 2024-12-18 15:50:32 UTC
README
Ecommerce Shopping Cart
This package contains all the logic you need to make use of a shopping cart in your Laravel application. It also contains all the Nova resources you need to manage your store. We use this package at Marshmallow for a lot of customers and add new functionalities when ever we need them. If you wish to use this, please do so and let us know if you have any issues.
Installation
Composer
You can install this package via the following composer command.
composer require marshmallow/cart
Migrate
You need to run the migration from this package to create all the tables we need to do some ecommerce magic.
php artisan migrate
Middleware
Please add the following middle ware to your web group to make sure the cart is available on every route. If you wish to include this middleware to a select set of route you can do so.
protected $middlewareGroups = [ 'web' => [ // ... \Marshmallow\Ecommerce\Cart\Http\Middleware\CartMiddleware::class, ], ];
Nova
Run the commands below to publish all the Nova resources that you need to manage all the ecommerce stuff.
php artisan marshmallow:resource Product Product php artisan marshmallow:resource ProductCategory Product php artisan marshmallow:resource Supplier Product php artisan marshmallow:resource Price Priceable php artisan marshmallow:resource VatRate Priceable php artisan marshmallow:resource Currency Priceable php artisan marshmallow:resource Prospect Ecommerce\\Cart php artisan marshmallow:resource ShoppingCart Ecommerce\\Cart php artisan marshmallow:resource Customer Ecommerce\\Cart php artisan marshmallow:resource ShippingMethod Ecommerce\\Cart php artisan marshmallow:resource ShippingMethodCondition Ecommerce\\Cart php artisan marshmallow:resource Order Ecommerce\\Cart php artisan marshmallow:resource OrderItem Ecommerce\\Cart php artisan marshmallow:resource Discount Ecommerce\\Cart php artisan marshmallow:resource Route Seoable
Seed tables
We have created seeders for ecommerce site in the Netherlands. If you are running a dutch shop, you can run these seeders. If not, don't run these. Just create your own via the Nova resources you've just created.
php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\CurrencySeeder php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\VatRatesSeeder
Envoirment file
Make sure you set the CURRENCY
value in you .env
file to match the currency you are using.
CURRENCY=eur
Events
This package triggers a set of events which you can listen to in your application if you wish to do so.
Discounts
Setup
To use the discount module, you first need to make sure you have run all the migrations
.
Create the Nova resource
You need to publish the Nova resource to be able to create new discount code's in Nova. Run the command below.
php artisan marshmallow:resource Discount Ecommerce\\Cart
Publish the new config
There is a new config file that handles defaults for the discount functionalities. Run the command below to publish the new config file.
php artisan vendor:publish --tag="ecommerce-discount-config"
Usage
Adding a discount
To add the discount to a shopping cart, you need to create your own route/endpoint to handle this. You can use the example code below to active the discount. If all is oke, the $response
will be empty. If something went wrong this method will return an error message containing the reason why we couldn't add the discount to the cart.
use Marshmallow\Ecommerce\Cart\Facades\Cart; use Marshmallow\Ecommerce\Cart\Models\Discount; $discount = Discount::byCode( request()->discount ); $response = Cart::get()->addDiscount($discount);
Deleting a discount
If you made the customer to be able to delete an activated discount from the shopping cart, you will again have to create your own route/endpoint for this. You can then use the example code below to remove the discount from the card.
use Marshmallow\Ecommerce\Cart\Facades\Cart; Cart::get()->deleteDiscount();
Cart methods
With the introduction of the discount methods you might need to update the methods that are used in your shopping cart to display cart totals. Please see the new methods below.
$cart->getTotalAmountWithoutShippingAndDiscount(); $cart->getTotalAmountWithoutShippingAndDiscountAndWithoutVat(); $cart->getDiscountAmount(); $cart->getDiscountAmountWithoutVat();
Cart methods
/** * These are helper functions to get cart totals. */ $cart->getTotalAmountWithoutShipping(); $cart->getTotalAmountWithoutShippingAndWithoutVat(); $cart->getShippingAmount(); $cart->getShippingAmountWithoutVat(); $cart->getTotalAmount(); $cart->getTotalAmountWithoutVat(); $cart->getTotalVatAmount(); $cart->getTotalAmountWithoutShippingAndDiscount(); $cart->getTotalAmountWithoutShippingAndDiscountAndWithoutVat(); $cart->getDiscountAmount(); $cart->getDiscountAmountWithoutVat(); /** * You can format all the methods above to get a string with currency. */ $cart->getFormatted('getTotalAmount'); /** * Extra helpers */ $cart->productCount(); $cart->getItemsWithoutShipping(); $cart->getItemsWithoutDiscount(); $cart->getDiscountItems(); $cart->getItemsWithoutDiscountAndShipping(); $cart->getOnlyProductItems();
Item methods
$item->setQuantity(4); $item->increaseQuantity(); $item->decreaseQuantity(); // Amount helpers $item->getUnitAmount(); $item->getUnitAmountWithVat(); $item->getUnitAmountWithoutVat(); $item->getUnitVatAmount(); $item->getTotalAmount(); $item->getTotalAmountWithVat(); $item->getTotalAmountWithoutVat(); $item->getTotalVatAmount(); // Formatted $item->getFormatted('getTotalAmount');
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
composer test
Security
If you discover any security related issues, please email stef@marshmallow.dev instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.