PHP code example of simplia / api

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/ */

    

simplia / api example snippets


use \Simplia\Api\Api;
use \Simplia\Api\Input\AddressTypeApiInput;
use \Simplia\Api\Input\OrderCreateTypeApiInput;
use \Simplia\Api\Input\OrderItemTypeApiInput;
use \Simplia\Api\Entity\OrderApiEntity;

$api = Api::withUsernameAuth($httpClient, 'demo2.simpliashop.cz', 'api_user', '*********');
$order = $api->getOrdersEndpoint()->create(
    OrderCreateTypeApiInput::create()
        ->setDeliveryAddress(
            AddressTypeApiInput::create()
                ->setFirstName('John')
                ->setLastName('Smith')
                ->setCity('Prague')
                ->setEmail('[email protected]')
        )
        ->setCustomerNote('customer note')
        ->setItems([
            OrderItemTypeApiInput::create()
            ->setItemId(123)
            ->setQuantity(2)
            ->setPriceVat(200) // unit price with vat
        ]),
    OrderApiEntity::createFieldConfig()
        ->withId()
);

echo $order->getId();

use \Simplia\Api\Api;
use \Simplia\Api\Input\OrderStatusTypeApiInput;

$api = Api::withUsernameAuth($httpClient, 'demo2.simpliashop.cz', 'api_user', '*********');
$api->getOrdersEndpoint()->updateStatus(
    '123',
    OrderStatusTypeApiInput::create()
        ->setStatusId(4)
);

use \Simplia\Api\Api;
use \Simplia\Api\Entity\ContactApiEntity;
use \Simplia\Api\Entity\OrderApiEntity;
use \Simplia\Api\Request\OrderApiRequest;

$api = Api::withUsernameAuth($httpClient, 'demo2.simpliashop.cz', 'api_user', '*********');
$orders = $api->getOrdersEndpoint()->iterate(
    OrderApiRequest::create()
        ->whereStatus(1),
    OrderApiEntity::createFieldConfig()
        ->withId()
        ->withDeliveryAddress(
            ContactApiEntity::createFieldConfig()
                ->withCompanyName()
        )
);

foreach ($orders as $order) {
    echo $order->getId();
    echo $order->getDeliveryAddress()->getCompanyName();
}

use \Simplia\Api\Api;
use \Simplia\Api\Entity\ContactApiEntity;
use \Simplia\Api\Entity\OrderApiEntity;

$api = Api::withUsernameAuth($httpClient, 'demo2.simpliashop.cz', 'api_user', '*********');
$order = $api->getOrdersEndpoint()->get(
   '123',
    OrderApiEntity::createFieldConfig()
        ->withId()
        ->withDeliveryAddress(
            ContactApiEntity::createFieldConfig()
                ->withCompanyName()
        )
);

echo $order->getId();
echo $order->getDeliveryAddress()->getCompanyName();
echo $order->getCurrency(); // throws error because currency with wasn't loaded from API (is not defined in field config)

use \Simplia\Api\Api;
use \Simplia\Api\Request\ArticleApiRequest;
use \Simplia\Api\Entity\ArticleApiEntity;

$api = Api::withUsernameAuth($httpClient, 'demo2.simpliashop.cz', 'api_user', '*********');
$articles = $api->getArticlesEndpoint()->iterate(
    ArticleApiRequest::create()
        ->whereTopic(7)
        ->orderByPublishedAsc(),
    ArticleApiEntity::createFieldConfig()
        ->withName()
        ->withUrl()
);

foreach ($articles as $article) {
    echo '<a href="' . $article->getUrl() . '">' . $article->getName() . '</a>';
}