承接 justbetter/laravel-magento-stock 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

justbetter/laravel-magento-stock

Composer 安装命令:

composer require justbetter/laravel-magento-stock

包简介

This packages facilitates a generic way to push stock to Magento.

README 文档

README

Package banner

Laravel Magento Stock

Tests Coverage Analysis Total downloads

This packages facilitates a way to push stock to Magento from a configurable source. Both simple stock and MSI are supported.

Features

This package provides all the logic of pushing stock to Magento. It only requires an implementation for retrieving the stock.

Features:

  • Retrieve stock from any source
  • MSI support
  • Only update stock when there are modifications
  • Automatically stop syncing when there are too many errors (configurable)
  • Compare stock between Magento and this package
  • Supports Magento 2 async bulk requests for updating stock using Laravel Magento Async
  • Logs activities using Spatie activitylog
  • Checks if Magento products exist using JustBetter Magento Products

Also check out our other Laravel Magento packages! We also have a Magento Client to easily connect Laravel to Magento!

Installation

Require this package: composer require justbetter/laravel-magento-stock

Publish the config

php artisan vendor:publish --provider="JustBetter\MagentoStock\ServiceProvider" --tag="config"

Publish the activity log's migrations:

php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"

Run migrations.

php artisan migrate

TIP: All actions in this package are run via jobs, we recommend Laravel Horizon or another queueing system to run these

Add the following commands to your scheduler.

    protected function schedule(Schedule $schedule): void
    {
       // Process stocks marked for retrieval / update
       $schedule->command(\JustBetter\MagentoStock\Commands\ProcessStocksCommand::class)->everyMinute();

       // Retrieve all stock daily
       $schedule->command(\JustBetter\MagentoStock\Commands\Retrieval\RetrieveAllStockCommand::class)->dailyAt('05:00');

       // Retrieve modified stock every fifteen minutes, with a small overlap
       $schedule->command(\JustBetter\MagentoStock\Commands\Retrieval\RetrieveAllStockCommand::class, ['now -1 hour'])->everyFifteenMinutes();
    }

Laravel Nova

We have a Laravel Nova integration for this package.

Setup

This package requires you to implement a stock repository which is responsible for retrieving stock.

Retrieving stock

Implement the retrieve method and return a StockData object that contains the stock fields.

<?php

namespace App\Integrations\MagentoStock;

use JustBetter\MagentoStock\Repositories\Repository;
use JustBetter\MagentoStock\Data\StockData;
use JustBetter\MagentoStock\Enums\Backorders;

class MyStockRepository extends Repository
{
    public function retrieve(string $sku): ?StockData
    {
        // Retrieve stock from your source

        return StockData::of([
            'sku' => $sku,
            'quantity' => 10,
            'in_stock' => true,
            'backorders' => Backorders::BackordersNotify,
        ]);
    }
}

Retrieving SKU's

By default the Repository that you are extending will retrieve the SKU's from justbetter/laravel-magento-products. If you wish to use this you have to add the commands to your scheduler to automatically import products.

If you have another source for your SKU's you may implement the skus method yourself. It accepts an optional carbon instance to only retrieve modified stock.

<?php

namespace App\Integrations\MagentoStock;

use JustBetter\MagentoStock\Repositories\Repository;
use Illuminate\Support\Carbon;
use Illuminate\Support\Enumerable;

class MyStockRepository extends Repository
{
    public function skus(?Carbon $from = null): ?Enumerable
    {
        return collect(['sku_1', 'sku_2']);
    }
}

Configuring the repository

The repository class has a couple of settings that you can adjust:

class BaseRepository
{
    protected string $name = 'Repository';

    // How many stocks may be retrieved at once when the process job runs
    protected int $retrieveLimit = 250;

    // How many stocks may be updated at once when the process job runs
    protected int $updateLimit = 250;

    // How many times an update to Magento may fail before it stops trying
    protected int $failLimit = 3;

    // If MSI is enabled
    protected bool $msi = false;

    // Enable if the package should update backorders
    protected bool $backorders = false;
}

After you've created and configured the repository you have to set it in your configuration file:

<?php

return [
    'repository' => \App\Integrations\MagentoStock\MyStockRepository::class,
];

Usage

To retrieve stock you can use the following commands.

Processing stocks that are marked for retrieval/update

php artisan magento-stock:process

Each stock record has two flags, retrieve and update. This command will dispatch the jobs to run those actions. It is primarily used for updates, but you can implement the retrieve flag in your application to slow down retrievals.

Retrieving stock for a single SKU

php artisan magento-stock:retrieve {sku}

This will directly pass the SKU to your repository and process the result. If the stock has been modified it will set the update flag.

Retrieving stock for all or modified SKU's

php artisan magento-stock:retrieve-all {from?}

This will call the skus method on your repository and dispatch retrieval jobs for all the SKU's that are returned from your repository.

Updating stock for a single SKU

php artisan magento-stock:update {sku}

Updating all stock

php artisan magento-stock:update-all

Comparing stock

php artisan magento-stock:compare

This will compare the stock in Magento and the database table. If it differs it will force an update to Magento.

Magento MSI

If you have Magento MSI enabled you have to return the quantity and status of each source in the repository.

NOTE: Be sure to set the msi setting in the repository to true!

For example:

<?php

namespace App\Integrations\MagentoStock;

use JustBetter\MagentoStock\Repositories\Repository;
use JustBetter\MagentoStock\Data\StockData;
use JustBetter\MagentoStock\Enums\Backorders;

class MyStockRepository extends Repository
{
    public function retrieve(string $sku): ?StockData
    {
        return StockData::of([
            'sku' => $sku,
            'backorders' => Backorders::BackordersNotify,
            'msi_status' => [
                'A' => true, // Source A is in stock
                'B' => false, // Source B is out of stock
            ],
            'msi_quantity' => [
                'A' => 10, // Source A has qty of 10
                'B' => 0, // Source B has qty of 0
            ],
        ]);
    }
}

Comparisons

This feature requires job batching

This package provides a way to compare stock quantities in Magento with those in the Laravel database. If a difference is detected it will start an update for that product.

An event is dispatched when a difference is detected \JustBetter\MagentoStock\Events\DifferenceDetectedEvent.

Handling failures

When an update fails it will try again. A fail counter is stored with the model which is increased at each failure. In the repository you can specify how many times the update may be attempted. You can restart the updates for a product by setting the sync field in the DB to true.

Quality

To ensure the quality of this package, run the following command:

composer quality

This will execute three tasks:

  1. Makes sure all tests are passed
  2. Checks for any issues using static code analysis
  3. 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 logo

justbetter/laravel-magento-stock 适用场景与选型建议

justbetter/laravel-magento-stock 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 19.94k 次下载、GitHub Stars 达 12, 最近一次更新时间为 2022 年 10 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 justbetter/laravel-magento-stock 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 justbetter/laravel-magento-stock 我们能提供哪些服务?
定制开发 / 二次开发

基于 justbetter/laravel-magento-stock 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 12
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-10-24