marshmallow / cart
洛伦兹·伊普西兰蒂克·道尔·斯图尔特·阿梅特,康奈克图斯·阿迪宾迪克·埃利特,塞多·尤尔·伊休梅多·特莫里努斯·伊努迪恩·乌塔·埃图罗·伊图罗·马加卢阿。
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-09-18 15:15:24 UTC
README
电子商务购物车
此软件包包含您在Laravel应用程序中实现购物车所需的所有逻辑。它还包含您管理商店所需的所有Nova资源。Marshmallow为许多客户使用此软件包,并在需要时添加新功能。如果您想使用此软件包,请这样做,并在遇到任何问题的情况下告知我们。
安装
Composer
您可以通过以下Composer命令安装此软件包。
composer require marshmallow/cart
迁移
您需要运行此软件包中的迁移以创建我们进行电子商务魔法所需的所有表。
php artisan migrate
中间件
请将以下中间件添加到您的Web组中,以确保购物车在每个路由上可用。如果您希望将此中间件包括在选定的路由集中,您也可以这样做。
protected $middlewareGroups = [ 'web' => [ // ... \Marshmallow\Ecommerce\Cart\Http\Middleware\CartMiddleware::class, ], ];
Nova
运行以下命令以发布您需要管理所有电子商务内容所需的所有Nova资源。
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
填充表
我们为荷兰的电子商务网站创建了种子器。如果您正在运营一家荷兰商店,可以运行这些种子器。如果不是,则不要运行这些种子器。只需通过您刚刚创建的Nova资源创建自己的种子器。
php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\CurrencySeeder php artisan db:seed --class=Marshmallow\\Priceable\\Seeders\\VatRatesSeeder
环境文件
确保您在您的.env
文件中将CURRENCY
值设置为与您使用的货币相匹配。
CURRENCY=eur
事件
此软件包触发一系列事件,您可以在应用程序中监听这些事件(如果需要的话)。
折扣
设置
要使用折扣模块,您首先需要确保已运行所有migrations
。
创建Nova资源
您需要发布Nova资源,以便在Nova中创建新的折扣代码。运行以下命令。
php artisan marshmallow:resource Discount Ecommerce\\Cart
发布新配置
有一个新的配置文件处理折扣功能默认值。运行以下命令以发布新的配置文件。
php artisan vendor:publish --tag="ecommerce-discount-config"
用法
添加折扣
要将折扣添加到购物车,您需要创建自己的路由/端点来处理此操作。您可以使用以下示例代码来激活折扣。如果一切顺利,则$response
将为空。如果出现错误,此方法将返回包含我们为什么无法将折扣添加到购物车的原因的错误消息。
use Marshmallow\Ecommerce\Cart\Facades\Cart; use Marshmallow\Ecommerce\Cart\Models\Discount; $discount = Discount::byCode( request()->discount ); $response = Cart::get()->addDiscount($discount);
删除折扣
如果您允许客户从购物车中删除已激活的折扣,您将再次需要创建自己的路由/端点来处理此操作。然后,您可以使用以下示例代码从卡片中删除折扣。
use Marshmallow\Ecommerce\Cart\Facades\Cart; Cart::get()->deleteDiscount();
购物车方法
随着折扣方法的引入,您可能需要更新用于显示购物车总金额的方法。请参阅以下新方法。
$cart->getTotalAmountWithoutShippingAndDiscount(); $cart->getTotalAmountWithoutShippingAndDiscountAndWithoutVat(); $cart->getDiscountAmount(); $cart->getDiscountAmountWithoutVat();
购物车方法
/** * 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->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');
变更日志
有关最近更改的更多信息,请参阅变更日志。
测试
composer test
安全
如果您发现任何与安全相关的问题,请通过电子邮件发送给 stef@marshmallow.dev,而不是使用问题跟踪器。
致谢
许可
MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件。