定制 neimarperez/laravel-woocommerce 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

neimarperez/laravel-woocommerce

Composer 安装命令:

composer require neimarperez/laravel-woocommerce

包简介

WooCommerce Rest API with Laravel

README 文档

README

WooCommerce Rest API for Laravel. You can Get, Create, Update and Delete your woocommerce product using this package easily.

#Install

composer require codexshaper/laravel-woocommerce

#Publish config file

php artisan vendor:publish --tag=woocommerce

#Add API credentials in your .env file

WOOCOMMERCE_STORE_URL=YOUR_WEBSITE_URL
WOOCOMMERCE_CONSUMER_KEY=API_CONSUMER_KEY
WOOCOMMERCE_CONSUMER_SECRET=API_CONSUMER_SECRET

#Do you need any help to create your own API credentials? Read the officials Doc https://docs.woocommerce.com/document/woocommerce-rest-api/

Example for Product

#Retrieve Product(s)

use Codexshaper\WooCommerce\Facades\Product;

public function products()
{
  return Product::all();
}

public function product( Request $request )
{
  $product = Product::find($request->id);
}

#Create new Product

// For Simple Product
$data = [
    'name'              => 'Simple Product', // Product Name or Title
    'type'              => 'simple', // Product type simple|variable
    'regular_price'     => '100', // Regular Price
    'sale_price'        => '', // Price after offer
    'description'       => 'Product Description', // Product Long Description
    'short_description' => 'Product Short Description', // Product Short Description
    // Set Categories as an array
    'categories'        => [
        [
            'id' => 1,
        ],
        [
            'id' => 3,
        ],
    ],
    // Set thumnail images as an array
    'images'            => [
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
        ],
        [
            'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
        ],
    ],
];

// For Variable Product
$data = [
            'name'               => 'Variable Product', // Product Name pr Title
            'type'               => 'variable', // Product Type simple|variable
            'description'        => 'Product Description', // Product Long Description
            'short_description'  => 'Product Summery', // Product Short Description
            // Product Categories
            'categories'         => [
                [
                    'id' => 9,
                ],
                [
                    'id' => 14,
                ],
            ],
            // Product images
            'images'             => [
                [
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_front.jpg',
                ],
                [
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_4_back.jpg',
                ],
                [
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_front.jpg',
                ],
                [
                    'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_3_back.jpg',
                ],
            ],
            // Product Attributes
            'attributes'         => [
                [
                    'id'        => 6,
                    'position'  => 0,
                    'visible'   => false,
                    'variation' => true,
                    'options'   => [
                        'Black',
                        'Green',
                    ],
                ],
                [
                    'name'      => 'Size',
                    'position'  => 0,
                    'visible'   => true,
                    'variation' => true,
                    'options'   => [
                        'S',
                        'M',
                    ],
                ],
            ],
            // Set Default attributes
            'default_attributes' => [
                [
                    'id'     => 6,
                    'option' => 'Black',
                ],
                [
                    'name'   => 'Size',
                    'option' => 'S',
                ],
            ],
        ];

// Create a product using create() method
$product = Product::create($data);

// Create a product using save() method
$categories = [
    [
        'id' => 1,
    ],
    [
        'id' => 3,
    ],
];

$images = [
    [
        'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg',
    ],
    [
        'src' => 'http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_back.jpg',
    ],
];

$product                    = new Product;
$product->name              = 'Product Eloquent 2';
$product->type              = 'simple';
$product->regular_price     = '100';
$product->sale_price        = '50';
$product->description       = 'Product Description';
$product->short_description = 'Product Short Description';
$product->categories        = $categories;
$product->images            = $images;
$product->save();

#Update existing Product

$product_id = 40;
$data       = [
    'regular_price' => '50',
    'sale_price'    => '25', // 50% off
];

$product = Product::update($product_id, $data);

#Delete a Product

$product_id = 40;

$options = ['force' => true]; // Set force option true for delete permanently. Default value false

$product = Product::delete($product_id, $options);

Example for Order

#Create Order

$data = [
    'payment_method'       => 'bacs',
    'payment_method_title' => 'Direct Bank Transfer',
    'set_paid'             => true,
    'billing'              => [
        'first_name' => 'John',
        'last_name'  => 'Doe',
        'address_1'  => '969 Market',
        'address_2'  => '',
        'city'       => 'San Francisco',
        'state'      => 'CA',
        'postcode'   => '94103',
        'country'    => 'US',
        'email'      => 'john.doe@example.com',
        'phone'      => '(555) 555-5555',
    ],
    'shipping'             => [
        'first_name' => 'John',
        'last_name'  => 'Doe',
        'address_1'  => '969 Market',
        'address_2'  => '',
        'city'       => 'San Francisco',
        'state'      => 'CA',
        'postcode'   => '94103',
        'country'    => 'US',
    ],
    'line_items'           => [
        [
            'product_id' => 40,
            'quantity'   => 2,
        ],
        [
            'product_id'   => 127,
            'variation_id' => 23,
            'quantity'     => 1,
        ],
    ],
];

$order = Order::create($data);

#Retrieve Order(s)

use Codexshaper\WooCommerce\Facades\Order;

public function orders()
{
  $orders = Order::all();
}

