Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial Commit of MSI module #1

Merged
merged 6 commits into from
Mar 25, 2022
Merged

Initial Commit of MSI module #1

merged 6 commits into from
Mar 25, 2022

Conversation

rbnmulder
Copy link
Member

No description provided.

{
public function apply(Builder $builder, Model $model)
{
$stockId = config()->has('rapidez.stock_id') ? config('rapidez.stock_id') : $this->getInventoryStockId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe $stockId = config('rapidez.stock_id') ?? $this->getInventoryStockId(); is enough? 🤔

Copy link
Member

@indykoning indykoning Mar 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the config() helper should have a fallback attribute available so
$stockId = config('rapidez.stock_id', $this->getInventoryStockId()); should suffice 🙂
https://laravel.com/docs/8.x/helpers#method-config

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indykoning Changed to use fallback from config function itself.

{
public function apply(Builder $builder, Model $model)
{
$stockId = config()->has('rapidez.stock_id') ? config('rapidez.stock_id') : $this->getInventoryStockId();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Member Author

@rbnmulder rbnmulder Mar 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to use fallback from config function itself.

README.md Outdated
##Installation
```composer require rapidez/msi```

To expose the `stock_qty` to the product detail and overview page you can add the following configuration to the ```config/rapidez.php``` file:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference here would go out to this module having it's own config file. e.g. msi.php
You can see an example here https://github.com/rapidez/strapi/blob/master/src/StrapiServiceProvider.php
where it loads the config from /config/strapi.php and if you publish the config you can override those values

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would still need to do what @rbnmulder says here to have this var available in the JS. look here: https://github.com/rapidez/core/blob/master/config/rapidez.php#L23

Copy link
Member Author

@rbnmulder rbnmulder Mar 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indykoning I made an msi config with a preset of default for exposing stock.

public function handle($request, Closure $next)
{
$stockId = DB::table('inventory_stock_sales_channel')
->where('inventory_stock_sales_channel.type', 'website')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know this will always be website? If so this will be fine, if not perhaps we could use the mage_run_type
https://devdocs.magento.com/guides/v2.4/config-guide/multi-site/ms_over.html#:~:text=variables%20as%20follows%3A-,MAGE_RUN_TYPE,-can%20be%20either

If i remember correctly this is store by default

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indykoning according to Magento it should be possible to match a stocks with websit, customer, groups, etc. to form a sales channel. But I can't seem to find the proper documentation for that. I currently can set website and it's also the default type. https://github.com/magento/inventory/blob/develop/InventorySalesApi/Api/Data/SalesChannelInterface.php#L29

* @param Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could cache the result in the user's session or something similar somehow.
I don't expect this to change much while someone is using the website and it saves on a query running every request

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated this part of the PR with a cache layer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@indykoning I added the website_id to the cache key. You raised a good point.

*/
public function handle($request, Closure $next)
{
$stockId = Cache::rememberForever('stock_id', function () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be best to add the website id to the cache key in order to prevent the incorrect stock id returning for the different websites

@royduin royduin merged commit 3f2aeaf into rapidez:master Mar 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants