Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Pobo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
149 changes: 92 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Pobo PHP SDK

[![Tests](https://github.com/pobo-builder/php-sdk/actions/workflows/tests.yml/badge.svg)](https://github.com/pobo-builder/php-sdk/actions/workflows/tests.yml)
[![Latest Stable Version](https://poser.pugx.org/pobo-builder/php-sdk/v/stable)](https://packagist.org/packages/pobo-builder/php-sdk)
[![License](https://poser.pugx.org/pobo-builder/php-sdk/license)](https://packagist.org/packages/pobo-builder/php-sdk)

Official PHP SDK for [Pobo API V2](https://api.pobo.space) - product content management and webhooks.

## Requirements
Expand All @@ -11,7 +15,7 @@ Official PHP SDK for [Pobo API V2](https://api.pobo.space) - product content man
## Installation

```bash
composer require pobo/php-sdk
composer require pobo-builder/php-sdk
```

## Quick Start
Expand Down Expand Up @@ -59,16 +63,35 @@ Import categories second (no dependencies).
```php
use Pobo\Sdk\DTO\Category;
use Pobo\Sdk\DTO\LocalizedString;
use Pobo\Sdk\Enum\Language;

$category = new Category(
id: 'CAT-001',
isVisible: true,
name: LocalizedString::create('Electronics'),
url: LocalizedString::create('https://example.com/electronics'),
description: LocalizedString::create('<p>All electronics</p>'),
);

$result = $client->importCategories([$category]);
$categories = [
new Category(
id: 'CAT-001',
isVisible: true,
name: LocalizedString::create('Electronics')
->withTranslation(Language::CS, 'Elektronika')
->withTranslation(Language::SK, 'Elektronika'),
url: LocalizedString::create('https://example.com/electronics')
->withTranslation(Language::CS, 'https://example.com/cs/elektronika')
->withTranslation(Language::SK, 'https://example.com/sk/elektronika'),
description: LocalizedString::create('<p>All electronics</p>'),
images: ['https://example.com/images/electronics.jpg'],
),
new Category(
id: 'CAT-002',
isVisible: true,
name: LocalizedString::create('Phones')
->withTranslation(Language::CS, 'Telefony')
->withTranslation(Language::SK, 'Telefóny'),
url: LocalizedString::create('https://example.com/phones')
->withTranslation(Language::CS, 'https://example.com/cs/telefony')
->withTranslation(Language::SK, 'https://example.com/sk/telefony'),
),
];

$result = $client->importCategories($categories);
echo sprintf('Imported: %d, Updated: %d', $result->imported, $result->updated);
```

### Import Products
Expand All @@ -80,35 +103,47 @@ use Pobo\Sdk\DTO\Product;
use Pobo\Sdk\DTO\LocalizedString;
use Pobo\Sdk\Enum\Language;

// Using DTO objects
$product = new Product(
id: 'PROD-001',
isVisible: true,
name: LocalizedString::create('iPhone 15')
->withTranslation(Language::SK, 'iPhone 15')
->withTranslation(Language::EN, 'iPhone 15'),
url: LocalizedString::create('https://example.com/iphone-15')
->withTranslation(Language::SK, 'https://example.com/sk/iphone-15'),
shortDescription: LocalizedString::create('Latest iPhone model'),
images: [
'https://example.com/images/iphone-1.jpg',
'https://example.com/images/iphone-2.jpg',
],
categoriesIds: ['CAT-001', 'CAT-002'],
parametersIds: [1, 2, 3],
);

$result = $client->importProducts([$product]);

// Or using arrays
$result = $client->importProducts([
[
'id' => 'PROD-002',
'is_visible' => true,
'name' => ['default' => 'Samsung Galaxy S24'],
'url' => ['default' => 'https://example.com/samsung-s24'],
],
]);
$products = [
new Product(
id: 'PROD-001',
isVisible: true,
name: LocalizedString::create('iPhone 15')
->withTranslation(Language::CS, 'iPhone 15')
->withTranslation(Language::SK, 'iPhone 15'),
url: LocalizedString::create('https://example.com/iphone-15')
->withTranslation(Language::CS, 'https://example.com/cs/iphone-15')
->withTranslation(Language::SK, 'https://example.com/sk/iphone-15'),
shortDescription: LocalizedString::create('Latest iPhone model')
->withTranslation(Language::CS, 'Nejnovější model iPhone')
->withTranslation(Language::SK, 'Najnovší model iPhone'),
images: [
'https://example.com/images/iphone-1.jpg',
'https://example.com/images/iphone-2.jpg',
],
categoriesIds: ['CAT-001', 'CAT-002'],
parametersIds: [1, 2],
),
new Product(
id: 'PROD-002',
isVisible: true,
name: LocalizedString::create('Samsung Galaxy S24')
->withTranslation(Language::CS, 'Samsung Galaxy S24')
->withTranslation(Language::SK, 'Samsung Galaxy S24'),
url: LocalizedString::create('https://example.com/samsung-s24')
->withTranslation(Language::CS, 'https://example.com/cs/samsung-s24')
->withTranslation(Language::SK, 'https://example.com/sk/samsung-s24'),
shortDescription: LocalizedString::create('Flagship Android phone')
->withTranslation(Language::CS, 'Vlajková loď Android')
->withTranslation(Language::SK, 'Vlajková loď Android'),
images: [
'https://example.com/images/samsung-1.jpg',
],
categoriesIds: ['CAT-001', 'CAT-002'],
parametersIds: [1, 3],
),
];

$result = $client->importProducts($products);

if ($result->hasErrors() === true) {
foreach ($result->errors as $error) {
Expand Down Expand Up @@ -248,28 +283,28 @@ $name->toArray(); // ['default' => '...', 'cs' => '...', ...]

### Supported Languages

| Code | Language |
|------|----------|
| Code | Language |
|-----------|--------------------|
| `default` | Default (required) |
| `cs` | Czech |
| `sk` | Slovak |
| `en` | English |
| `de` | German |
| `pl` | Polish |
| `hu` | Hungarian |
| `cs` | Czech |
| `sk` | Slovak |
| `en` | English |
| `de` | German |
| `pl` | Polish |
| `hu` | Hungarian |

## Limits

| Limit | Value |
|-------|-------|
| Max items per import request | 100 |
| Max items per export page | 100 |
| Product/Category ID length | 255 chars |
| Name length | 250 chars |
| URL length | 255 chars |
| Image URL length | 650 chars |
| Description length | 65,000 chars |
| SEO description length | 500 chars |
| Limit | Value |
|------------------------------|--------------|
| Max items per import request | 100 |
| Max items per export page | 100 |
| Product/Category ID length | 255 chars |
| Name length | 250 chars |
| URL length | 255 chars |
| Image URL length | 650 chars |
| Description length | 65,000 chars |
| SEO description length | 500 chars |

## License

Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@
"ecommerce",
"product-content"
],
"homepage": "https://github.com/pobo-builder/php-sdk",
"authors": [
{
"name": "Pobo",
"email": "support@pobo.cz"
"email": "tomas@pobo.cz",
"homepage": "https://pobo.cz"
}
],
"support": {
"issues": "https://github.com/pobo-builder/php-sdk/issues",
"source": "https://github.com/pobo-builder/php-sdk"
},
"require": {
"php": "^8.1",
"ext-curl": "*",
Expand Down
24 changes: 12 additions & 12 deletions src/DTO/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@

namespace Pobo\Sdk\DTO;

readonly class Category
final class Category
{
/**
* @param array<string> $images
*/
public function __construct(
public string $id,
public bool $isVisible,
public LocalizedString $name,
public LocalizedString $url,
public ?LocalizedString $description = null,
public ?LocalizedString $seoTitle = null,
public ?LocalizedString $seoDescription = null,
public array $images = [],
public ?string $guid = null,
public ?\DateTimeInterface $createdAt = null,
public ?\DateTimeInterface $updatedAt = null,
public readonly string $id,
public readonly bool $isVisible,
public readonly LocalizedString $name,
public readonly LocalizedString $url,
public readonly ?LocalizedString $description = null,
public readonly ?LocalizedString $seoTitle = null,
public readonly ?LocalizedString $seoDescription = null,
public readonly array $images = [],
public readonly ?string $guid = null,
public readonly ?\DateTimeInterface $createdAt = null,
public readonly ?\DateTimeInterface $updatedAt = null,
) {
}

Expand Down
16 changes: 8 additions & 8 deletions src/DTO/ImportResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@

namespace Pobo\Sdk\DTO;

readonly class ImportResult
final class ImportResult
{
/**
* @param array<array{index: int, id: string, errors: array<string>}> $errors
*/
public function __construct(
public bool $success,
public int $imported,
public int $updated,
public int $skipped,
public array $errors = [],
public ?int $valuesImported = null,
public ?int $valuesUpdated = null,
public readonly bool $success,
public readonly int $imported,
public readonly int $updated,
public readonly int $skipped,
public readonly array $errors = [],
public readonly ?int $valuesImported = null,
public readonly ?int $valuesUpdated = null,
) {
}

Expand Down
4 changes: 2 additions & 2 deletions src/DTO/LocalizedString.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

use Pobo\Sdk\Enum\Language;

readonly class LocalizedString
final class LocalizedString
{
/**
* @param array<string, string|null> $values
*/
public function __construct(
private array $values,
private readonly array $values,
) {
}

Expand Down
10 changes: 5 additions & 5 deletions src/DTO/PaginatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

namespace Pobo\Sdk\DTO;

readonly class PaginatedResponse
final class PaginatedResponse
{
/**
* @param array<Product|Category> $data
*/
public function __construct(
public array $data,
public int $currentPage,
public int $perPage,
public int $total,
public readonly array $data,
public readonly int $currentPage,
public readonly int $perPage,
public readonly int $total,
) {
}

Expand Down
8 changes: 4 additions & 4 deletions src/DTO/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Pobo\Sdk\DTO;

readonly class Parameter
final class Parameter
{
/**
* @param array<ParameterValue> $values
*/
public function __construct(
public int $id,
public string $name,
public array $values,
public readonly int $id,
public readonly string $name,
public readonly array $values,
) {
}

Expand Down
6 changes: 3 additions & 3 deletions src/DTO/ParameterValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Pobo\Sdk\DTO;

readonly class ParameterValue
final class ParameterValue
{
public function __construct(
public int $id,
public string $value,
public readonly int $id,
public readonly string $value,
) {
}

Expand Down
Loading