justbetter/laravel-magento-customer-prices
Composer 安装命令:
composer require justbetter/laravel-magento-customer-prices
包简介
Package to push customer specific prices to Magento
README 文档
README
Laravel Magento Customer Prices
This package provides a way to add customer specific prices to Magento from a Laravel app. By default, it uses the JustBetter Magento 2 Customer Pricing module for customer specific prices. You can implement another customer specific price module, see Updating Customer Prices.
Features
This package can:
- Retrieve prices from any source
- Push customer specific prices to Magento
- Only update prices in Magento when are modified. i.e. when you retrieve the same price ten times it only updates once to Magento
- Automatically stop syncing when updating fails
- Logs activities using Spatie activitylog
- Checks if Magento products exist using JustBetter Magento Products
Check out Laravel Magento Prices for connecting regular prices to Magneto We also have a Magento Client to easily connect Laravel to Magento!
Installation
Require this package: composer require justbetter/laravel-magento-customer-prices
Publish the config
php artisan vendor:publish --provider="JustBetter\MagentoCustomerPrices\ServiceProvider" --tag="config"
Publish the activity log's migrations:
php artisan vendor:publish --provider="Spatie\Activitylog\ActivitylogServiceProvider" --tag="activitylog-migrations"
Run the migrations
php artisan migrate
Laravel Nova
We have a Laravel Nova integration for this package.
Usage
Add the following commands to your scheduler:
<?php protected function schedule(Schedule $schedule): void { $schedule->command(\JustBetter\MagentoCustomerPrices\Commands\ProcessCustomerPricesCommand::class)->everyMinute(); // Retrieve all customer prices daily $schedule->command(\JustBetter\MagentoCustomerPrices\Commands\Retrieval\RetrieveAllCustomerPricesCommand::class)->daily(); // Retrieve updated customer prices hourly $schedule->command(\JustBetter\MagentoCustomerPrices\Commands\Retriavel\RetrieveAllCustomerPricesCommand::class, ['from' => 'now - 1 hour'])->hourly(); }
Retrieving Customer Prices
This package works with a repository that retrieves prices per SKU which you have to implement.
Repository
This class is responsible for retrieving prices for products, retrieving sku's and settings.
Your class must extend \JustBetter\MagentoCustomerPrices\Repository\Repository and implement the retrieve method.
If there is no price for the SKU you may return null. In all other cases you need to return a CustomerPriceData object which contains two elements:
skuRequiredpricesOptional, array of customer pricespricefloat of the pricecustomer_idMagento 2 customer idquantityMinimum quantity
You can view the rules in the CustomerPriceData class to get an idea of what you need to provide.
Example
<?php namespace App\Integrations\MagentoCustomerPrices; use JustBetter\MagentoCustomerPrices\Data\CustomerPriceData; use JustBetter\MagentoCustomerPrices\Repository\Repository; class MyCustomerPriceRepository extends Repository { public function retrieve(string $sku): ?CustomerPriceData { return CustomerPriceData::of([ 'sku' => $sku, 'prices' => [ [ 'customer_id' => 1, 'price' => 10, 'quantity' => 1, ], [ 'customer_id' => 1, 'price' => 8, 'quantity' => 10, ], ], ]); } }
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\MagentoCustomerPrices; use JustBetter\MagentoCustomerPrices\Repositories\Repository; use Illuminate\Support\Carbon; use Illuminate\Support\Collection; class MyCustomerPriceRepository implements Repository { public function skus(?Carbon $from = null): Collection { return collect(['sku_1', 'sku_2']); } }
Configuring the repository
The repository class has a couple of settings that you can adjust:
class BaseRepository { // How many prices may be retrieved at once when the process job runs protected int $retrieveLimit = 250; // How many prices 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; }
After you've created and configured the repository you have to set it in your configuration file:
<?php return [ 'repository' => \App\Integrations\MagentoCustomerPrices\MyPriceRepository::class, ];
Magento 2 Customer Prices
By default, this package uses the JustBetter Magento 2 Customer Pricing module for updating prices to Magento.
If you use another Magento 2 module for customer specific pricing you can write your own class that updates prices in Magento.
You can do this by implementing JustBetter\MagentoCustomerPrices\Contracts\Update\UpdatesCustomerPrice.
See \JustBetter\MagentoCustomerPrices\Actions\Update\UpdateCustomerPrice for an example.
Don't forget to bind your own class!
<?php
app()->singleton(\JustBetter\MagentoCustomerPrices\Contracts\Update\UpdatesCustomerPrice::class, YourCustomUpdater::class);
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-customer-prices 适用场景与选型建议
justbetter/laravel-magento-customer-prices 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.86k 次下载、GitHub Stars 达 13, 最近一次更新时间为 2022 年 09 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 justbetter/laravel-magento-customer-prices 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 justbetter/laravel-magento-customer-prices 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 11.86k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-09-27