PHPackages                             justbetter/laravel-magento-stock - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. justbetter/laravel-magento-stock

ActivePackage

justbetter/laravel-magento-stock
================================

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

2.3.8(2mo ago)1217.4k—6.5%21MITPHPPHP ^8.3CI passing

Since Oct 24Pushed 2mo ago3 watchersCompare

[ Source](https://github.com/justbetter/laravel-magento-stock)[ Packagist](https://packagist.org/packages/justbetter/laravel-magento-stock)[ RSS](/packages/justbetter-laravel-magento-stock/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (12)Versions (36)Used By (1)

[ ![Package banner](./art/banner.svg)](https://github.com/justbetter/laravel-magento-stock "JustBetter")Laravel Magento Stock
=====================

[](#laravel-magento-stock)

 [![Tests](https://camo.githubusercontent.com/fb21152361364a91d1b247562ac9b46fcad03d327290f8f29423e21204b8ae9d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d6d6167656e746f2d73746f636b2f74657374732e796d6c3f6c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-magento-stock) [![Coverage](https://camo.githubusercontent.com/f8381445316a4981d43c2c88d34595c1965c42b03a45e136d5229c09caa88050/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d6d6167656e746f2d73746f636b2f636f7665726167652e796d6c3f6c6162656c3d636f766572616765267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-magento-stock) [![Analysis](https://camo.githubusercontent.com/fc40b1e95522819c6cc5e9162c13279fd3c7dbcf2035dc19fbfacde02255fd9e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a7573746265747465722f6c61726176656c2d6d6167656e746f2d73746f636b2f616e616c7973652e796d6c3f6c6162656c3d616e616c79736973267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-magento-stock) [![Total downloads](https://camo.githubusercontent.com/a1105c98d6fe68bd4631510d64103435002a865da11c2bd8a66259f9a2929e82/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a7573746265747465722f6c61726176656c2d6d6167656e746f2d73746f636b3f636f6c6f723d626c7565267374796c653d666c61742d737175617265)](https://github.com/justbetter/laravel-magento-stock)

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

Features
--------

[](#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](https://github.com/justbetter/laravel-magento-async)
- Logs activities using [Spatie activitylog](https://github.com/spatie/laravel-activitylog)
- Checks if Magento products exist using [JustBetter Magento Products](https://github.com/justbetter/laravel-magento-products)

> Also check out our other [Laravel Magento packages](https://github.com/justbetter?q=laravel-magento)! We also have a [Magento Client](https://github.com/justbetter/laravel-magento-client) to easily connect Laravel to Magento!

Installation
------------

[](#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

[](#laravel-nova)

We have a [Laravel Nova integration](https://github.com/justbetter/laravel-magento-stock-nova) for this package.

Setup
-----

[](#setup)

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

### Retrieving stock

[](#retrieving-stock)

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

```
