定制 ilbronza/products 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ilbronza/products

Composer 安装命令:

composer require ilbronza/products

包简介

:package_description

README 文档

README

Suppliers Creation from Standard Models

This package now includes a helper feature that allows you to create Suppliers directly from existing Eloquent models.

How it works

Any Eloquent model can be converted into a Supplier by invoking the SupplierCreatorHelper.
The system will automatically generate the corresponding Supplier entry, linking it to the source model through its class name and primary key.

Example Usage

Notes

  • If a Supplier for the given model already exists, the factory will return it instead of creating a duplicate.
  • The Supplier inherits descriptive fields from the model whenever possible.
  • This feature is intended to simplify the integration of existing domain models into the Products package.

Sellables Creation from Standard Models

This package now includes a helper feature that allows you to create Sellables directly from existing Eloquent models.

How it works

Any Eloquent model can be converted into a Sellable by invoking the SellableCreatorHelper.
The system will automatically generate the corresponding Sellable entry, linking it to the source model through its class name and primary key.

Example Usage

Notes

  • If a Sellable for the given model already exists, the factory will return it instead of creating a duplicate.
  • The Sellable inherits descriptive fields from the model whenever possible.
  • This feature is intended to simplify the integration of existing domain models into the Products package.

Sellable prices creation from Target Model

call this route

app('products')->route('products.calculatePrices')

it will execute ProductCalculatePricesController@calculatePrices

class ProductCalculatePricesController extends ProductCRUD
{
    public $allowedMethods = ['calculatePrices'];

    public function calculatePrices()
    {
        $products = $this->getModelClass()::all();

        foreach($products as $product)
            cache()->remember(
                $product->cacheKey('calculatePricesByTarget'),
                3600,
                function() use ($product)
                {
                    return SellablePricesCreatorHelper::calculatePricesByTarget($product);
                }
            );

        return response()->json([
            'status' => 'ok'
        ]);
    }
}

SellablePricesCreatorHelper::calculatePricesByTarget takes the product, call $product->getPriceBaseAttributes() and populate all sellable prices.

for example if you declare getPriceBaseAttributes like this:

namespace App\Overrides\Models\Products;

class Product extends IbProduct implements WithPriceInterface
{
	public function getPriceBaseAttributes()
	{
		return [
			'company_cost' => $this->company_cost,
			'client_price' => $this->client_price,
		];
	}
}

product sellables will have a company_cost and a client_price

统计信息

  • 总下载量: 119
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-14