yassineche/laravel-dokan

Dokan-Laravel API 连接器包是一个强大的集成解决方案,它使得 WordPress 的 Dokan 插件与您的 Laravel API 之间能够无缝通信。此包让开发者能够轻松地同步和交换 WordPress 基础市场与 Laravel 后端之间的数据。

1.0.0 2023-07-19 13:22 UTC

This package is not auto-updated.

Last update: 2024-09-26 20:42:03 UTC


README

Laravel-Dokan 包是一个强大的集成解决方案,它使得 WordPress 的 Dokan 插件与您的 Laravel API 之间能够无缝通信。它允许开发者轻松地同步和交换 WordPress 基础市场与 Laravel 后端之间的数据。

主要特性

  • 易于与 WordPress 的 Dokan 插件集成。
  • WordPress 和 Laravel API 之间的无缝通信。
  • 市场与后端之间的数据同步。

安装

步骤 1:安装包

您可以通过 Composer 安装 Laravel-Dokan 包。在您的终端中运行以下命令

composer require yassineche/laravel-dokan

步骤 2:发布 Laravel-Dokan 配置

为了自定义和配置 Laravel-Dokan 包,您需要发布其配置文件。这将允许您根据需要修改包的设置。按照以下步骤操作

  • 打开您的终端或命令提示符。

  • 运行以下命令

    php artisan vendor:publish --provider="YassineChe\LaravelDokan\LaravelDokanServiceProvider" --tag=dokan

步骤 3:安装和配置 JWT 认证插件

为了使 Laravel-Dokan 包与您的 WordPress API 之间能够实现无缝通信,您需要安装和配置 JWT Authentication for WP REST 插件。此插件为您的 WordPress 安装提供了 JWT 认证功能。按照以下步骤操作

  • 1 - 在您的 WordPress 安装中安装 "JWT Authentication for WP REST" 插件。

  • 2 - 在 WordPress 管理仪表板中激活插件。

  • 3 - 配置插件设置。您可能需要生成一个密钥并设置认证端点 URL。

  • 4 - 保存更改并确保 JWT 认证已启用。

有关安装和配置 "JWT Authentication for WP REST" 插件的详细说明,您可以参考以下视频教程:JWT Authentication for WP REST 教程

一旦您成功安装并配置了 WordPress 的 JWT 认证,您就可以继续将其与 Laravel-Dokan 包集成。

步骤 4:配置 Laravel-Dokan 包

要配置 Laravel-Dokan 包,您需要编辑 dokan.php 配置文件。此文件包含各种选项,允许您自定义包的行为。按照以下步骤操作

  • 找到您的 Laravel 应用程序中的 config/dokan.php 文件。

  • 在文本编辑器中打开 dokan.php 文件。

  • 在文件中,您将找到一个名为 "STORE CONFIGURATION" 的部分。此部分包含以下配置选项

    • token:此选项应设置为生成的 JWT Authentication for WordPress 令牌。您可以通过按照步骤 2 中的说明获取此令牌。

    • store_url:此选项应设置为您的 WordPress 安装 URL。这是您的 Dokan 商店所在的基础 URL。

  • 根据您的特定配置更新 tokenstore_url 的值。确保保存更改。

一旦您编辑了 dokan.php 配置文件,Laravel-Dokan 包将正确配置以与您的 Dokan 商店通信。

用法

要使用Laravel-Dokan包,您可以利用提供的接口和类与Dokan API交互,从您的Dokan商店检索/存储数据。以下是如何在您的Laravel应用程序中使用该包的示例:

  • LaravelDokanProduct 门面
use LaravelDokanProduct;

