justbetter/laravel-magento-async
Composer 安装命令:
composer require justbetter/laravel-magento-async
包简介
Interact with Magento via Async requests
README 文档
README
Laravel Magento Async
This package provides a way to store async/bulk requests to Magento to later retrieve the status of the operation and handle the status. It works by storing the send async request with the operations in the database and retrieving the statuses periodically.
Once the status of an operation changes an event is fired. It is possible to relate any model to an operation which makes it possible to know where the operation originates from and handle the operation result.
Installation
This package is an extension of justbetter/laravel-magento-client. Be sure to install and configure that package first.
Require this package:
composer require justbetter/laravel-magento-async
Optionally, publish the configuration file of this package to edit the queue and cleanup time.
php artisan vendor:publish --provider="JustBetter\MagentoAsync\ServiceProvider" --tag=config
Scheduler
In order to update and cleanup the statuses of the async operation two commands are required in your scheduler:
<?php protected function schedule(Schedule $schedule): void { $schedule->command(\JustBetter\MagentoAsync\Commands\UpdateBulkStatusesCommand::class)->everyFiveMinutes(); $schedule->command(\JustBetter\MagentoAsync\Commands\CleanBulkRequestsCommand::class)->everyFiveMinutes(); }
Usage
This package provides a MagentoAsync client to send requests.
An event will later be dispatched by the package to inform the application that the operation has been processed
You can listen to this event to handle the operation result.
Sending the request
To send an async (bulk) request using this package use the MagentoAsync client:
<?php public function __construct( protected \JustBetter\MagentoAsync\Client\MagentoAsync $magentoAsync ) {} ... public function handle(string $store): void { $products = Product::query()->take(1000)->get(); $payload = $products ->map(fn(Product $product) => ['product' => ['sku' => $product->sku, 'status' => $product->status]]) ->toArray(); $this->magentoAsync ->configure(fn (Magento $magento): Magento => $magento->store($store)) // Optionally configure the Magento client ->subjects($products->all()) // Pass the models in the same order as the payload ->postBulk('products', $payload); // Bulk post this payload to the `products` endpoint }
The subjects array is a list of models, the indexes have to match with the payload in order to bind Magento's operation id with the correct model.
When sending non-bulk requests a ->subject() method is available:
<?php public function __construct( protected \JustBetter\MagentoAsync\Client\MagentoAsync $magentoAsync ) {} ... public function handle(): void { $product = Product::query()->first(); $payload = ['product' => ['sku' => $product->sku, 'status' => $product->status]]; $this->magentoAsync ->subject($product) // Pass the subject ->post('products', $payload); // Post this payload to the `products` endpoint }
Retrieving the operation status
This package provides an event that dispatches for all operations: \JustBetter\MagentoAsync\Events\BulkOperationStatusEvent.
The event includes the bulk operation that has been updated for you to handle the response.
This event dispatches for all operation changes, you can use the operation model to determine what endpoint was called
If you have bound a subject the package provides an abstract listener \JustBetter\MagentoAsync\Listeners\BulkOperationStatusListener.
This class provides a way to filter on a specific model and ignore the Open status.
Example implementation:
<?php use \JustBetter\MagentoAsync\Listeners\BulkOperationStatusListener as BaseBulkOperationStatusListener; use \JustBetter\MagentoAsync\Models\BulkOperation; use \JustBetter\MagentoAsync\Enums\OperationStatus; class BulkOperationStatusListener extends BaseBulkOperationStatusListener { protected string $model = Product::class; public function execute(BulkOperation $operation): void { /** @var Model $status */ $status = $operation->subject; if ($operation->status === OperationStatus::Complete) { // Handle complete status return; } // Handle failed status } }
Quality
To ensure the quality of this package, run the following command:
composer quality
This will execute three tasks:
- Makes sure all tests are passed
- Checks for any issues using static code analysis
- Checks if the code is correctly formatted
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
justbetter/laravel-magento-async 适用场景与选型建议
justbetter/laravel-magento-async 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.13k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 07 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 justbetter/laravel-magento-async 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 justbetter/laravel-magento-async 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 25.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 7
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-03