public function order( Request $request )
{
  $order = Order::find($request->id);
}

#Update Order

$order_id = 173;
$data     = [
    'status' => 'completed',
];

$order = Order::update($order_id, $data);

#Delete an order

$order_id = 173;
$options = ['force' => true]; // Set force option true for delete permanently. Default value false

$order = Order::delete($order_id, $options);

#Create a note for a specific order

$order_id = 172;
$data = [
    'note' => 'Add your note',
];
$createNote = Order::createNote($order_id, $data);

#Get a note for sepcific order

$order_id = 172;
$note_id  = 67;

$note = Order::note($order_id, $note_id);

#Get all notes for sepcific order

$order_id = 172;
$options = [];
$notes = Order::notes($order_id, $options);

#Delete a note for sepcific order

$order_id = 172;
$note_id  = 67;
$options = [];

$note = Order::deleteNote($order_id, $note_id, $options);

#Create a Refund for a specific order

$order_id = 172;
$data = [
    'amount' => '10'
];
$createNote = Order::createRefund($order_id, $data);

#Get Refund for sepcific order

$order_id = 172;
$refund_id  = 117;

$refund = Order::refund($order_id, $refund_id);

#Get all Refunds for sepcific order

$order_id = 172;
$options = [];
$refunds = Order::refunds($order_id, $options);

#Delete Refund for sepcific order

$order_id = 172;
$refund_id  = 67;
$options = [];

$refund = Order::deleteRefund($order_id, $refund_id, $options);

Example for Customer

#Create Customer

$data = [
    'email'      => 'john.doe@example.com',
    'first_name' => 'John',
    'last_name'  => 'Doe',
    'username'   => 'john.doe',
    'billing'    => [
        'first_name' => 'John',
        'last_name'  => 'Doe',
        'company'    => '',
        'address_1'  => '969 Market',
        'address_2'  => '',
        'city'       => 'San Francisco',
        'state'      => 'CA',
        'postcode'   => '94103',
        'country'    => 'US',
        'email'      => 'john.doe@example.com',
        'phone'      => '(555) 555-5555',
    ],
    'shipping'   => [
        'first_name' => 'John',
        'last_name'  => 'Doe',
        'company'    => '',
        'address_1'  => '969 Market',
        'address_2'  => '',
        'city'       => 'San Francisco',
        'state'      => 'CA',
        'postcode'   => '94103',
        'country'    => 'US',
    ],
];
$customer = Customer::create($data);

#Retreive Customer(s)

use Codexshaper\WooCommerce\Facades\Customer;

public function customers()
{
  return Customer::all();
}

public function customer( Request $request )
{
  $customer = Customer::find($request->id);
}

#Update Customer

$customer_id = 2;
$data        = [
    'first_name' => 'James',
    'billing'    => [
        'first_name' => 'James',
    ],
    'shipping'   => [
        'first_name' => 'James',
    ],
];

$customer = Customer::update($customer_id, $data);

#Delete Customer

$customer_id = 2;
$options     = ['force' => true]; // Set force option true for delete permanently. Default value false

$customer = Customer::delete($customer_id, $options);

Eloquent Style for Product, Customer and Order

// Where passing multiple parameters
$orders = Order::where('status', 'publishing')->get();
$orders = Order::where('total', '>=', 10)->get();

// Where passing an array
$orders = Order::where(['status' => 'processing']);
$orders = Order::where(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc'])->get();

// Order with where
$orders = Order::where('total', '>=', 10)->orderBy('id', 'asc')->get();

// Set Options
$orders = Order::options(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc'])->get();

// You can set options by passing an array when call `all` method
$orders = Order::all(['status' => 'processing', 'orderby' => 'id', 'order' => 'asc']);

#Product Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#products

#Customer Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#customers

#Order Options: https://woocommerce.github.io/woocommerce-rest-api-docs/#orders

You can also use WooCommerce Facade

use Codexshaper\WooCommerce\Facades\WooCommerce;

public function products()
{
  return WooCommerce::all('products');
}

public function product( Request $request )
{
  $product = WooCommerce::find('products/'.$request->id);
}

public function orders()
{
  return WooCommerce::all('orders');
}

public function order( Request $request )
{
  $order = WooCommerce::all('orders/'.$request->id);
}

public function customers()
{
  return WooCommerce::all('customers');
}

public function customer( Request $request )
{
  $customer = WooCommerce::all('customers/'.$request->id);
}

Use Facade Alias

use WooCommerce // Same as use Codexshaper\WooCommerce\Facades\WooCommerce;
use Customer // Same as use Codexshaper\WooCommerce\Models\Customer;
use Order // Same as use Codexshaper\WooCommerce\Models\Order;
use Product // Same as Codexshaper\WooCommerce\Models\Product;

neimarperez/laravel-woocommerce 适用场景与选型建议

neimarperez/laravel-woocommerce 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 230 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「woocommerce」 「laravel-woocommerce」 「woocommerce-api」 「woocommerce-rest-api」 「laravel-woocommerce-api」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 neimarperez/laravel-woocommerce 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 neimarperez/laravel-woocommerce 我们能提供哪些服务?
定制开发 / 二次开发

基于 neimarperez/laravel-woocommerce 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 230
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 8
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 61
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-22