Skip to content

Commit d1ec19d

Browse files
authored
Merge pull request #23 from Invertus/BRD-315-feature/client-specific-search-implementation
[BRD-315] feature / client specific search implementation + claude code
2 parents 11c1a2d + f587184 commit d1ec19d

File tree

2 files changed

+114
-4
lines changed

2 files changed

+114
-4
lines changed

CLAUDE.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Development Commands
6+
7+
### Testing
8+
```bash
9+
# Run all tests
10+
vendor/bin/phpunit
11+
12+
# Run tests with coverage
13+
vendor/bin/phpunit --coverage-html coverage
14+
15+
# Run a specific test
16+
vendor/bin/phpunit tests/Adapters/PrestaShopAdapterTest.php
17+
```
18+
19+
### Code Quality
20+
```bash
21+
# Run PHPStan static analysis
22+
vendor/bin/phpstan analyse
23+
24+
# Run PHP CodeSniffer
25+
vendor/bin/phpcs src tests
26+
27+
# Install dependencies
28+
composer install
29+
30+
# Update dependencies
31+
composer update
32+
```
33+
34+
## Code Architecture
35+
36+
### Core SDK Structure
37+
The PHP SDK for Brad Search synchronization is organized into a modular architecture:
38+
39+
- **`SynchronizationApiSdk`** - Main SDK class providing the public API for index management and product synchronization
40+
- **Field Configuration System** - Type-safe field definitions using PHP enums and configuration builders
41+
- **Validation Layer** - Comprehensive data validation against field configurations before API calls
42+
- **HTTP Client** - cURL-based client with error handling and authentication
43+
- **Exception Hierarchy** - Typed exceptions for different error scenarios
44+
45+
### Key Components
46+
47+
#### SynchronizationApiSdk (src/SynchronizationApiSdk.php)
48+
Main entry point providing methods:
49+
- `createIndex()` / `deleteIndex()` - Index management
50+
- `sync()` / `syncBulk()` - Product synchronization (single and batch)
51+
- `copyIndex()` - Index replication
52+
- `deleteProductsBulk()` - Bulk product deletion
53+
- `validateProduct()` / `validateProducts()` - Data validation without syncing
54+
55+
#### Field Configuration (src/Models/)
56+
- **`FieldConfig`** - Individual field configuration with type and attributes
57+
- **`FieldConfigBuilder`** - Helper for building common field configurations
58+
- **`FieldType` enum** - Defines supported field types (TEXT_KEYWORD, HIERARCHY, VARIANTS, etc.)
59+
60+
#### Validation System (src/Validators/)
61+
- **`DataValidator`** - Validates product data against field configuration
62+
- Supports all field types including hierarchical categories, variants with attributes, and URL validation
63+
- Provides detailed error reporting
64+
65+
#### HTTP Layer (src/Client/)
66+
- **`HttpClient`** - Handles API communication with authentication, timeouts, and error handling
67+
- Supports all HTTP methods (GET, POST, PUT, DELETE) with JSON encoding
68+
69+
### API Endpoints
70+
The SDK communicates with these endpoints:
71+
- `DELETE /api/v1/sync/{index}` - Delete index
72+
- `PUT /api/v1/sync/` - Create index with field configuration
73+
- `POST /api/v1/sync/` - Bulk sync products
74+
- `POST /api/v1/sync/reindex` - Copy/reindex operations
75+
- `POST /api/v1/sync/delete-products` - Bulk delete products
76+
77+
### Field Types Supported
78+
- `TEXT_KEYWORD` - Full-text search with keyword matching
79+
- `TEXT` - Full-text search only
80+
- `KEYWORD` - Exact keyword matching
81+
- `HIERARCHY` - Hierarchical categories (e.g., "Clothing > T-Shirts > Premium")
82+
- `VARIANTS` - Product variants with configurable attributes
83+
- `NAME_VALUE_LIST` - Key-value pairs (features, specifications)
84+
- `IMAGE_URL` - Image URLs object with size keys
85+
- `URL` - Regular URLs with validation
86+
- `FLOAT`, `INTEGER`, `DOUBLE` - Numeric types
87+
88+
### Data Processing
89+
- **Field Filtering** - Only configured fields are sent to API
90+
- **Batch Processing** - Large datasets automatically chunked (default 100 items per batch)
91+
- **Validation First** - All products validated before any API calls
92+
- **Embeddable Fields** - Support for localized fields with configurable locales
93+
94+
### PrestaShop Integration
95+
The SDK includes a PrestaShop adapter (`src/Adapters/PrestaShopAdapter.php`) for e-commerce platform integration, handling product data mapping and synchronization specific to PrestaShop's data structure.
96+
97+
### Dependencies
98+
- **PHP 8.4+** - Uses modern PHP features (readonly properties, enums, constructor property promotion)
99+
- **ext-json** - JSON encoding/decoding
100+
- **ext-curl** - HTTP client functionality
101+
- **PHPUnit** - Testing framework
102+
- **PHPStan** - Static analysis
103+
- **PHP CodeSniffer** - Code style enforcement

src/SynchronizationApiSdk.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,18 @@ class SynchronizationApiSdk
1616
private readonly HttpClient $httpClient;
1717
private readonly DataValidator $validator;
1818

19+
private readonly string $apiStartUrl;
20+
1921
/**
2022
* @param array<string, FieldConfig> $fieldConfiguration
2123
*/
2224
public function __construct(
2325
SyncConfig $config,
24-
public readonly array $fieldConfiguration
26+
public readonly array $fieldConfiguration,
27+
private readonly string $endpoint = ''
2528
) {
2629
$this->httpClient = new HttpClient($config);
30+
$this->apiStartUrl = 'api/v1/';
2731
$this->validator = new DataValidator($fieldConfiguration);
2832
}
2933

@@ -36,7 +40,7 @@ public function __construct(
3640
public function deleteIndex(string $index): void
3741
{
3842
$this->validator->validateIndex($index);
39-
$this->httpClient->delete("api/v1/sync/{$index}");
43+
$this->httpClient->delete("{$this->apiStartUrl}sync/{$index}");
4044
}
4145

4246
/**
@@ -59,7 +63,10 @@ public function createIndex(string $index): void
5963
'fields' => $fields,
6064
];
6165

62-
$this->httpClient->put('api/v1/sync/', $data);
66+
67+
$url = $this->apiStartUrl . (!empty($this->endpoint) ? $this->endpoint . '/' : '') . 'sync/';
68+
69+
$this->httpClient->put($url, $data);
6370
}
6471

6572
/**
@@ -82,7 +89,7 @@ public function copyIndex(string $sourceIndex, string $targetIndex): void
8289
'target_index' => $targetIndex
8390
];
8491

85-
$this->httpClient->post('api/v1/sync/reindex', $data);
92+
$this->httpClient->post("{$this->apiStartUrl}sync/reindex", $data);
8693
}
8794

8895
/**

0 commit comments

Comments
 (0)