thoaud/ongoing-warehouse-php
Composer 安装命令:
composer require thoaud/ongoing-warehouse-php
包简介
PHP client library for the Ongoing Warehouse Management System REST API
README 文档
README
A PHP client library for the Ongoing Warehouse Management System REST API. This library provides a convenient way to interact with the Ongoing WMS API from PHP applications.
Features
- Complete API Coverage: All Ongoing WMS REST API endpoints are supported
- Type Safety: Full PHP type hints and return type declarations
- PSR Standards: Compliant with PSR-7, PSR-18, and PSR-4
- Modern PHP: Requires PHP 7.4+ with modern features
- Composer Ready: Easy installation via Composer
- Well Documented: Comprehensive PHPDoc comments
Installation
Via Composer
composer require thoaud/ongoing-warehouse-php
Manual Installation
- Download the latest release
- Extract to your project directory
- Include the autoloader:
require_once 'path/to/ongoing-api-php/autoload.php';
Quick Start
Basic Configuration
<?php require_once 'vendor/autoload.php'; use OngoingAPI\Configuration; use OngoingAPI\Api\ArticlesApi; // Configure the API client $config = new Configuration(); $config->setHost('https://api.ongoingsystems.se/your-warehouse'); $config->setUsername('your-username'); $config->setPassword('your-password'); // Create an API instance $articlesApi = new ArticlesApi(null, $config);
Example: Get All Articles
<?php use OngoingAPI\Api\ArticlesApi; use OngoingAPI\Configuration; // Setup configuration $config = new Configuration(); $config->setHost('https://api.ongoingsystems.se/your-warehouse'); $config->setUsername('your-username'); $config->setPassword('your-password'); // Create API client $articlesApi = new ArticlesApi(null, $config); try { // Get all articles for a goods owner $articles = $articlesApi->articlesGetAll(123); // goods_owner_id = 123 foreach ($articles as $article) { echo "Article: " . $article->getArticleName() . "\n"; echo "Stock: " . $article->getInventoryInfo()->getSellableNumberOfItems() . "\n"; } } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Example: Create an Order
<?php use OngoingAPI\Api\OrdersApi; use OngoingAPI\Configuration; use OngoingAPI\Model\GetOrderModel; use OngoingAPI\Model\GetOrderLine; // Setup configuration $config = new Configuration(); $config->setHost('https://api.ongoingsystems.se/your-warehouse'); $config->setUsername('your-username'); $config->setPassword('your-password'); // Create API client $ordersApi = new OrdersApi(null, $config); try { // Create order model $order = new GetOrderModel(); $order->setOrderNumber('ORD-001'); $order->setGoodsOwnerId(123); // Add order line $orderLine = new GetOrderLine(); $orderLine->setRowNumber(1); $orderLine->setArticleNumber('ART-001'); $orderLine->setNumberOfItems(5); $order->setOrderLines([$orderLine]); // Create the order $result = $ordersApi->ordersPut($order); echo "Order created successfully!\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
API Endpoints
This library provides access to all Ongoing WMS API endpoints:
Articles
ArticlesApi- Manage articles, inventory, and article dataArticleItemsApi- Work with individual article items
Orders
OrdersApi- Create and manage customer ordersReturnOrdersApi- Handle return orders
Purchase Orders
PurchaseOrdersApi- Manage incoming purchase orders
Inventory
InventoryAdjustmentsApi- Handle inventory adjustments
Warehouses
WarehousesApi- Warehouse information and management
Invoices
InvoicesApi- Invoice management
Transport
TransporterContractsApi- Transporter contract managementParcelTypesApi- Parcel type information
Configuration Options
Authentication
The API uses HTTP Basic Authentication:
$config->setUsername('your-username'); $config->setPassword('your-password');
Host Configuration
Set your warehouse-specific API URL:
$config->setHost('https://api.ongoingsystems.se/your-warehouse');
Debug Mode
Enable debug mode for troubleshooting:
$config->setDebug(true); $config->setDebugFile('/path/to/debug.log');
Custom HTTP Client
You can use a custom HTTP client:
use GuzzleHttp\Client; $client = new Client([ 'timeout' => 30, 'verify' => false // Only for development ]); $articlesApi = new ArticlesApi($client, $config);
Error Handling
The library throws exceptions for API errors:
try { $articles = $articlesApi->articlesGetAll(123); } catch (\OngoingAPI\ApiException $e) { echo "API Error: " . $e->getMessage() . "\n"; echo "Response Code: " . $e->getCode() . "\n"; echo "Response Body: " . $e->getResponseBody() . "\n"; } catch (\Exception $e) { echo "General Error: " . $e->getMessage() . "\n"; }
Pagination
Many API endpoints support pagination. Use the max_articles_to_get parameter:
// Get first 100 articles $articles = $articlesApi->articlesGetAll(123, null, null, 100); // Get next 100 articles (using article_system_id_from) $nextArticles = $articlesApi->articlesGetAll(123, null, $lastArticleId, 100);
Development
Running Tests
composer test
Code Quality
# Run PHPStan static analysis composer phpstan # Run PHP CodeSniffer composer phpcs # Auto-fix coding standards composer phpcbf
Building Documentation
# Generate API documentation
composer docs
Contributing
We welcome contributions! Please see our Contributing Guide for details.
Support
- Documentation: Ongoing WMS API Documentation
- Email: phpdevsec@proton.me
- Issues: GitHub Issues
License
This library is licensed under the MIT License. See the LICENSE file for details.
Changelog
See CHANGELOG.md for a list of changes and version history.
Acknowledgments
- Ongoing Warehouse for providing the API
- OpenAPI Generator for generating the base client code
- Directhouse for development and maintenance
Example: Get Article Items (with Pagination)
<?php use OngoingAPI\Api\ArticleItemsApi; use OngoingAPI\Configuration; // Setup configuration $config = new Configuration(); $config->setHost('https://api.ongoingsystems.se/your-warehouse'); $config->setUsername('your-username'); $config->setPassword('your-password'); // Create API client $articleItemsApi = new ArticleItemsApi(null, $config); try { // Get article items for a goods owner (with pagination) $goodsOwnerId = 123; // Replace with your goods owner ID $maxArticlesToGet = 100; $articleSystemIdFrom = null; $allArticleItems = []; do { $response = $articleItemsApi->articleItemsGetArticleItemsModel( $goodsOwnerId, null, // article_number $articleSystemIdFrom, // article_system_id_from $maxArticlesToGet ); foreach ($response->getArticleItems() as $item) { echo "ArticleItemId: " . $item->getArticleItemId() . "\n"; echo "Batch: " . $item->getBatch() . "\n"; echo "Serial: " . $item->getSerial() . "\n"; echo "Status code: " . $item->getStatusCode() . "\n"; // ... access other fields as needed ... $allArticleItems[] = $item; } // Pagination: set articleSystemIdFrom to the last article system ID $articleSystemIdFrom = $response->getArticleSystemId() + 1; } while (count($response->getArticleItems()) === $maxArticlesToGet); echo "Total article items fetched: " . count($allArticleItems) . "\n"; } catch (Exception $e) { echo "Error: " . $e->getMessage() . "\n"; }
Migration from Legacy Method
If you're using the legacy articleItemsGetArticleItems() method, you should migrate to the new articleItemsGetArticleItemsModel() method:
// Old way (deprecated) $articleItems = $api->articleItemsGetArticleItems($goodsOwnerId); foreach ($articleItems as $articleModel) { foreach ($articleModel->getItems() as $item) { // Process item } } // New way (recommended) $response = $api->articleItemsGetArticleItemsModel($goodsOwnerId); foreach ($response->getArticleItems() as $item) { // Process item directly }
The new method provides better consistency and easier access to article items.
Error Handling and Debugging
The API client provides comprehensive error handling with detailed exception messages:
try { $response = $articleItemsApi->articleItemsGetArticleItemsModel($goodsOwnerId); // Process response } catch (\OngoingAPI\ApiException $e) { echo "API Error: " . $e->getMessage() . "\n"; echo "Status Code: " . $e->getCode() . "\n"; echo "Response Body: " . $e->getResponseBody() . "\n"; echo "Response Headers: " . print_r($e->getResponseHeaders(), true) . "\n"; } catch (\InvalidArgumentException $e) { echo "Invalid Argument: " . $e->getMessage() . "\n"; } catch (Exception $e) { echo "Unexpected Error: " . $e->getMessage() . "\n"; }
Debug Mode
Enable debug mode to log all HTTP requests and responses:
$config->setDebug(true); $config->setDebugFile('/tmp/ongoing-api-debug.log');
This will help you troubleshoot API issues and understand the exact requests being made.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-22