riesenia / pohoda
Pohoda XML 通信
v1.20.0
2024-09-09 18:22 UTC
Requires
- php: ^7.1 || ^8.0
- symfony/options-resolver: ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- friends-of-phpspec/phpspec-expect: *
- friendsofphp/php-cs-fixer: ^2.0
- phpspec/phpspec: ^5.0 || ^6.0 || ^7.0
- rshop/php-cs-fixer-config: ^2.0
- dev-master
- v1.20.0
- v1.19.2
- v1.19.1
- v1.19.0
- v1.18.3
- v1.18.2
- v1.18.1
- v1.18.0
- v1.17.2
- v1.17.1
- v1.17.0
- v1.16.4
- v1.16.3
- v1.16.2
- v1.16.1
- v1.16.0
- v1.15.1
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.1
- v1.8.0
- v1.7.0
- v1.6.2
- v1.6.1
- v1.6.0
- v1.5.1
- v1.5
- v1.4.12
- v1.4.11
- v1.4.10
- v1.4.9
- v1.4.8
- v1.4.7
- v1.4.6
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.4
- v1.3.3
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- v0.1.1
- v0.1.0
- dev-old
This package is auto-updated.
Last update: 2024-09-10 06:44:32 UTC
README
安装
将 composer.json 中的内容添加进来
{ "require": { "riesenia/pohoda": "~1.0" } }
使用命令
composer require 'riesenia/pohoda:~1.0'
订单导入示例
导入各种类型的示例,请参阅 spec 文件夹。
use Riesenia\Pohoda; $pohoda = new Pohoda('ICO'); // create file $pohoda->open($filename, 'i_obj1', 'Import orders'); // create order $order = $pohoda->createOrder([ 'numberOrder' => $order_number, 'isReserved' => true, 'date' => $created, 'text' => '...', 'partnerIdentity' => [ 'address' => [ 'name' => $billing_name, 'street' => $billing_street, 'city' => $billing_city, 'zip' => $billing_zip, 'email' => $email, 'phone' => $phone ], 'shipToAddress' => [ 'name' => $shipping_name, 'street' => $shipping_street, 'city' => $shipping_city, 'zip' => $shipping_zip, 'email' => $email, 'phone' => $phone ] ] ]); // add items foreach ($items as $item) { $order->addItem([ 'code' => $item->code, 'text' => $item->text, 'quantity' => $item->quantity, 'payVAT' => false, 'rateVAT' => $item->rate, 'homeCurrency' => [ 'unitPrice' => $item->unit_price ], 'stockItem' => [ 'stockItem' => [ 'id' => $item->pohoda_id ] ] ]); } // add summary $order->addSummary([ 'roundingDocument' => 'none' ]); // add order to import (identified by $order_number) $pohoda->addItem($order_number, $order); // finish import file $pohoda->close();
库存导出示例
通过创建 ListRequest 来实现导出命令的创建。
use Riesenia\Pohoda; $pohoda = new Pohoda('ICO'); // create request for export $pohoda->open($filename, 'e_zas1', 'Export stock'); $request = $pohoda->createListRequest([ 'type' => 'Stock' ]); // optional filter $request->addUserFilterName('MyFilter'); $pohoda->addItem('Export 001', $request); $pohoda->close();
数据处理本身很简单 - 调用 next
返回包含特定实体的 SimpleXMLElement。
// load file $pohoda->loadStock($filename); while ($stock = $pohoda->next()) { // access header $header = $stock->children('stk', true)->stockHeader; // ... }
库存删除示例
删除时,需要创建一个空数据议程并设置其 delete actionType。
use Riesenia\Pohoda; $pohoda = new Pohoda('ICO'); // create request for deletion $pohoda->open($filename, 'd_zas1', 'Delete stock'); $stock = $pohoda->createStock([]); $stock->addActionType('delete', [ 'code' => $code ]); $pohoda->addItem($code, $stock); $pohoda->close();
使用 ValueTransformer 修改值
通过 ValueTransformer 接口,我们可以实现一个变换器,该变换器可以更改所有数据。以下是将所有值修改为大写的示例。
use Riesenia\Pohoda; class Capitalizer implements \Riesenia\Pohoda\ValueTransformer\ValueTransformer { public function transform(string $value): string { return \strtoupper($value); } } // Register the capitalizer to be used to capitalize values Pohoda::$transformers[] = new Capitalizer(); $pohoda = new Pohoda('ICO'); ...