netflex / commerce
Netflex Commerce 库
v5.0.2
2024-08-16 15:57 UTC
Requires
- php: ^7.4|^8.0
- illuminate/support: ^8.0
- netflex/api: ^4.33
- netflex/query-builder: ^4.33
- netflex/support: ^4.33
Requires (Dev)
- illuminate/cache: ^8.0
- illuminate/container: ^8.0
- illuminate/filesystem: ^8.0
- larapack/dd: ^1.1
- vlucas/phpdotenv: ^5.2
- v5.0.2
- v5.0.1
- v5.0.0
- v4.47.1
- v4.47.0
- v4.46.0
- v4.45.1
- v4.45.0
- v4.44.5
- v4.44.4
- v4.44.3
- v4.44.2
- v4.44.1
- v4.44.0
- v4.43.0
- v4.42.0
- v4.41.0
- v4.40.2
- v4.40.1
- v4.40.0
- v4.34.1
- v4.34.0
- dev-master / 4.33.x-dev
- v4.33.6
- v4.33.5
- v4.33.4
- v4.33.3
- v4.33.2
- v4.33.1
- v4.33.0
- v4.32.3
- 4.32.2
- 4.32.1
- v4.32.0
- 4.31.6
- v4.31.5
- v4.31.4
- 4.31.3
- v4.31.2
- v4.31.1
- v4.31.0
- v4.30.0
- 4.29.2
- v4.29.1
- v4.29.0
- 4.28.8
- 4.28.7
- 4.28.6
- 4.28.5
- 4.28.4
- 4.28.3
- 4.28.2
- v4.27.0
- v4.21.1
- v4.21.0
- v4.20.3
- v4.20.2
- v4.20.1
- 4.20.0
- 4.19.6
- 4.19.5
- 4.19.4
- 4.19.3
- 4.19.2
- 4.19.1
- 4.19.0
- v4.18.5
- 4.18.4
- 4.18.3
- 4.18.2
- 4.18.1
- 4.18.0
- 4.17.6
- 4.17.5
- 4.17.4
- 4.17.3
- 4.17.2
- 4.17.1
- 4.17.0
- v4.16.1
- 4.16.0
- v4.15.9
- v4.15.8
- 4.15.7
- 4.15.6
- 4.15.5
- 4.15.4
- 4.15.3
- 4.15.2
- 4.15.1
- 4.15.0
- v4.14.1
- v4.14.0
- 4.13.4
- 4.13.3
- 4.13.2
- 4.13.1
- 4.13.0
- 4.12.25
- 4.12.24
- 4.12.23
- 4.12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.0.0-RC3
- v2.0.0-RC2
- v2.0.0-RC1
- 1.x-dev
- v1.0.0
- 0.x-dev
- v0.2.1
This package is auto-updated.
Last update: 2024-09-16 16:05:49 UTC
README
[只读] Netflex Commerce 组件的子树拆分(见 netflex/framework)
Netflex Commerce 库用于与 Netflex API 中的商业端点交互。
安装
composer require netflex/commerce
快速开始 TL;DR
// Creating new order and checking out $order = Order::create() ->addToSession() ->addCart([ 'entry_id' => 10001, 'entry_name' => 'Ticket', 'variant_cost' => 100, 'no_of_entries' => 1, 'tax_percent' => 1.12 ]) ->checkout([ 'firstname' => 'Ola', 'surname' => 'Nordmann' ]) ->save([ 'status' => 'p', 'currency' => 'NOK', 'customer_mail' => 'ola@nordmann.no', 'customer_phone' => '99123456' ]) ->addData('paymentId', '123456789', 'Payment ID') ->addLog('Customer sent to payment'); // Adding payment and completing order $order = Order::retrieveBySecret('a72b...12f4') ->addLog('Customer returned from payment') ->addPayment([ 'payment_method' => 'stripe', 'amount' => 100, 'status' => 'OK', 'capture_status' => 'OK', 'transaction_id' => '123456789', 'card_type_name' => 'visa', ]) ->register() ->lock() ->removeFromSession();
正确开始
始终从订单对象开始。订单是本库的主要类,旨在包含所有其他对象。
// Empty object. Does NOT create an order in the API. $order = new Order(); // Creating and getting a new empty order in the API. $order = Order::create(); // Retrieves an existing order from the API based on an order id. Throws an exception if not found. $order = Order::retrieve(10001); // Retrieves an existing order from the API based on a register id. Throws an exception if not found. $order = Order::retrieveByRegisterId(10001); // Retrieves an existing order from the API based on an order secret. Throws an exception if not found. $order = Order::retrieveBySecret('a1234567896e8bf63bbd43e851811234'); // Retrieves an existing order from the API based on an order secret stored in $_SESSION. // If session or order does not exist, it creates an empty object. // It does NOT create a new empty order in the API. // On the next save() or refresh(), it stores the order secret in session. $order = Order::retrieveBySession(); // Retrieves an existing order from the API based on an order secret stored in $_SESSION. // If session or order does not exist, it creates a new empty order in the API // and stores the order secret in session. $order = Order::retrieveBySessionOrCreate(); // Manually adding the order secret to session. $order->addToSession();
向订单中添加内容
在下面的所有添加方法中,数据将立即发送到 API。要更新订单对象以包含添加的项目和计算出的总计,您需要调用 refresh() 方法。
$order->addCart([ 'entry_id' => 10001, 'entry_name' => 'Ticket', 'variant_cost' => 100, 'no_of_entries' => 1, 'tax_percent' => 1.12, 'properties' => [ 'someCustomKey' => 'someCustomValue' ] ]); $order->addLog('This is a log item'); $order->addLogInfo('Log some info'); $order->addLogWarning('Log a warning'); $order->addLogSuccess('Log a success'); $order->addLogDanger('Log danger'); $order->addData('key', 'value', 'Label'); $order->addDiscount([ 'scope' => 'item', // cart|item|shipping 'scope_key' => '10001', // cart item id 'label' => '20 % discount on your ticket', 'discount' => 0.20, 'type' => 'percent', // percent|fixed|amount ]); $order->addPayment([ 'payment_method' => 'stripe', 'amount' => 100, 'status' => 'OK', 'capture_status' => 'OK', 'transaction_id' => '123456789', 'card_type_name' => 'visa', 'data' => [ 'someCustomKey' => 'someCustomValue' ] ]); // Updating the order object with added items and calculated totals $order->refresh();
在大多数添加方法中也可以传入 Item 对象。
$cartItem = new CartItem(); $cartItem->entry_id = 10001; $cartItem->entry_name = 'Ticket'; $cartItem->variant_cost = 100; $cartItem->no_of_entries = 1; $cartItem->tax_percent = 1.12; $order->addCart($cartItem);
更新订单
更新主订单对象的属性。选项 A
$order->status = 'p'; $order->currency = 'NOK'; $order->customer_mail = 'ola@nordmann.no'; $order->customer_phone = '99123456'; $order->save();
选项 B
$order->save([ 'status' => 'p', 'currency' => 'NOK', 'customer_mail' => 'ola@nordmann.no', 'customer_phone' => '99123456' ]);
更新购物车项目。选项 A
// Updating the number of entries on cart items with a specific entry_id foreach ($order->cart->items as $item) { if ($item->entry_id == 10001) { $item->no_of_entries = 5; $item->save(); } }
选项 B
foreach ($order->cart->items as $item) { if ($item->entry_id == 10001) { $item->save(['no_of_entries' => 5]); } }
结账并完成订单
$order->checkout([ 'firstname' => 'Ola', 'surname' => 'Nordmann' ]); $order->register(); $order->saveStatus('n'); $order->checkoutEnd(); // This does the same as saveStatus('n') and checkoutEnd(); // Saves the status to 'n' and add a checkout_end date. $order->lock(); $order->removeFromSession();
搜索查询构建器
此包使用Netflex QueryBuilder 库,因此您可以轻松搜索并返回一组订单。
$orders = Order::where('data.someCustomKey', 'someCustomValue')->get();
贡献
感谢您考虑为 Netflex Commerce 库做出贡献!请阅读贡献指南。
行为准则
为了确保社区对所有成员都友好,请审查并遵守行为准则。
许可
Netflex Commerce 库是开源软件,根据MIT 许可证许可。
版权 © 2020 Apility AS