sectheater/marketplace

Fluent Laravel 电子商务系统

v1.0.2 2018-10-19 20:13 UTC

This package is auto-updated.

Last update: 2024-09-16 20:45:52 UTC


README

Latest Version on Packagist MadeWithLaravel.com shield

marketplace 快速参考手册即将推出

marketplace 为您提供以下功能

1. 产品 & 产品变体系统

创建简单产品,以及通过将产品附加到特定类型来使用变体系统创建复杂产品。

2. 优惠券系统

生成、验证并在结账时轻松购买。

3.心愿单/购物车系统

  • 轻松CRUD心愿单/购物车
  • 获取整个购物车/心愿单的总计/小计,并可选地应用销售/优惠券后。
  • 在幕后处理库存。

4. 分类系统

  • 将产品、产品类型附加到分类。

5. 销售系统

  • 为分类、特定产品、产品类型设置销售。

6. 授权用户 & 管理角色。

安装步骤

1. 需求包

创建您的 Laravel 应用程序后,可以使用以下命令包含 marketplace 包:

composer require sectheater/marketplace:dev-master

2. 添加数据库凭证 & APP_URL

接下来,请确保创建一个新的数据库,并将您的数据库凭证添加到 .env 文件中

DB_HOST=localhost
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret

您还想要更新您的网站 URL,在 .env 文件中的 APP_URL 变量内部

APP_URL=https://:8000

3. 准备环境

只需运行以下命令。

 php artisan sectheater-market:install     
 
命令解释
  • 该命令仅发布 marketplace 的配置、迁移、辅助程序和种子。

注意:您可能需要运行自动加载 composer 命令来重新加载更改。

 composer dump-autoload -o 

另一个注意:别忘了删除默认用户表迁移,因为 marketplace 也附带了一个默认的迁移。

4. 示例用法

4.1 创建具有变体的产品。
Product::generate([
  'user_id' => auth()->id(),
  'name' => 'laptop',
  'description' => 'Fancy laptop',
  'price' => 15000,
  'category' => 'electronics',
  'type' => ['name' => 'MacBook Pro', 'stock' => 20],
  'details' => ['color' => 'Silver', 'dummy-feature' => 'dummy-text']
);
4.2 根据标准过滤产品。
Product::fetchByVariations(['locations' => 'U.K', 'variations' => ['size' => 'XL', 'color' => 'red'], 'categories' => 'clothes']);
  • 添加自定义标准并在搜索时使用它。
4.3 获取购物车总计/小计。

出人意料的是,您可以使用一些方法来检索总计/小计

Cart::subtotal();
Cart::total(); // returns total after applying tax.
Cart::total($coupons); // Collection of coupons passed, returns total after applying tax and coupons.
Cart::subtotalAfterCoupon($coupons);

令人惊讶的是,您可以使用任何方法对购物车进行操作,也可以对心愿单进行操作(因为我们可以将其视为虚拟购物车)

4.4 获取购物车项目。
Cart::item(1); // get the item with id of 1

Cart::item(1,  ['color' => 'blue', 'size' => 'L']); // get the item with the id of 1 and should have these attributes.

Cart::item(null, ['color' => 'blue','size' => 'L']); // get the current authenticated user's cart which has these attributes assuming that these attributes identical to the database record.

Cart::item(null, ['color' => 'blue','size' => 'L'] , 'or');  // get the current authenticated user's cart which has any of these attributes.
4.4 生成优惠券。
Coupon::generate([
  'user_id' => auth()->id(),
  'active' => true,
  'percentage' => 10.5,
  'expires_at' => Carbon::now()->addWeeks(3)->format('Y-m-d H:i:s')
]);
4.5 验证优惠券。
$coupon = Coupon::first(); // valid one
Coupon::validate($coupon); // returns true
4.6 停用优惠券。
$coupon = Coupon::first(); 
Coupon::deactivate($coupon->id);
4.7 购买优惠券。
$coupon = Coupon::first();
Coupon::purchase($coupon); // Purchase the coupon for the current authenticated user.
Coupon::purchase($coupon, $anotherUser); // Purchase the coupon for the passed user.
4.7 已购买优惠券。
  • 它自动释放无效的已购买优惠券。
Coupon::purchased(); // returns the only valid purchased coupons.
4.8 应用特定优惠券。
  • 假设用户有一些优惠券,他可以指定哪些优惠券可以应用于特定产品。
Coupon::appliedCoupons($coupons); // returns a query builder.

更多信息,请查看 文档