corcel/woocommerce

Corcel 的 WooCommerce 插件

v5.0.1 2024-06-16 17:00 UTC

This package is auto-updated.

Last update: 2024-09-16 17:29:35 UTC


README

Corcel WooCommerce logo

WooCommerce 的 Laravel 模型集合。

此插件扩展了基础 Corcel 包,并允许从 WordPress 数据库中获取 WooCommerce 数据。目前此插件实现了以下模型

  • 客户 - 用户模型的包装器
  • 订单 - 帖子模型的包装器
  • 产品 - 帖子模型的包装器
  • 项目
  • 产品分类 - 分类模型的包装器
  • 产品标签 - 分类模型的包装器
  • 产品属性 - 获取产品属性的辅助模型(不应直接使用)
  • 产品类型 - 获取产品类型的辅助模型(不应直接使用)

一些元值收集到辅助类中

兼容性列表

安装

composer require corcel/woocommerce

模型列表

客户模型

按 ID 获取客户

$customer = Customer::find(1);

客户关系

$customer = Customer::find(1);

$customerOrders = $customer->orders;

客户属性

$customer = Customer::find(1);

$customer->order_count;      // e.g. 10
$customer->billing_address;  // \Corcel\WooCommerce\Support\BillingAddress class instance
$customer->shipping_address; // \Corcel\WooCommerce\Support\ShippingAddress class instance

订单模型

按 ID 获取订单

$order = Order::find(1);

获取完成的订单

$completedOrders = Order::completed()->get();

对于其他状态的方法,请查看 OrderBuilder.php

订单关系

$order = Order::find(1);

$orderItems    = $order->items;
$orderCustomer = $order->customer;

订单属性

$order = Order::find(1);

$order->currency;         // e.g. EUR
$order->total;            // e.g. 10.20
$order->tax;              // e.g. 0.50
$order->shipping_tax;     // e.g. 0.20
$order->status;           // e.g. completed
$order->date_completed;   // e.g. 2020-06-01 10:00:00
$order->date_paid;        // e.g. 2020-06-01 10:00:00
$order->payment;          // \Corcel\WooCommerce\Support\Payment class instance
$order->billing_address;  // \Corcel\WooCommerce\Support\BillingAddress class instance
$order->shipping_address; // \Corcel\WooCommerce\Support\ShippingAddress class instance

项目模型

按 ID 获取项目

$item = Item::find(1);

项目关系

$item = Item::find(1);

$itemOrder   = $item->order;
$itemProduct = $item->product;

项目属性

$item = Item::find(1);

$item->order_item_id;
$item->order_item_name;
$item->order_item_type;
$item->order_id;
$item->product_id;
$item->variation_id;
$item->quantity;          // e.g. 2
$item->tax_class;
$item->line_subtotal;     // e.g. 5.50
$item->line_subtotal_tax; // e.g. 0.50
$item->line_total;        // e.g. 10.50
$item->line_tax;          // e.g. 2.00

产品模型

按 ID 获取产品

$product = Product::find(1);

产品关系

$product = Product::find(1);

$product->categories;
$product->items;
$product->tags;

产品属性

$product = Product::find(1);

$product->price;
$product->regular_price;
$product->sale_price;
$product->on_sale;
$product->sku;
$product->tax_status;
$product->is_taxable;
$product->weight;
$product->length;
$product->width;
$product->height;
$product->is_virtual;
$product->is_downloadable;
$product->stock;
$product->in_stock;
$product->type;
$product->attributes; // Collection of (variation) attributes
$product->crosssells; // Collection of cross-sell products
$product->upsells;    // Collection of up-sell products
$product->gallery;    // Collection of gallery attachments

辅助类列表

账单地址辅助类

此类收集与账单地址相关的客户和订单元数据。

$order   = Order::find(1);
$address = $order->billingAddress;

$address->first_name;
$address->last_name;
$address->company;
$address->address_1;
$address->address_2;
$address->city;
$address->state;
$address->postcode;
$address->country;
$address->email;
$address->phone;

配送地址辅助类

此类收集与账单地址相关的客户和订单元数据。

$order   = Order::find(1);
$address = $order->shippingAddress;

$address->first_name;
$address->last_name;
$address->company;
$address->address_1;
$address->address_2;
$address->city;
$address->state;
$address->postcode;
$address->country;

支付辅助类

此类收集与支付相关的订单元数据。

$order   = Order::find(1);
$payment = $order->payment;

$payment->method;
$payment->method_title;
$payment->transaction_id;