justbetter/laravel-magento-customer-prices

将客户特定价格推送到 Magento 的软件包

3.1.0 2024-09-10 06:44 UTC

README

Package banner

Laravel Magento Customer Prices

Tests Coverage Analysis Total downloads

此软件包提供了一种从 Laravel 应用程序向 Magento 添加客户特定价格的方法。默认情况下,它使用 JustBetter Magento 2 Customer Pricing 模块来处理客户特定价格。您可以实现另一个客户特定价格模块,请参阅 更新客户价格

特性

此软件包可以

  • 从任何来源检索价格
  • 将客户特定价格推送到 Magento
  • 只有在修改时才更新 Magento 中的价格。例如,当您十次检索同一价格时,它只更新一次到 Magento
  • 在更新失败时自动停止同步
  • 使用 Spatie activitylog 记录活动
  • 使用 JustBetter Magento Products 检查 Magento 产品是否存在

查看 Laravel Magento Prices 以连接常规价格到 Magneto。我们还有一个 Magento Client,可以轻松地将 Laravel 连接到 Magento!

安装

要求此软件包: composer require justbetter/laravel-magento-customer-prices

发布配置

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

发布活动日志的迁移

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

运行迁移

php artisan migrate

Laravel Nova

为此软件包提供 Laravel Nova 集成

用法

将以下命令添加到您的计划任务中

<?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();
}

检索客户价格

此软件包与一个检索每个 SKU 价格的存储库一起工作,您必须实现它。

存储库

此类负责检索产品的价格、检索 SKU 和设置。您的类必须扩展 \JustBetter\MagentoCustomerPrices\Repository\Repository 并实现 retrieve 方法。如果 SKU 没有价格,您可能返回 null。在其他所有情况下,您需要返回一个包含两个元素的 CustomerPriceData 对象

  • sku 必需
  • prices 可选,客户价格的数组
    • price 价格的浮点数
    • customer_id Magento 2 客户 ID
    • quantity 最小数量

您可以在 CustomerPriceData 类中查看规则,以了解您需要提供什么。

示例
<?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,
                ],
            ],
        ]);
    }
}

检索 SKU

默认情况下,您所扩展的 Repository 将从 justbetter/laravel-magento-products 中检索 SKU。如果您想使用它,您必须将命令添加到您的计划任务中,以自动导入产品。

如果您有其他来源的 SKU,您可以自己实现 skus 方法。它接受一个可选的 carbon 实例,以仅检索修改后的库存。

<?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']);
    }
}

配置存储库

存储库类有一些您可以调整的设置

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;
}

在您创建并配置存储库后,您必须在配置文件中将其设置好

<?php

return [
    'repository' => \App\Integrations\MagentoCustomerPrices\MyPriceRepository::class,
];

Magento 2 客户价格

默认情况下,此包使用JustBetter Magento 2 Customer Pricing模块来更新价格到Magento。如果您使用其他针对特定客户的Magento 2模块,您可以编写自己的类来更新Magento中的价格。您可以通过实现JustBetter\MagentoCustomerPrices\Contracts\Update\UpdatesCustomerPrice来完成此操作。有关示例,请参阅\JustBetter\MagentoCustomerPrices\Actions\Update\UpdateCustomerPrice

不要忘记绑定您自己的类!

<?php

app()->singleton(\JustBetter\MagentoCustomerPrices\Contracts\Update\UpdatesCustomerPrice::class, YourCustomUpdater::class);

质量

为确保此包的质量,请运行以下命令

composer quality

这将执行三个任务

  1. 确保所有测试都通过
  2. 使用静态代码分析检查任何问题
  3. 检查代码格式是否正确

贡献

请参阅CONTRIBUTING以获取详细信息。

安全漏洞

请审查我们的安全策略以了解如何报告安全漏洞。

致谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件

Package footer