try {
    // Get all products
    LaravelDokanProduct::getAllProducts();

    // Get a product by ID
    LaravelDokanProduct::getProduct($productId);

    // Delete a product by ID
    LaravelDokanProduct::deleteProduct($productId);

    // Update a product
    LaravelDokanProduct::updateProduct($productId, [
        'name' => 'Updated Product',
        'price' => 99.99,
    ]);

    // Get product summary
    LaravelDokanProduct::getProductSummary();

    // Create a new product
    LaravelDokanProduct::createProduct([
        'name' => 'New Product',
        'price' => 49.99,
    ]);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanProductVariations 门面
use LaravelDokanProductVariations;

try {
    // Create product variations for a specific product
    LaravelDokanProductVariations::createProductVariations($productId,[
            'name' => 'Variation 1',
            'price' => 9.99,
    ]);

    // Get all product variations for a specific product
    LaravelDokanProductVariations::getAllProductVariations($productId);

    // Get a specific product variation by its IDs
    LaravelDokanProductVariations::getProductVariation($productId, $variationId);

    // Update a specific product variation
    LaravelDokanProductVariations::updateProductVariation($productId, $variationId, $[
        'name' => 'Updated Variation',
        'price' => 29.99,
    ]);

    // Delete a specific product variation
    LaravelDokanProductVariations::deleteProductVariation($productId, $variationId);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanCoupon 门面
use LaravelDokanCoupon;

try {
    // Create a coupon
    LaravelDokanCoupon::createCoupon([
        'code' => 'SUMMER2023',
        'type' => 'percent',
        'amount' => 20,
    ]);

    // Update a coupon
    LaravelDokanCoupon::updateCoupon($couponId, [
        'type' => 'fixed_cart',
        'amount' => 10,
    ]);

    // Get a coupon by its ID
    LaravelDokanCoupon::getCoupon($couponId);

    // Get all coupons
    LaravelDokanCoupon::getAllCoupons();

    // Delete a coupon
    LaravelDokanCoupon::deleteCoupon($couponId);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanAttribute 门面
use LaravelDokanAttribute;

try {
    // Get all attributes
    LaravelDokanAttribute::getAllAttributes();

    // Get a specific attribute by ID
    LaravelDokanAttribute::getAttribute($attributeId);

    // Create a new attribute
    LaravelDokanAttribute::createAttribute([
        'name' => 'Color',
        'slug' => 'color',
        'type' => 'select',
        'values' => ['Red', 'Green', 'Blue'],
    ]);

    // Update an attribute
    LaravelDokanAttribute::updateAttribute($attributeId,[
        'name' => 'Size',
        'slug' => 'size',
        'type' => 'select',
        'values' => ['Small', 'Medium', 'Large'],
    ]);

    // Delete an attribute
    LaravelDokanAttribute::deleteAttribute($attributeId);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanAttributeTerm 门面
use LaravelDokanAttributeTerm;

try {

    // Get all attribute terms for a given attribute ID
    LaravelDokanAttributeTerm::getAllAttributeTerms($attributeId);

    // Get a specific attribute term by attribute ID and term ID
    LaravelDokanAttributeTerm::getAttributeTerms($attributeId, $termId);

    // Create a new attribute term for a given attribute ID
    LaravelDokanAttributeTerm::createAttributeTerm($attributeId, [
        'name' => 'New Term',
        'slug' => 'new-term',
    ]);

    // Update an attribute term for a given attribute ID and term ID
    LaravelDokanAttributeTerm::updateAttributeTerm($attributeId, $updatedTermId,[
        'name' => 'Updated Term',
        'slug' => 'updated-term',
    ]);

    // Delete an attribute term for a given attribute ID and term ID
    LaravelDokanAttributeTerm::deleteAttributeTerm($attributeId, $termIdToDelete);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanOrder 门面
use LaravelDokanOrder;

try {
    // Get all orders from the Dokan API
    LaravelDokanOrder::getAllOrders();

    // Get paginated orders from the Dokan API
    LaravelDokanOrder::getOrdersPaginations($perPage, $page);

    // Get a specific order from the Dokan API
    LaravelDokanOrder::getOrder($orderId);

    // Get orders summary from the Dokan API
    LaravelDokanOrder::getOrdersSummary();

    // Update an order in the Dokan API
    LaravelDokanOrder::updateOrder($orderIdToUpdate, 'completed');

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanOrderNote 门面
use LaravelDokanOrderNote;

try {
    // Create an order note in the Dokan API
    LaravelDokanOrderNote::createOrderNote($orderId, $noteProperties = [
        'note' => 'This is a test note',
        'customer_note' => false,
    ]);

    // Get all order notes for a specific order from the Dokan API
    LaravelDokanOrderNote::getAllOrderNote($orderId);

    // Get a specific order note for an order from the Dokan API
    LaravelDokanOrderNote::getOrderNote($orderId, $noteId);

    // Delete an order note from the Dokan API
    LaravelDokanOrderNote::deleteOrderNote($orderId, $noteId);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanReport 门面
use LaravelDokanReport;

try {
    // Get the summary of the report
    LaravelDokanReport::getReportSummary();

    // Get the sales overview report
    LaravelDokanReport::getReportSalesOverview();

    // Get the top earners report for a specific start date
    LaravelDokanReport::getReprotTopEarners('2023-07-01');

    // Get the top selling products report for a specific start date
    LaravelDokanReport::getReportTopSellingProduct('2023-07-01');

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanReview 门面
use LaravelDokanReview;

try {
    // Get all reviews
    LaravelDokanReview::getAllReviews();

    // Get the review summary
    LaravelDokanReview::getReviewSummary();

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanStore 门面
use LaravelDokanStore;

try {
    // Get all stores
    LaravelDokanStore::getAllStores();

    // Get a specific store by vendor ID
    LaravelDokanStore::getStore($vendor_id);

    // Get products of a specific store by vendor ID
    LaravelDokanStore::getStoreProducts($vendor_id);

    // Get reviews of a specific store by vendor ID
    LaravelDokanStore::getStoreReviews($vendor_id);

} catch (\Exception $e) {
    echo $e->getMessage();
}
  • LaravelDokanWithdraw 门面
use YassineChe\LaravelDokan\Facades\LaravelDokanWithdraw;

try {
    // Create a new withdraw
    LaravelDokanWithdraw::createWithdraw([
        // properties..
    ]);

    // Get the balance details
    LaravelDokanWithdraw::getBalanceDetails();

    // Get withdraws by status
    LaravelDokanWithdraw::getWithdrawByStatus($status);

    // Get all withdraws
    LaravelDokanWithdraw::getAllWithdraws();

} catch (\Exception $e) {
    echo $e->getMessage();
}

  • LaravelDokanSetting 门面
use LaravelDokanSetting;

try {
    // Get the current settings
    LaravelDokanSetting::getSettings();

    // Update the settings
    LaravelDokanSetting::updateSettings([
        // properties...
    ]);

} catch (\Exception $e) {
    echo $e->getMessage();
}

注意

  • 所有函数都返回创建、更新、删除或读取数据的数组。
  • 如果发生不良请求、没有数据或在Laravel-Dokan API中失败,将抛出DokanApiException异常。

结论

Laravel-Dokan包为在Laravel应用程序中与Dokan API交互提供了一套全面的类和接口。该包包括处理Dokan平台各个方面的模块,如订单、订单备注、报告、评论、商店、提现和设置...

在整个包中,方法旨在从Dokan API检索、创建、更新或删除数据。在成功的API调用后,方法返回包含相关数据的数组。然而,在发生不良请求、没有数据或在Dokan API中失败的情况下,该包将抛出DokanApiException异常。此异常提供了详细的错误信息,可以在您的应用程序中捕获和处理。

该包旨在提供Laravel和Dokan平台之间的无缝集成,使开发者能够利用Dokan功能构建强大的应用程序。它通过使用接口提供灵活性和可扩展性,使其易于定制和扩展以适应特定项目需求。

通过利用Laravel-Dokan包,开发者可以在与Dokan平台无缝集成的同时利用Laravel生态系统,从而有效地开发带有Dokan支持的电子商务应用程序。

希望这个总结能为您清楚地了解Laravel-Dokan包及其功能。

如果您遇到任何问题或对改进有建议,请随时在Laravel-Dokan包的GitHub仓库上提交问题。仓库是讨论、错误报告、功能请求和协作的中心场所。您的反馈对改进包和解决任何问题都很有价值。