1. Go to this page and download the library: Download simplia/api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Simplia\Api\Entity\OrderApiEntity;
use Simplia\Api\Entity\UserApiEntity;
$fields = OrderApiEntity::createFieldConfig()
->selectCode()
->selectTotalPrice()
->selectUser(UserApiEntity::createFieldConfig()->selectEmail()); // an embed: name its fields too
use Simplia\Api\Enum\OrderStatus;
use Simplia\Api\Request\OrdersApiRequest;
$request = OrdersApiRequest::create()
->whereStatus([OrderStatus::Unprocessed]) // filters: where*()
->whereCreatedAtFrom(new \DateTimeImmutable('-7 days'))
->orderByCreatedAtDesc(); // sort: orderBy*(); the allowed sorts are the methods you see
foreach ($api->getOrdersEndpoint()->iterate($request, $fields, perPage: 100) as $order) {
// one entity per row, across every page
}
$total = $api->getOrdersEndpoint()->count($request); // the total only, no rows
use Simplia\Api\Entity\OrderApiEntity;
use Simplia\Api\Enum\OrderStatus;
$order = $api->getOrdersEndpoint()->get(123, OrderApiEntity::createFieldConfig()->selectStatus());
$label = match ($order?->getStatus()) {
OrderStatus::Unprocessed, OrderStatus::Processed => 'open',
OrderStatus::Waiting, OrderStatus::Ready => 'in progress',
OrderStatus::Finished, OrderStatus::Cancelled => 'closed',
null => 'no public status', // also the arm for a 404, which get() answers as null
};
use Simplia\Api\Entity\OrderApiEntity;
use Simplia\Api\Enum\OrderStatus;
use Simplia\Api\Input\OrderCreateApiInput;
use Simplia\Api\Input\OrderDeliveryApiInput;
use Simplia\Api\Input\OrderItemApiInput;
use Simplia\Api\Input\OrderStatusApiInput;
use Simplia\Api\Input\OrderUpdateApiInput;
use Simplia\Api\Money;
$input = OrderCreateApiInput::create()
->setItems([
OrderItemApiInput::create()
->setQuantity(2)->setPrice(new Money('490.00', 'CZK'))->setVatRate(21.0)
->setStockItemCode('SKU-1'), // not optional: one of the three names the item (or setStockItemId() / setStockItemTrackingId())
])
->setDelivery(
OrderDeliveryApiInput::create()
->setTransportMethodId(3)->setTransportPrice(new Money('99.00', 'CZK'))->setTransportVatRate(21.0)
->setPaymentMethodId(1)->setPaymentPrice(new Money('0.00', 'CZK'))->setPaymentVatRate(21.0)
);
if ($customerNote !== null) {
$input->setCustomerNote($customerNote); // an optional property: only what you set is sent
}
$order = $api->getOrdersEndpoint()->create(
$input,
OrderApiEntity::createFieldConfig()->selectCode()->selectStatus(), // omit it for the id alone
);
$api->getOrdersEndpoint()->updateStatus($order->getId(), OrderStatusApiInput::create()->setStatus(OrderStatus::Processed));
$api->getOrdersEndpoint()->update($order->getId(), OrderUpdateApiInput::create()->setPackagingNote('fragile'));
use Simplia\Api\Entity\OrderApiEntity;
use Simplia\Api\Exception\RateLimitedException;
use Simplia\Api\Exception\UnknownEnumValueException;
use Simplia\Api\Exception\ValidationException;
try {
$order = $api->getOrdersEndpoint()->create($input, OrderApiEntity::createFieldConfig()->selectStatus());
$status = $order->getStatus();
} catch (ValidationException $e) {
foreach ($e->violations() as $violation) {
// which property, and why
}
} catch (RateLimitedException $e) {
sleep($e->retryAfter() ?? 1); // then send the same request, with the same idempotency key
} catch (UnknownEnumValueException $e) {
// $e->getField() carried $e->getValue(), which this client does not know: upgrade simplia/api
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.