marshmallow/products
Composer 安装命令:
composer require marshmallow/products
包简介
Package that will contain basic methods for handeling products and preparing them toe be used in ecommerce.
关键字:
README 文档
README
Marshmallow Products
Basic building blocks for handling products and preparing them to be used in e-commerce. This package ships the Product, ProductCategory and Supplier models (with prices, SEO, slugs, soft deletes and flexible images) plus matching Laravel Nova resources. It is typically used together with Marshmallow's Cart or Ecommerce packages.
Requirements
- PHP
^8.1 - Laravel Nova
^5.0
Laravel Nova is a paid product. Make sure your Composer is authenticated against https://nova.laravel.com before installing.
Installation
Install the package via Composer:
composer require marshmallow/products
The service provider is auto-discovered. It registers the package config and loads the package migrations automatically, so a php artisan migrate is all that is needed to create the products, product_categories, suppliers and pivot tables.
Register the product observer in your application's AppServiceProvider::boot() method:
use Marshmallow\Product\Models\Product; use Marshmallow\Product\Observers\ProductObserver; public function boot() { Product::observe(ProductObserver::class); }
Seed the default VAT rates (provided by marshmallow/priceable) so products can be priced:
php artisan db:seed --class="Marshmallow\Priceable\Database\Seeds\VatRatesSeeder"
Publishing the config
Optionally publish the config file to override the models, Nova resources and defaults:
php artisan vendor:publish --tag="config"
After installation
Generate the Nova resources for this package (and for the Priceable resources it relies on) using the marshmallow:resource command from marshmallow/commands:
php artisan marshmallow:resource Product Product php artisan marshmallow:resource Supplier Product php artisan marshmallow:resource ProductCategory Product php artisan marshmallow:resource Price Priceable php artisan marshmallow:resource VatRate Priceable php artisan marshmallow:resource Currency Priceable
Set your default currency in your .env:
CURRENCY=eur
Configuration
The published config/product.php file exposes the following options:
| Key | Default | Description |
|---|---|---|
models.product |
Marshmallow\Product\Models\Product |
The Product Eloquent model. Override to use your own. |
models.product_category |
Marshmallow\Product\Models\ProductCategory |
The ProductCategory Eloquent model. |
models.supplier |
Marshmallow\Product\Models\Supplier |
The Supplier Eloquent model. |
nova.wysiwyg |
Laravel\Nova\Fields\Trix (env NOVA_WYSIWYG) |
The Nova field used for the product body. |
nova.prices_are_including_vat |
true |
Whether prices entered in Nova already include VAT. |
nova.defaults.currencies |
1 |
Default currency id used on new prices. |
nova.defaults.vat_rates |
3 |
Default VAT rate id used on new prices. |
nova.resources |
Marshmallow\Product\Nova\* |
The Nova resource classes for product, category and supplier (price resource comes from Priceable). |
nova.relationships.product_supplier |
Marshmallow\Product\Nova\Relationships\ProductSupplier::class |
The pivot definition for the product/supplier relationship. |
default_product_view |
shop.product |
The blade view used to render a product detail page. |
channels |
[] |
Optional sales channels (e.g. Bol.com) to expose the product on. |
Usage
The Product model
use Marshmallow\Product\Models\Product; $product = Product::factory()->create([ 'name' => 'Example product', ]); // Eager load the common relationships to prevent N+1 queries. $products = Product::active()->withRelationships()->get(); foreach ($products as $product) { $product->fullname(); // human readable name $product->freeStock(); // amount purchasable right now $product->getAvailability(); // Product::IN_STOCK | OUT_OF_STOCK | PREORDER $product->getCondition(); // 'new' $product->route(); // route('product.detail', $product) if ($product->hasImage()) { $product->firstImagePath(); } }
A Product is sluggable, SEO-able and priceable, uses soft deletes, and casts its images attribute to a Nova Flexible value. It exposes category() (belongs-to), categories() and suppliers() (belongs-to-many) relationships, all resolved through the configurable model classes.
Available scopes
| Scope | Description |
|---|---|
active() |
Only products where active = 1. |
withRelationships() |
Eager loads category, categories, suppliers and media. |
Stock status constants
Product::IN_STOCK; Product::OUT_OF_STOCK; Product::PREORDER;
Security Vulnerabilities
Please report security vulnerabilities by email to stef@marshmallow.dev rather than via the public issue tracker.
Credits
License
The MIT License (MIT). Please see the License File for more information.
marshmallow/products 适用场景与选型建议
marshmallow/products 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.44k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2020 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「marshmallow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 marshmallow/products 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 marshmallow/products 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 marshmallow/products 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This packages provides you with the ability to easily connect your Laravel application to ZohoDesk.
Generate slugs when saving Eloquent models
A Laravel Nova help field.
Connect your Kiyoh to your Laravel application
Sending request to you Google Analytics has never been easier. With support for e-commerce tracking.
A package to simply add metadata to models
统计信息
- 总下载量: 7.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-03