Integrations DI refactor, remove Sellasist/Baselinker, fix product-edit encoding (0.263)
- New: Domain\Integrations\IntegrationsRepository + admin\Controllers\IntegrationsController (DI) - Cleanup: removed all Sellasist and Baselinker integrations from entire project - Fix: product-edit.php Polish characters (UTF-8/CP1250 double-encoding) - Update: factory\Integrations as facade (Apilo + ShopPRO only) - Tests: 212 tests, 577 assertions Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -28,4 +28,4 @@ To ma pomóc zachować spójność zmian i dokumentacji.
|
||||
|
||||
## INNE
|
||||
|
||||
Przejdźmy teraz do refaktoringu wszystkiego co związane z https://shoppro.project-dc.pl/admin/articles_archive/, nowe widoki, klasy (usuwanie starych), poprawa routingu, przeszukanie innych klas pod względem zależności. Zapisz plan a później realizuj krok po kroku.
|
||||
Przejdźmy teraz do refaktoringu wszystkiego co związane z https://shoppro.project-dc.pl/admin/articles_archive/, nowe widoki, klasy (usuwanie starych), poprawa routingu, przeszukanie innych klas pod względem zależności. Zapisz plan i przedstaw mi go a po akceptacji realizuj krok po kroku w trybie Human In The Loop
|
||||
@@ -19,7 +19,7 @@ Główna tabela produktów.
|
||||
| vat | Stawka VAT |
|
||||
| ean | Kod EAN |
|
||||
| sku | Kod SKU |
|
||||
| baselinker_product_name | Nazwa produktu w Baselinker |
|
||||
| apilo_product_id | ID produktu w Apilo |
|
||||
| apilo_product_name | Nazwa produktu w Apilo |
|
||||
|
||||
**Używane w:** `Domain\Product\ProductRepository`, `admin\factory\ShopProduct`
|
||||
@@ -319,3 +319,27 @@ Tlumaczenia kontenerow statycznych (per jezyk).
|
||||
**Aktualizacja 2026-02-12 (ver. 0.259):** modul `/admin/scontainers` korzysta z `Domain\Scontainers\ScontainersRepository` (DI kontroler + fasada legacy).
|
||||
|
||||
**Aktualizacja 2026-02-12 (ver. 0.260):** modul `/admin/articles_archive` korzysta z `Domain\Article\ArticleRepository` (`listArchivedForAdmin`, `restore`, `deletePermanently`) przez `admin\Controllers\ArticlesArchiveController`.
|
||||
|
||||
## pp_shop_apilo_settings
|
||||
Ustawienia integracji Apilo (key-value).
|
||||
|
||||
| Kolumna | Opis |
|
||||
|---------|------|
|
||||
| id | PK |
|
||||
| name | Klucz ustawienia (np. client-id, access-token) |
|
||||
| value | Wartosc ustawienia |
|
||||
|
||||
**Uzywane w:** `Domain\Integrations\IntegrationsRepository`, `admin\Controllers\IntegrationsController`, `admin\factory\Integrations`
|
||||
|
||||
## pp_shop_shoppro_settings
|
||||
Ustawienia integracji ShopPRO (key-value).
|
||||
|
||||
| Kolumna | Opis |
|
||||
|---------|------|
|
||||
| id | PK |
|
||||
| name | Klucz ustawienia (np. domain, db_name) |
|
||||
| value | Wartosc ustawienia |
|
||||
|
||||
**Uzywane w:** `Domain\Integrations\IntegrationsRepository`, `admin\Controllers\IntegrationsController`, `admin\factory\Integrations`
|
||||
|
||||
**Aktualizacja 2026-02-13:** modul `/admin/integrations/` korzysta z `Domain\Integrations\IntegrationsRepository` (DI kontroler + fasada legacy). Usunieto integracje Sellasist i Baselinker.
|
||||
|
||||
@@ -57,26 +57,13 @@ shop\product:{product_id}:{lang_id}:{permutation_hash}
|
||||
|
||||
### Plik: `cron.php`
|
||||
|
||||
#### Sellasist
|
||||
- **Aktualizacja produktów:** Linia 111-149
|
||||
- **Funkcje:** Aktualizacja cen i stanów magazynowych
|
||||
- **Częstotliwość:** Co 10 minut
|
||||
- **Czyszczenie cache:** Linia 146
|
||||
|
||||
#### Apilo
|
||||
- **Aktualizacja pojedynczego produktu:** Linia 152-176
|
||||
- Częstotliwość: Co 10 minut
|
||||
- Czyszczenie cache: Linia 173
|
||||
- **Aktualizacja pojedynczego produktu:** synchronizacja cen i stanow
|
||||
- Czestotliwosc: Co 10 minut
|
||||
- **Synchronizacja cennika:** masowa aktualizacja cen z Apilo
|
||||
- Czestotliwosc: Co 1 godzine
|
||||
|
||||
- **Synchronizacja cennika:** Linia 179-218
|
||||
- Częstotliwość: Co 1 godzinę
|
||||
- Czyszczenie cache: Linia 212
|
||||
|
||||
#### Baselinker
|
||||
- **Aktualizacja produktów:** Linia 220-289
|
||||
- **Funkcje:** Ceny, stany magazynowe, wagi
|
||||
- **Częstotliwość:** Co 24 godziny (1440 minut)
|
||||
- **Czyszczenie cache:** Linia 278
|
||||
**Uwaga:** Integracje Sellasist i Baselinker zostaly usuniete w ver. 0.263.
|
||||
|
||||
## Panel Administratora
|
||||
|
||||
@@ -130,9 +117,10 @@ shopPRO/
|
||||
|
||||
### Tabele integracji
|
||||
- Kolumny w `pp_shop_products`:
|
||||
- `sellasist_product_id`, `sellasist_get_data_date`
|
||||
- `apilo_product_id`, `apilo_get_data_date`
|
||||
- `baselinker_product_id`, `baselinker_get_data_date`
|
||||
- `apilo_product_id`, `apilo_product_name`, `apilo_get_data_date`
|
||||
- Tabele ustawien:
|
||||
- `pp_shop_apilo_settings` (key-value)
|
||||
- `pp_shop_shoppro_settings` (key-value)
|
||||
|
||||
## Konfiguracja
|
||||
|
||||
@@ -387,9 +375,9 @@ Aktualnie w suite są też testy modułów `Dictionaries`, `Articles` i `Users`
|
||||
- **UPDATE:** widoki Users przeniesione z `grid/gridEdit` na `components/table-list` i `components/form-edit`
|
||||
|
||||
## Aktualizacja 2026-02-12 (finalizacja Users)
|
||||
- Modu<64> users dzia<69>a na `Domain\\User\\UserRepository` + `admin\\Controllers\\UsersController`.
|
||||
- Usuni<6E>to legacy klasy: `autoload/admin/controls/class.Users.php`, `autoload/admin/factory/class.Users.php`, `autoload/admin/view/class.Users.php`.
|
||||
- Walidacja: przy w<><77>czonym 2FA pole `twofa_email` jest wymagane.
|
||||
- Modu<64> users dzia<69>a na `Domain\\User\\UserRepository` + `admin\\Controllers\\UsersController`.
|
||||
- Usuni<6E>to legacy klasy: `autoload/admin/controls/class.Users.php`, `autoload/admin/factory/class.Users.php`, `autoload/admin/view/class.Users.php`.
|
||||
- Walidacja: przy w<><77>czonym 2FA pole `twofa_email` jest wymagane.
|
||||
- Widoki users przeniesione na `components/table-list` i `components/form-edit`.
|
||||
- **NOWE:** `Domain\\Languages\\LanguagesRepository` - repozytorium jezykow i tlumaczen (lista, zapis, usuwanie, max_order)
|
||||
- **NOWE:** `admin\\Controllers\\LanguagesController` - kontroler DI (`list/view_list`, `language_*`, `translation_*`)
|
||||
@@ -479,3 +467,11 @@ Aktualnie w suite są też testy modułów `Dictionaries`, `Articles` i `Users`
|
||||
- UPDATE: routing DI (`admin\\Site`) ma fabryke kontrolera `Pages`.
|
||||
- UPDATE: zalezne endpointy `cookie_*` i `generate_seo_link` przepiete na `/admin/pages/*`.
|
||||
- CLEANUP: usuniete legacy pliki `autoload/admin/controls/class.Pages.php`, `autoload/admin/view/class.Pages.php`, `autoload/admin/factory/class.Pages.php`, `admin/ajax/pages.php`.
|
||||
|
||||
## Aktualizacja 2026-02-13 (Integrations refactor, ver. 0.263)
|
||||
- NOWE: `Domain\Integrations\IntegrationsRepository` (settings Apilo/ShopPRO, OAuth, product linking, API fetch).
|
||||
- NOWE: `admin\Controllers\IntegrationsController` (DI) dla akcji Apilo (settings, authorization, fetch lists, product CRUD) i ShopPRO (settings, product import).
|
||||
- UPDATE: `admin\factory\Integrations` jako fasada delegujaca do repozytorium (tylko Apilo + ShopPRO).
|
||||
- CLEANUP: **usunieto integracje Sellasist i Baselinker z calego projektu** - kontrolery, factory, szablony, referencje w cron.php, Order, ShopStatuses, ShopTransport, ShopPaymentMethod, ShopProduct, config.php, front/factory/*.
|
||||
- CLEANUP: usuniete pliki: `autoload/admin/controls/class.Integrations.php`, `autoload/admin/controls/class.Baselinker.php`, `autoload/admin/factory/class.Baselinker.php`, `autoload/front/factory/class.Shop.php`, `autoload/shop/class.ShopStatus.php`, szablony sellasist/baselinker.
|
||||
- Testy: **OK (212 tests, 577 assertions)**.
|
||||
|
||||
@@ -260,12 +260,23 @@ grep -r "Product::getQuantity" .
|
||||
- Legacy cleanup: usuniety `autoload/admin/controls/class.Users.php`
|
||||
- Testy: 25 testow repozytorium (CRUD, logon, 2FA, checkLogin) + 12 testow kontrolera (kontrakty + normalizeUser)
|
||||
|
||||
- **Integrations** (migracja kontrolera i repozytorium + cleanup Sellasist/Baselinker)
|
||||
- ✅ IntegrationsRepository - **ZMIGROWANE** (2026-02-13) 🎉
|
||||
- Nowa klasa: `Domain\Integrations\IntegrationsRepository` (settings Apilo/ShopPRO, OAuth, product linking, API fetch)
|
||||
- Nowy kontroler: `admin\Controllers\IntegrationsController` (DI, instancyjny)
|
||||
- Router: `admin\Site` - factory wpis dla modulu `Integrations`
|
||||
- Fasada: `admin\factory\Integrations` deleguje do repozytorium (tylko Apilo + ShopPRO)
|
||||
- **CLEANUP:** usunieto integracje Sellasist i Baselinker z calego projektu
|
||||
- Usuniete pliki: `controls/Integrations`, `controls/Baselinker`, `factory/Baselinker`, `front/factory/Shop`, `shop/ShopStatus`, szablony sellasist/baselinker
|
||||
- Wyczyszczone referencje w: cron.php, Order, ShopStatuses, ShopTransport, ShopPaymentMethod, ShopProduct, config.php, front/factory/*
|
||||
- Testy: 16 nowych testow (repozytorium) + 10 testow kontrolera
|
||||
- Aktualizacja: ver. 0.263
|
||||
|
||||
### 📋 Do zrobienia
|
||||
- Order
|
||||
- Category
|
||||
- ShopAttribute
|
||||
- ShopProduct (factory)
|
||||
- Pages (`browse_list` i widoki drzewiaste nadal w legacy `admin\controls` / `admin\view`)
|
||||
|
||||
## Testowanie
|
||||
|
||||
@@ -286,17 +297,19 @@ tests/
|
||||
│ │ ├── Dictionaries/DictionariesRepositoryTest.php
|
||||
│ │ ├── Product/ProductRepositoryTest.php
|
||||
│ │ ├── Settings/SettingsRepositoryTest.php
|
||||
│ │ └── User/UserRepositoryTest.php
|
||||
│ │ ├── User/UserRepositoryTest.php
|
||||
│ │ └── Integrations/IntegrationsRepositoryTest.php
|
||||
│ └── admin/
|
||||
│ └── Controllers/
|
||||
│ ├── ArticlesControllerTest.php
|
||||
│ ├── DictionariesControllerTest.php
|
||||
│ ├── IntegrationsControllerTest.php
|
||||
│ ├── ProductArchiveControllerTest.php
|
||||
│ ├── SettingsControllerTest.php
|
||||
│ └── UsersControllerTest.php
|
||||
└── Integration/
|
||||
```
|
||||
**Łącznie: 119 testów, 256 asercji**
|
||||
**Łącznie: 212 testów, 577 asercji**
|
||||
|
||||
### Przykład testu
|
||||
```php
|
||||
@@ -381,10 +394,11 @@ vendor/bin/phpstan analyse autoload/Domain
|
||||
6. **ProductArchive** ✅ (migracja kontrolera + cleanup szablonów, ver. 0.252)
|
||||
7. **Filemanager** ✅ (migracja routingu + fix `Invalid Key`, ver. 0.252)
|
||||
8. **Users** ✅ (repo + kontroler + 2FA + legacy cleanup, ver. 0.253)
|
||||
9. **Order**
|
||||
10. **Category**
|
||||
11. **ShopAttribute**
|
||||
12. **Pages** (`browse_list` i powiązane widoki nadal legacy)
|
||||
9. **Pages** ✅ (repo + kontroler + drzewo stron + AJAX endpoints, ver. 0.262)
|
||||
10. **Integrations** ✅ (repo + kontroler + cleanup Sellasist/Baselinker, ver. 0.263)
|
||||
11. **Order**
|
||||
12. **Category**
|
||||
13. **ShopAttribute**
|
||||
|
||||
- **Form Edit System** - Nowy uniwersalny system formularzy edycji
|
||||
- ✅ Klasy ViewModel: `FormFieldType`, `FormField`, `FormTab`, `FormAction`, `FormEditViewModel`
|
||||
@@ -589,7 +603,7 @@ Gdy `persist = true`:
|
||||
- **NOWE:** `admin\\Controllers\\LanguagesController` (DI) dla akcji `view_list/list`, `language_*`, `translation_*`
|
||||
- **UPDATE:** `admin\\factory\\Languages` jako fasada delegujaca do repozytorium
|
||||
- **CLEANUP:** usunieto legacy `admin\\controls\\Languages` oraz `admin\\view\\Languages`
|
||||
- **UPDATE:** poprawki globalne `components/table-list` dla krotkich kolumn/filtr<74>w
|
||||
- **UPDATE:** poprawki globalne `components/table-list` dla krotkich kolumn/filtr<74>w
|
||||
|
||||
## Aktualizacja 2026-02-12 (ver. 0.255)
|
||||
- UPDATE: SettingsController, BannerController, DictionariesController, ArticlesController pobieraja liste jezykow przez Domain/Languages/LanguagesRepository (DI) zamiast legacy admin/factory/Languages.
|
||||
@@ -700,3 +714,14 @@ Gdy `persist = true`:
|
||||
- UPDATE: endpointy zalezne od Pages w innych modulach (`articles`, `layouts`, `shop-category`, `shop-product`) przepiete z `admin/ajax.php?a=*` na `/admin/pages/*`.
|
||||
- CLEANUP: usuniete `autoload/admin/controls/class.Pages.php`, `autoload/admin/view/class.Pages.php`, `autoload/admin/factory/class.Pages.php`, `admin/ajax/pages.php`; `admin/ajax.php` nie includuje juz `ajax/pages.php`.
|
||||
- Testy: **OK (186 tests, 478 assertions)**.
|
||||
|
||||
## Aktualizacja 2026-02-13 - Integrations (/admin/integrations)
|
||||
- NOWE: `Domain\Integrations\IntegrationsRepository` (settings Apilo/ShopPRO, OAuth, product linking, API fetch lists, product search/create, ShopPRO import).
|
||||
- NOWE: `admin\Controllers\IntegrationsController` (DI) dla akcji: `apilo_settings`, `apilo_settings_save`, `apilo_authorization`, `get_platform_list`, `get_status_types_list`, `get_carrier_account_list`, `get_payment_types_list`, `apilo_create_product`, `apilo_product_search`, `apilo_product_select_save`, `apilo_product_select_delete`, `shoppro_settings`, `shoppro_settings_save`, `shoppro_product_import`.
|
||||
- UPDATE: `admin\factory\Integrations` jako fasada delegujaca do `Domain\Integrations\IntegrationsRepository` (tylko Apilo + ShopPRO).
|
||||
- **CLEANUP: usunieto integracje Sellasist i Baselinker z calego projektu:**
|
||||
- Usuniete klasy: `admin\controls\Integrations`, `admin\controls\Baselinker`, `admin\factory\Baselinker`, `front\factory\Shop`, `shop\ShopStatus`
|
||||
- Usuniete szablony: `integrations/sellasist-settings.php`, `integrations/baselinker-settings.php`, `admin/templates/baselinker/`
|
||||
- Wyczyszczone referencje w: `cron.php`, `cron/cron-xml.php`, `shop\Order`, `admin\controls\ShopStatuses`, `admin\controls\ShopTransport`, `admin\controls\ShopPaymentMethod`, `admin\controls\ShopProduct`, `admin\factory\ShopStatuses`, `admin\factory\ShopTransport`, `admin\factory\ShopProduct`, `front\factory\ShopStatuses`, `front\factory\ShopTransport`, `front\factory\ShopPaymentMethod`, `front\factory\ShopProduct`, `front\factory\ShopOrder`, `shop\Product`, `config.php`
|
||||
- Wyczyszczone szablony: `shop-statuses/*`, `shop-transport/*`, `shop-payment-method/*`, `shop-product/*`, `site/main-layout.php`
|
||||
- Testy: **OK (212 tests, 577 assertions)**.
|
||||
|
||||
18
TESTING.md
18
TESTING.md
@@ -52,11 +52,13 @@ tests/
|
||||
| | |-- Dictionaries/DictionariesRepositoryTest.php
|
||||
| | |-- Product/ProductRepositoryTest.php
|
||||
| | |-- Settings/SettingsRepositoryTest.php
|
||||
| | `-- User/UserRepositoryTest.php
|
||||
| | |-- User/UserRepositoryTest.php
|
||||
| | `-- Integrations/IntegrationsRepositoryTest.php
|
||||
| `-- admin/
|
||||
| `-- Controllers/
|
||||
| |-- ArticlesControllerTest.php
|
||||
| |-- DictionariesControllerTest.php
|
||||
| |-- IntegrationsControllerTest.php
|
||||
| |-- ProductArchiveControllerTest.php
|
||||
| |-- SettingsControllerTest.php
|
||||
| `-- UsersControllerTest.php
|
||||
@@ -281,3 +283,17 @@ Nowe testy dodane 2026-02-13:
|
||||
|
||||
Zaktualizowane testy 2026-02-13:
|
||||
- `tests/Unit/admin/Controllers/ArticlesControllerTest.php` (konstruktor z `Domain\\Pages\\PagesRepository`)
|
||||
|
||||
## Aktualizacja suite (Integrations refactor, ver. 0.263)
|
||||
Ostatnio zweryfikowano: 2026-02-13
|
||||
|
||||
```text
|
||||
OK (212 tests, 577 assertions)
|
||||
```
|
||||
|
||||
Nowe testy dodane 2026-02-13:
|
||||
- `tests/Unit/Domain/Integrations/IntegrationsRepositoryTest.php` (16 testow: getSettings, getSetting, saveSetting, linkProduct, unlinkProduct, getProductSku, apiloGetAccessToken, invalid provider, settings table mapping)
|
||||
- `tests/Unit/admin/Controllers/IntegrationsControllerTest.php` (10 testow: kontrakty metod, return types, brak metod sellasist/baselinker)
|
||||
|
||||
Zaktualizowane pliki:
|
||||
- `tests/bootstrap.php` (dodany stub `S::remove_special_chars()`)
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
<form method="POST" action="/admin/baselinker/bundling_products_save/">
|
||||
<table class="table mbn table-hover table-striped table-bordered">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nazwa produktu</th>
|
||||
<th>SKU</th>
|
||||
<th>Produkt w Baselinker</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<? foreach ( $this -> products as $product ):?>
|
||||
<tr>
|
||||
<td><?= $product['name'];?> - <?= $product['id'];?></td>
|
||||
<td><?= $product['sku'];?></td>
|
||||
<td>
|
||||
<select class="form-control" name="product_<?= $product['id'];?>">
|
||||
<option value="">--- wybierz produkt ---</option>
|
||||
<? foreach ( $this -> baselinker_products as $product_baselinker ):?>
|
||||
<option value="<?= $product_baselinker['product_id'];?>"
|
||||
<? if ( $product_baselinker['product_id'] == $product['baselinker_product_id'] or ( $product['sku'] == $product_baselinker['sku'] and $product['sku'] != "" ) ):?>selected="selected"<? endif;?>
|
||||
>
|
||||
<?= $product_baselinker['name'] . ' - ' . $product_baselinker['sku'];?>
|
||||
<? endforeach;?>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<? endforeach;?>
|
||||
</tbody>
|
||||
</table>
|
||||
<button class="btn btn-success btn-sm">
|
||||
<i class="fa fa-check-circle mr5"></i>Zapisz
|
||||
</button>
|
||||
</form>
|
||||
@@ -1,139 +0,0 @@
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">Ustawienia baselinker.com</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Baselinker API</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="api_code" name="api_code" placeholder="" value="<?= $this -> settings['api_code'];?>">
|
||||
<span class="input-group-addon cursor" field-id="api_code">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- magazyn -->
|
||||
<? $storages_list = unserialize( $this -> settings['storages_list'] );?>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Magazyn</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select name="storage_id" id="storage_id" class="form-control">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<? foreach ( $storages_list as $storage ):?>
|
||||
<option value="<?= $storage['storage_id'];?>" <? if ( $this -> settings['storage_id'] == $storage['storage_id'] ):?>selected<? endif;?>><?= $storage['name'];?></option>
|
||||
<? endforeach;?>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="storage_id">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację z baselinker.com</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="enabled" name="enabled">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['enabled'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['enabled'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="enabled">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację produktów</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_products" name="sync_products">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_products'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_products'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_products">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację zamówień</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_orders" name="sync_orders">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_orders'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_orders'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_orders">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Data rozpoczęcia synchronizacji zamówień</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="sync_orders_date_start" name="sync_orders_date_start" placeholder="" value="<?= $this -> settings['sync_orders_date_start'];?>">
|
||||
<span class="input-group-addon cursor" field-id="sync_orders_date_start">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<a href="/admin/integrations/baselinker_get_order_status_list/" class="btn btn-primary btn-block">Pobierz statusy zamówień</a>
|
||||
<!-- pobierz listę magazynów -->
|
||||
<a href="/admin/integrations/baselinker_get_storages_list/" class="btn btn-primary btn-block">Pobierz listę magazynów</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('body').on('click', '.input-group-addon', function() {
|
||||
var field_id = $(this).attr('field-id');
|
||||
var value = $('#' + field_id).val();
|
||||
$.ajax({
|
||||
url: '/admin/integrations/baselinker_settings_save/',
|
||||
type: 'POST',
|
||||
data: {
|
||||
field_id: field_id,
|
||||
value: value
|
||||
},
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if (response.status == 'ok') {
|
||||
$('#' + field_id).val(response.value);
|
||||
$('#' + field_id).closest('.form-group').addClass('has-success');
|
||||
setTimeout(function() {
|
||||
$('#' + field_id).closest('.form-group').removeClass('has-success');
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@@ -1,119 +0,0 @@
|
||||
<div class="panel panel-danger">
|
||||
<div class="panel-heading">
|
||||
<span class="panel-title">Ustawienia sellasist.com</span>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Sellasist API</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="api_code" name="api_code" placeholder="" value="<?= $this -> settings['api_code'];?>">
|
||||
<span class="input-group-addon cursor" field-id="api_code">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację z sellasist.com</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="enabled" name="enabled">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['enabled'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['enabled'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="enabled">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację produktów</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_products" name="sync_products">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_products'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_products'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_products">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group mb10">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Włącz synchronizację zamówień</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<select class="form-control" id="sync_orders" name="sync_orders">
|
||||
<option value="">--- wybierz ---</option>
|
||||
<option value="0" <? if ( !$this -> settings['sync_orders'] ):?>selected<? endif;?>>nie</option>
|
||||
<option value="1" <? if ( $this -> settings['sync_orders'] ):?>selected<? endif;?>>tak</option>
|
||||
</select>
|
||||
<span class="input-group-addon cursor" field-id="sync_orders">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="col-lg-3 control-label" for="inputDefault">Data rozpoczęcia synchronizacji zamówień</label>
|
||||
<div class="col-lg-9">
|
||||
<div class="bs-component">
|
||||
<div class="input-group">
|
||||
<input class="form-control" type="text" id="sync_orders_date_start" name="sync_orders_date_start" placeholder="" value="<?= $this -> settings['sync_orders_date_start'];?>">
|
||||
<span class="input-group-addon cursor" field-id="sync_orders_date_start">
|
||||
<i class="fa fa-save"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<a href="/admin/integrations/get_sellasist_status_types_list/" class="btn btn-primary btn-block">Pobierz statusy zamówień</a>
|
||||
<a href="/admin/integrations/get_sellasist_payment_types_list/" class="btn btn-primary btn-block">Pobierz metody płatności</a>
|
||||
<a href="/admin/integrations/get_sellasist_shipments_list/" class="btn btn-primary btn-block">Pobierz metody dostawy</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
$('body').on('click', '.input-group-addon', function() {
|
||||
var field_id = $(this).attr('field-id');
|
||||
var value = $('#' + field_id).val();
|
||||
$.ajax({
|
||||
url: '/admin/integrations/sellasist_settings_save/',
|
||||
type: 'POST',
|
||||
data: {
|
||||
field_id: field_id,
|
||||
value: value
|
||||
},
|
||||
success: function(response) {
|
||||
response = JSON.parse(response);
|
||||
if (response.status == 'ok') {
|
||||
$('#' + field_id).val(response.value);
|
||||
$('#' + field_id).closest('.form-group').addClass('has-success');
|
||||
setTimeout(function() {
|
||||
$('#' + field_id).closest('.form-group').removeClass('has-success');
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
});
|
||||
</script>
|
||||
@@ -5,10 +5,6 @@ foreach ( $this -> apilo_payment_types_list as $payment_type )
|
||||
if ( isset( $payment_type['name'] ) && isset( $payment_type['id'] ) )
|
||||
$payment_types[ $payment_type['id'] ] = $payment_type['name'];
|
||||
}
|
||||
// sellasist payment methods
|
||||
$sellasist_payment_types_list = [];
|
||||
foreach ( $this -> sellasist_payment_types_list as $sellasist_payment_type )
|
||||
$sellasist_payment_types_list[ $sellasist_payment_type['id'] ] = $sellasist_payment_type['title'];
|
||||
|
||||
$grid = new \grid( 'pp_shop_payment_methods' );
|
||||
$grid -> gdb_opt = $gdb;
|
||||
@@ -39,12 +35,6 @@ $grid -> columns_view = [
|
||||
'replace' => [ 'array' => $payment_types ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
|
||||
], [
|
||||
'name' => 'Typ płatności Sellasist',
|
||||
'db' => 'sellasist_payment_type_id',
|
||||
'replace' => [ 'array' => $sellasist_payment_types_list ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'th' => [ 'class' => 'g-center', 'style' => 'width: 150px;' ]
|
||||
]
|
||||
];
|
||||
|
||||
@@ -63,11 +53,6 @@ $grid -> columns_edit = [
|
||||
'type' => 'select',
|
||||
'name' => 'Typ płatności Apilo',
|
||||
'replace' => [ 'array' => $payment_types ],
|
||||
], [
|
||||
'db' => 'sellasist_payment_type_id',
|
||||
'type' => 'select',
|
||||
'name' => 'Typ płatności Sellasist',
|
||||
'replace' => [ 'array' => $sellasist_payment_types_list ],
|
||||
], [
|
||||
'name' => 'Aktywny',
|
||||
'db' => 'status',
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
<th>Stan magazynowy</th>
|
||||
<th>Cena netto</th>
|
||||
<th>Zam. SM 0</th>
|
||||
<th>Baselinker</th>
|
||||
<th style="width: 100px;">Opcje</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -50,14 +49,6 @@
|
||||
<td>
|
||||
<input type="checkbox" name="stock_0_buy" <? if ( $product['stock_0_buy'] ): echo 'checked="checked"'; endif;?> onchange="$.ajax({ type: 'POST', cache: false, url: '/admin/shop_product/product_combination_stock_0_buy_save/', data: { product_id: <?= $product['id'];?>, stock_0_buy: $( this ).is( ':checked' ) } } );">
|
||||
</td>
|
||||
<td>
|
||||
<?
|
||||
if ( $product['baselinker_product_name'] != "" )
|
||||
echo "<span title='" . $product['baselinker_product_name'] . "'>" . substr( $product['baselinker_product_name'], 0, 25 ) . "...</span>";
|
||||
else
|
||||
echo "<span class='text-danger baselinker-product-search' product-id='" . $product['id'] . "'>nie przypisano <i class='fa fa-search'></i></span>";
|
||||
?>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a href="/admin/shop_product/delete_combination/combination_id=<?= $product['id'];?>&product_id=<?= $product['parent_id'];?>" class="btn btn-danger btn-delete-permutation"><i class="fa fa-trash"></i></a>
|
||||
</td>
|
||||
@@ -138,86 +129,5 @@
|
||||
return false;
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.baselinker-product-search', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/shop_product/baselinker_product_search/',
|
||||
data: {
|
||||
product_id: product_id
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'SUCCESS' ) {
|
||||
$('.baselinker-found-products').remove();
|
||||
var html = '<div class="baselinker-found-products">';
|
||||
html += '<p>Znaleziono ' + data.products.length + ' produktów</p>';
|
||||
html += '<select class="form-control baselinker-product-select" product-id="' + product_id + '">';
|
||||
$.each( data.products, function( index, value ) {
|
||||
html += '<option value="' + value.product_id + '">' + value.name + ' SKU: ' + value.sku + '</option>';
|
||||
});
|
||||
html += '</select>';
|
||||
html += '<button class="btn btn-success baselinker-product-select-save" product-id="' + product_id + '">Zapisz</button>';
|
||||
html += '</div>';
|
||||
$( 'span[product-id="' + product_id + '"]' ).closest( 'td' ).append( html );
|
||||
} else if ( data.status == 'error' ) {
|
||||
$.alert({
|
||||
title: 'Błąd',
|
||||
content: data.msg,
|
||||
type: 'red',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-times',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
columnClass: 'col-12 col-lg-10',
|
||||
theme: 'modern',
|
||||
icon: 'fa fa-exclamation-triangle',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'OK',
|
||||
btnClass: 'btn-danger',
|
||||
keys: ['enter'],
|
||||
action: function() {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.baselinker-product-select-save', function(){
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
var baselinker_product_id = $( '.baselinker-product-select[product-id="' + product_id + '"]' ).val();
|
||||
var baselinker_product_name = $( '.baselinker-product-select[product-id="' + product_id + '"] option:selected' ).text();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/shop_product/baselinker_product_select_save/',
|
||||
data: {
|
||||
product_id: product_id,
|
||||
baselinker_product_id: baselinker_product_id,
|
||||
baselinker_product_name: baselinker_product_name
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'ok' ) {
|
||||
$( '.baselinker-product-select[product-id="' + product_id + '"]' ).closest( '.baselinker-found-products' ).remove();
|
||||
$( 'span[product-id="' + product_id + '"]' ).html( '<span title="' + baselinker_product_name + '">' + baselinker_product_name.substr( 0, 25 ) + '...</span>' ).removeClass( 'baselinker-product-search' ).removeClass( 'text-danger' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@@ -21,15 +21,15 @@ ob_start();
|
||||
<div id="settings-tabs">
|
||||
<ul class="resp-tabs-list settings-tabs">
|
||||
<li><i class="fa fa-file"></i>Opis</li>
|
||||
<li><i class="fa fa-file"></i>Zakładki</li>
|
||||
<li><i class="fa fa-file"></i>Zakładki</li>
|
||||
<li><i class="fa fa-dollar"></i>Cena</li>
|
||||
<li><i class="fa fa-home"></i>Magazyn</li>
|
||||
<li><i class="fa fa-wrench"></i>Ustawienia</li>
|
||||
<li><i class="fa fa-globe"></i>SEO</li>
|
||||
<li><i class="fa fa-share-alt"></i>Wyświetlanie</li>
|
||||
<li><i class="fa fa-share-alt"></i>Wyświetlanie</li>
|
||||
<li><i class="fa fa-file-image-o"></i>Galeria</li>
|
||||
<li><i class="fa fa-file-archive-o"></i>Załączniki</li>
|
||||
<li><i class="fa fa-exchange"></i>Produkty powiÄ…zane</li>
|
||||
<li><i class="fa fa-file-archive-o"></i>Załączniki</li>
|
||||
<li><i class="fa fa-exchange"></i>Produkty powiązane</li>
|
||||
<li><i class="fa fa-file-excel-o"></i>XML</li>
|
||||
<li><i class="fa fa-file-o"></i>Dodatkowe pola</li>
|
||||
<li><i class="fa fa-file-o"></i>GPSR</li>
|
||||
@@ -40,7 +40,7 @@ ob_start();
|
||||
<ul class="resp-tabs-list languages-main htabs">
|
||||
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
||||
<? if ($lg['status']) : ?>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></a></li>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></a></li>
|
||||
<? endif; ?>
|
||||
<?
|
||||
endforeach;
|
||||
@@ -52,7 +52,7 @@ ob_start();
|
||||
<?
|
||||
$languages = array();
|
||||
|
||||
$languages[''] = '---- wersja językowa ----';
|
||||
$languages[''] = '---- wersja językowa ----';
|
||||
if (is_array($this->languages))
|
||||
foreach ($this->languages as $lg_tmp)
|
||||
{
|
||||
@@ -65,7 +65,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::select(
|
||||
array(
|
||||
'label' => 'Wyświetlaj treść z wersji',
|
||||
'label' => 'Wyświetlaj treść z wersji',
|
||||
'name' => 'copy_from[' . $lg['id'] . ']',
|
||||
'values' => $languages,
|
||||
'value' => $this->product['languages'][$lg['id']]['copy_from'],
|
||||
@@ -86,7 +86,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::input(
|
||||
array(
|
||||
'label' => 'Komunikat gdy stan magazynowy rĂłwny 0',
|
||||
'label' => 'Komunikat gdy stan magazynowy równy 0',
|
||||
'name' => 'warehouse_message_zero[' . $lg['id'] . ']',
|
||||
'id' => 'warehouse_message_zero_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['warehouse_message_zero'],
|
||||
@@ -97,7 +97,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::input(
|
||||
array(
|
||||
'label' => 'Komunikat gdy stan magazynowy większy niż 0',
|
||||
'label' => 'Komunikat gdy stan magazynowy większy niż 0',
|
||||
'name' => 'warehouse_message_nonzero[' . $lg['id'] . ']',
|
||||
'id' => 'warehouse_message_nonzero_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['warehouse_message_nonzero'],
|
||||
@@ -108,7 +108,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::textarea(
|
||||
array(
|
||||
'label' => 'KrĂłtki opis',
|
||||
'label' => 'Krótki opis',
|
||||
'name' => 'short_description[' . $lg['id'] . ']',
|
||||
'id' => 'short_description_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['short_description'],
|
||||
@@ -154,7 +154,7 @@ ob_start();
|
||||
<ul class="resp-tabs-list languages-tabs htabs">
|
||||
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
||||
<? if ($lg['status']) : ?>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></a></li>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></a></li>
|
||||
<? endif; ?>
|
||||
<?
|
||||
endforeach;
|
||||
@@ -166,7 +166,7 @@ ob_start();
|
||||
<?
|
||||
$languages = array();
|
||||
|
||||
$languages[''] = '---- wersja językowa ----';
|
||||
$languages[''] = '---- wersja językowa ----';
|
||||
if (is_array($this->languages))
|
||||
foreach ($this->languages as $lg_tmp)
|
||||
{
|
||||
@@ -179,7 +179,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::input(
|
||||
array(
|
||||
'label' => 'Nazwa zakładki (1)',
|
||||
'label' => 'Nazwa zakładki (1)',
|
||||
'name' => 'tab_name_1[' . $lg['id'] . ']',
|
||||
'id' => 'tab_name_1_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['tab_name_1'],
|
||||
@@ -190,7 +190,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::textarea(
|
||||
array(
|
||||
'label' => 'Zawartość zakładki (1)',
|
||||
'label' => 'Zawartość zakładki (1)',
|
||||
'name' => 'tab_description_1[' . $lg['id'] . ']',
|
||||
'id' => 'tab_description_1_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['tab_description_1'],
|
||||
@@ -201,7 +201,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::input(
|
||||
array(
|
||||
'label' => 'Nazwa zakładki (2)',
|
||||
'label' => 'Nazwa zakładki (2)',
|
||||
'name' => 'tab_name_2[' . $lg['id'] . ']',
|
||||
'id' => 'tab_name_2_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['tab_name_2'],
|
||||
@@ -212,7 +212,7 @@ ob_start();
|
||||
<?=
|
||||
\Html::textarea(
|
||||
array(
|
||||
'label' => 'Zawartość zakładki (2)',
|
||||
'label' => 'Zawartość zakładki (2)',
|
||||
'name' => 'tab_description_2[' . $lg['id'] . ']',
|
||||
'id' => 'tab_description_2_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['tab_description_2'],
|
||||
@@ -305,7 +305,7 @@ ob_start();
|
||||
?>
|
||||
|
||||
<?
|
||||
$units[] = '--- wybierze jednostkÄ™ miary ---';
|
||||
$units[] = '--- wybierze jednostkę miary ---';
|
||||
foreach ($this->units as $unit)
|
||||
$units[$unit['id']] = $unit['text'];
|
||||
?>
|
||||
@@ -317,7 +317,7 @@ ob_start();
|
||||
'value' => $this->product['product_unit_id']
|
||||
]); ?>
|
||||
<?= \Html::input([
|
||||
'label' => 'Waga/pojemność',
|
||||
'label' => 'Waga/pojemność',
|
||||
'name' => 'weight',
|
||||
'id' => 'weight',
|
||||
'class' => 'number-format',
|
||||
@@ -336,14 +336,14 @@ ob_start();
|
||||
?>
|
||||
<?=
|
||||
\Html::input_switch([
|
||||
'label' => 'Pozwól zamawiać gdy stan 0',
|
||||
'label' => 'Pozwól zamawiać gdy stan 0',
|
||||
'name' => 'stock_0_buy',
|
||||
'checked' => $this->product['stock_0_buy'] == 1 ? true : false
|
||||
]);
|
||||
?>
|
||||
<?=
|
||||
\Html::input([
|
||||
'label' => 'Współczynnik WP',
|
||||
'label' => 'Współczynnik WP',
|
||||
'name' => 'wp',
|
||||
'id' => 'wp',
|
||||
'class' => 'number-format',
|
||||
@@ -382,7 +382,7 @@ ob_start();
|
||||
?>
|
||||
<?=
|
||||
\Html::input([
|
||||
'label' => 'Nowość do dnia',
|
||||
'label' => 'Nowość do dnia',
|
||||
'name' => 'new_to_date',
|
||||
'id' => 'new_to_date',
|
||||
'class' => 'date',
|
||||
@@ -390,19 +390,19 @@ ob_start();
|
||||
]);
|
||||
?>
|
||||
<?= \Html::input_switch([
|
||||
'label' => 'Wyświetlaj pole na dodatkową wiadomość',
|
||||
'label' => 'Wyświetlaj pole na dodatkową wiadomość',
|
||||
'name' => 'additional_message',
|
||||
'checked' => $this->product['additional_message'] == 1 ? true : false
|
||||
]);
|
||||
?>
|
||||
<?= \Html::input_switch([
|
||||
'label' => 'Dodatkowa wiadomość jest wymagana',
|
||||
'label' => 'Dodatkowa wiadomość jest wymagana',
|
||||
'name' => 'additional_message_required',
|
||||
'checked' => $this->product['additional_message_required'] == 1 ? true : false
|
||||
]);
|
||||
?>
|
||||
<?= \Html::input([
|
||||
'label' => 'Dodatkowa wiadomość (treść komunikatu)',
|
||||
'label' => 'Dodatkowa wiadomość (treść komunikatu)',
|
||||
'name' => 'additional_message_text',
|
||||
'id' => 'additional_message_text',
|
||||
'value' => $this->product['additional_message_text']
|
||||
@@ -414,7 +414,7 @@ ob_start();
|
||||
<ul class="resp-tabs-list languages-seo htabs">
|
||||
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
||||
<? if ($lg['status']) : ?>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||
<? endif; ?>
|
||||
<?
|
||||
endforeach;
|
||||
@@ -481,7 +481,7 @@ ob_start();
|
||||
</div>
|
||||
<div>
|
||||
<?
|
||||
$layouts[''] = '---- szablon domyślny ----';
|
||||
$layouts[''] = '---- szablon domyślny ----';
|
||||
if (is_array($this->layouts)) : foreach ($this->layouts as $layout) :
|
||||
$layouts[$layout['id']] = $layout['name'];
|
||||
endforeach;
|
||||
@@ -497,7 +497,7 @@ ob_start();
|
||||
]);
|
||||
?>
|
||||
<div class="form-group row">
|
||||
<label class="col-md-4 control-label">Wyświetlaj w:</label>
|
||||
<label class="col-md-4 control-label">Wyświetlaj w:</label>
|
||||
<div class="col-md-8">
|
||||
<div class="menu_sortable">
|
||||
<ol class="sortable" id="sortable">
|
||||
@@ -580,7 +580,7 @@ ob_start();
|
||||
</div>
|
||||
<div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-4 control-label">Wybierz zdefiniowany komplet produktĂłw:</label>
|
||||
<label class="col-lg-4 control-label">Wybierz zdefiniowany komplet produktów:</label>
|
||||
<div class="col-lg-8">
|
||||
<select id="set" class="form-control" name="set">
|
||||
<option value="">wybierz komplet...</option>
|
||||
@@ -591,9 +591,9 @@ ob_start();
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label class="col-lg-4 control-label">Produkty powiÄ…zane:</label>
|
||||
<label class="col-lg-4 control-label">Produkty powiązane:</label>
|
||||
<div class="col-lg-8">
|
||||
<select id="products_related" multiple name="products_related[]" placeholder="produkty powiÄ…zane">
|
||||
<select id="products_related" multiple name="products_related[]" placeholder="produkty powiązane">
|
||||
<option value="">wybierz produkt...</option>
|
||||
<? foreach ($this->products as $key => $val) : ?>
|
||||
<? if ($key != $this->product['id']) : ?>
|
||||
@@ -622,7 +622,7 @@ ob_start();
|
||||
<? if (is_array($this->languages)) : foreach ($this->languages as $lg) : ?>
|
||||
<? if ($lg['status']) : ?>
|
||||
<div id="xml_name_<?= $this->i; ?>_<?= $lg['id']; ?>" class="tab-pane <? if (!$z++) : ?>active<? endif; ?>">
|
||||
<label class="col-lg-4 control-label">Nazwa produktu XML (150 znakĂłw):</label>
|
||||
<label class="col-lg-4 control-label">Nazwa produktu XML (150 znaków):</label>
|
||||
<div class="col-lg-8">
|
||||
<input type="text" class="form-control" name="xml_name[<?= $lg['id']; ?>]" value="<?= $this->product['languages'][$lg['id']]['xml_name']; ?>">
|
||||
</div>
|
||||
@@ -700,7 +700,7 @@ ob_start();
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-sm-12 text-right">
|
||||
<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>
|
||||
<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -724,7 +724,7 @@ ob_start();
|
||||
<ul class="resp-tabs-list gpsr-seo htabs">
|
||||
<? if ( is_array( $this -> languages ) ): foreach ( $this -> languages as $lg ):?>
|
||||
<? if ($lg['status']) : ?>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||
<li><? if ($lg['id'] == \front\factory\Languages::default_language()) echo '<i class="fa fa-star fa-lg text-system" title="Język domyślny"></i> '; ?><?= $lg['name']; ?></li>
|
||||
<? endif; ?>
|
||||
<? endforeach; endif; ?>
|
||||
</ul>
|
||||
@@ -733,7 +733,7 @@ ob_start();
|
||||
<? if ( $lg['status'] ):?>
|
||||
<div>
|
||||
<?= \Html::textarea( [
|
||||
'label' => 'Informacje o bezpieczeństwie ('.$lg['name'].')',
|
||||
'label' => 'Informacje o bezpieczeństwie ('.$lg['name'].')',
|
||||
'name' => 'security_information[' . $lg['id'] . ']',
|
||||
'id' => 'security_information_' . $lg['id'],
|
||||
'value' => $this->product['languages'][$lg['id']]['security_information']
|
||||
@@ -776,7 +776,7 @@ $grid->actions = [
|
||||
];
|
||||
$grid->buttons = [
|
||||
[
|
||||
'label' => 'PodglÄ…d',
|
||||
'label' => 'Podgląd',
|
||||
'id' => 'product-preview',
|
||||
'url' => '#',
|
||||
'icon' => 'fa-search',
|
||||
@@ -845,7 +845,7 @@ echo $grid->draw();
|
||||
html += '</div>';
|
||||
html += '<div class="form-group row">';
|
||||
html += '<div class="col-sm-12 text-right">';
|
||||
html += '<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>';
|
||||
html += '<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
html += '</div>';
|
||||
@@ -1138,8 +1138,8 @@ echo $grid->draw();
|
||||
$(this).blur();
|
||||
var file_id = $(this).attr('file_id');
|
||||
|
||||
$.prompt('Na pewno chcesz usunąć wybrany plik?', {
|
||||
title: 'PotwierdĹş?',
|
||||
$.prompt('Na pewno chcesz usunąć wybrany plik?', {
|
||||
title: 'Potwierdź?',
|
||||
submit: function(e, v, m, f) {
|
||||
if (v === true) {
|
||||
$.ajax({
|
||||
@@ -1178,8 +1178,8 @@ echo $grid->draw();
|
||||
$(this).blur();
|
||||
var image_id = $(this).attr('image-id');
|
||||
|
||||
$.prompt('Na pewno chcesz usunąć wybrane zdjęcie?', {
|
||||
title: 'PotwierdĹş?',
|
||||
$.prompt('Na pewno chcesz usunąć wybrane zdjęcie?', {
|
||||
title: 'Potwierdź?',
|
||||
submit: function(e, v, m, f) {
|
||||
if (v === true) {
|
||||
$.ajax({
|
||||
|
||||
@@ -36,23 +36,6 @@
|
||||
<td class="text-center">
|
||||
<span class="text-muted"><?= (int)\admin\factory\shopProduct::get_product_quantity_list( $product['id'] );?></span>
|
||||
</td>
|
||||
<? if ( $this -> baselinker_enabled ):?>
|
||||
<td class="text-center">
|
||||
<?
|
||||
if ( $product['baselinker_product_name'] != "" ) {
|
||||
echo "<span title='" . htmlspecialchars( $product['baselinker_product_name'] ) . "'>" . mb_substr( $product['baselinker_product_name'], 0, 25, 'UTF-8' ) . "...</span>";
|
||||
echo "<br>";
|
||||
echo "<span class='text-danger baselinker-delete-linking' product-id='" . $product['id'] . "'>";
|
||||
echo "<i class='fa fa-times'></i>usuń powiązanie";
|
||||
echo "</span>";
|
||||
} else {
|
||||
echo "<span class='text-danger baselinker-product-search' product-id='" . $product['id'] . "'>";
|
||||
echo "nie przypisano <i class='fa fa-search'></i>";
|
||||
echo "</span>";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<? endif;?>
|
||||
<? if ( $this -> apilo_enabled ):?>
|
||||
<td class="text-center">
|
||||
<?
|
||||
@@ -70,24 +53,6 @@
|
||||
?>
|
||||
</td>
|
||||
<? endif;?>
|
||||
<!-- sellasist -->
|
||||
<? if ( $this -> sellasist_enabled ):?>
|
||||
<td class="text-center">
|
||||
<?
|
||||
if ( $product['sellasist_product_name'] != "" ) {
|
||||
echo "<span title='" . htmlspecialchars( $product['sellasist_product_name'] ) . "'>" . mb_substr( $product['sellasist_product_name'], 0, 25, "UTF-8" ) . "...</span>";
|
||||
echo "<br>";
|
||||
echo "<span class='text-danger sellasist-delete-linking' product-id='" . $product['id'] . "'>";
|
||||
echo "<i class='fa fa-times'></i>usuń powiązanie";
|
||||
echo "</span>";
|
||||
} else {
|
||||
echo "<span class='text-danger sellasist-product-search' product-id='" . $product['id'] . "'>";
|
||||
echo "nie przypisano <i class='fa fa-search'></i>";
|
||||
echo "</span>";
|
||||
}
|
||||
?>
|
||||
</td>
|
||||
<? endif;?>
|
||||
<td>
|
||||
<a href='/admin/shop_product/product_combination/product_id=<?= $product['id'];?>'>kombinacje (<?= \admin\factory\shopProduct::count_product_combinations( $product['id'] );?>)</a>
|
||||
</td>
|
||||
|
||||
@@ -23,15 +23,9 @@
|
||||
<th class="text-center" style="width: 25px;">Promowany</th>
|
||||
<th class="text-center" style="width: 25px;">Aktywny</th>
|
||||
<th class="text-center" style="width: 75px;">Stan MG</th>
|
||||
<? if ( $this -> baselinker_enabled ):?>
|
||||
<th class="text-center" style="width: 100px;">Baselinker</th>
|
||||
<? endif;?>
|
||||
<? if ( $this -> apilo_enabled ):?>
|
||||
<th class="text-center" style="width: 100px;">Apilo</th>
|
||||
<? endif;?>
|
||||
<? if ( $this -> sellasist_enabled ):?>
|
||||
<th class="text-center" style="width: 100px;">Sellasist</th>
|
||||
<? endif;?>
|
||||
<th class="text-center" style="width: 100px;">Kombinacje</th>
|
||||
<th class="text-center" style="width: 75px;">Edytuj</th>
|
||||
<th class="text-center" style="width: 75px;">Archiwizuj</th>
|
||||
@@ -305,60 +299,6 @@
|
||||
});
|
||||
})
|
||||
|
||||
// sellasist product search
|
||||
$( 'body' ).on( 'click', '.sellasist-product-search', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/sellasist_product_search/',
|
||||
data: {
|
||||
product_id: product_id
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'SUCCESS' ) {
|
||||
var html = '<div class="sellasist-found-products">';
|
||||
html += '<p>Znaleziono ' + data.products.length + ' produktów</p>';
|
||||
html += '<select class="form-control sellasist-product-select" product-id="' + product_id + '">';
|
||||
$.each( data.products, function( index, value ) {
|
||||
html += '<option value="' + value.id + '">' + value.name + ' SKU: ' + value.symbol + '</option>';
|
||||
});
|
||||
html += '</select>';
|
||||
html += '<button class="btn btn-success sellasist-product-select-save" product-id="' + product_id + '">Zapisz</button>';
|
||||
html += '</div>';
|
||||
$( 'span.sellasist-product-search[product-id="' + product_id + '"]' ).closest( 'td' ).append( html );
|
||||
} else if ( data.status == 'error' ) {
|
||||
$.alert({
|
||||
title: 'Błąd',
|
||||
content: data.msg,
|
||||
type: 'red',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-times',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
columnClass: 'col-12 col-lg-10',
|
||||
theme: 'modern',
|
||||
icon: 'fa fa-exclamation-triangle',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'OK',
|
||||
btnClass: 'btn-danger',
|
||||
keys: ['enter'],
|
||||
action: function() {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// apilo product search
|
||||
$( 'body' ).on( 'click', '.apilo-product-search', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
@@ -380,9 +320,8 @@
|
||||
{
|
||||
if ( data.products.length == 0 )
|
||||
{
|
||||
var html = '<div class="baselinker-found-products">';
|
||||
var html = '<div class="apilo-found-products">';
|
||||
html += '<p>Nie znaleziono produktów</p>';
|
||||
// button to create product on baselinker
|
||||
html += '<a href="/admin/integrations/apilo_create_product/product-id=' + product_id + '" class="btn btn-success btn_apilo_create_product" product_id="' + product_id + '">Utwórz produkt</a>';
|
||||
html += '</div>';
|
||||
$( 'span.apilo-product-search[product-id="' + product_id + '"]' ).closest( 'td' ).append( html );
|
||||
@@ -428,30 +367,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
// sellasist product delete linking
|
||||
$( 'body' ).on( 'click', '.sellasist-delete-linking', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/sellasist_product_select_delete/',
|
||||
data: {
|
||||
product_id: product_id
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'ok' ) {
|
||||
$( 'span.sellasist-delete-linking[product-id="' + product_id + '"]' ).closest('td').html( '<span class="text-danger sellasist-product-search" product-id="' + product_id + '">nie przypisano <i class="fa fa-search"></i></span>' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// delete apilo product linking
|
||||
$( 'body' ).on( 'click', '.apilo-delete-linking', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
@@ -476,31 +391,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
// delete baselinker product linking
|
||||
$( 'body' ).on( 'click', '.baselinker-delete-linking', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/baselinker_product_select_delete/',
|
||||
data: {
|
||||
product_id: product_id
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'ok' ) {
|
||||
$( 'span.baselinker-delete-linking[product-id="' + product_id + '"]' ).closest('td').html( '<span class="text-danger baselinker-product-search" product-id="' + product_id + '">nie przypisano <i class="fa fa-search"></i></span>' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// aplio product create button click with alert confirmation
|
||||
// apilo product create button click with alert confirmation
|
||||
$( 'body' ).on( 'click', '.btn_apilo_create_product', function(e)
|
||||
{
|
||||
e.preventDefault();
|
||||
@@ -540,137 +431,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
// baselinker product create button click with alert confirmation
|
||||
$( 'body' ).on( 'click', '.btn-create-product', function(e) {
|
||||
e.preventDefault();
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.alert({
|
||||
title: 'Pytanie',
|
||||
content: 'Na pewno chcesz utworzyć produkt w bazie Baselinker?',
|
||||
type: 'orange',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-times',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
columnClass: 'col-12 col-lg-10',
|
||||
theme: 'modern',
|
||||
icon: 'fa fa-question',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'Tak',
|
||||
btnClass: 'btn-success',
|
||||
keys: ['enter'],
|
||||
action: function() {
|
||||
document.location.href = '/admin/integrations/baselinker_create_product/product_id=' + product_id;
|
||||
}
|
||||
},
|
||||
cancel: {
|
||||
text: 'Nie',
|
||||
btnClass: 'btn-danger',
|
||||
action: function() {}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.baselinker-product-search', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/baselinker_product_search/',
|
||||
data: {
|
||||
product_id: product_id
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'SUCCESS' )
|
||||
{
|
||||
if ( data.products.length == 0 )
|
||||
{
|
||||
var html = '<div class="baselinker-found-products">';
|
||||
html += '<p>Nie znaleziono produktów</p>';
|
||||
// button to create product on baselinker
|
||||
html += '<a href="/admin/integrations/baselinker_create_product/product-id=' + product_id + '" class="btn btn-success btn-create-product" product-id="' + product_id + '">Utwórz produkt</a>';
|
||||
html += '</div>';
|
||||
$( 'span.baselinker-product-search[product-id="' + product_id + '"]' ).closest( 'td' ).append( html );
|
||||
}
|
||||
else
|
||||
{
|
||||
var html = '<div class="baselinker-found-products">';
|
||||
html += '<p>Znaleziono ' + data.products.length + ' produktów</p>';
|
||||
html += '<select class="form-control baselinker-product-select" product-id="' + product_id + '">';
|
||||
$.each( data.products, function( index, value ) {
|
||||
html += '<option value="' + value.product_id + '">' + value.name + ' SKU: ' + value.sku + '</option>';
|
||||
});
|
||||
html += '</select>';
|
||||
html += '<button class="btn btn-success baselinker-product-select-save" product-id="' + product_id + '">Zapisz</button>';
|
||||
html += '</div>';
|
||||
$( 'span.baselinker-product-search[product-id="' + product_id + '"]' ).closest( 'td' ).append( html );
|
||||
}
|
||||
}
|
||||
else if ( data.status == 'error' )
|
||||
{
|
||||
$.alert({
|
||||
title: 'Błąd',
|
||||
content: data.msg,
|
||||
type: 'red',
|
||||
closeIcon: true,
|
||||
closeIconClass: 'fa fa-times',
|
||||
typeAnimated: true,
|
||||
animation: 'opacity',
|
||||
columnClass: 'col-12 col-lg-10',
|
||||
theme: 'modern',
|
||||
icon: 'fa fa-exclamation-triangle',
|
||||
buttons: {
|
||||
confirm: {
|
||||
text: 'OK',
|
||||
btnClass: 'btn-danger',
|
||||
keys: ['enter'],
|
||||
action: function() {}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// sellasist product select save
|
||||
$( 'body' ).on( 'click', '.sellasist-product-select-save', function(){
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
var sellasist_product_id = $( '.sellasist-product-select[product-id="' + product_id + '"]' ).val();
|
||||
var sellasist_product_name = $( '.sellasist-product-select[product-id="' + product_id + '"] option:selected' ).text();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/sellasist_product_select_save/',
|
||||
data: {
|
||||
product_id: product_id,
|
||||
sellasist_product_id: sellasist_product_id,
|
||||
sellasist_product_name: sellasist_product_name
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'ok' ) {
|
||||
$( '.sellasist-product-select[product-id="' + product_id + '"]' ).closest( '.sellasist-found-products' ).remove();
|
||||
$( 'span.sellasist-product-search[product-id="' + product_id + '"]' ).html( '<span title="' + sellasist_product_name + '">' + sellasist_product_name.substr( 0, 25 ) + '...</span>' ).removeClass( 'sellasist-product-search' ).removeClass( 'text-danger' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// apilo product select save
|
||||
$( 'body' ).on( 'click', '.apilo-product-select-save', function(){
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
@@ -700,34 +460,6 @@
|
||||
});
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'click', '.baselinker-product-select-save', function(){
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
var baselinker_product_id = $( '.baselinker-product-select[product-id="' + product_id + '"]' ).val();
|
||||
var baselinker_product_name = $( '.baselinker-product-select[product-id="' + product_id + '"] option:selected' ).text();
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
cache: false,
|
||||
url: '/admin/integrations/baselinker_product_select_save/',
|
||||
data: {
|
||||
product_id: product_id,
|
||||
baselinker_product_id: baselinker_product_id,
|
||||
baselinker_product_name: baselinker_product_name
|
||||
},
|
||||
beforeSend: function() {
|
||||
$( '#overlay' ).show();
|
||||
},
|
||||
success: function( response ) {
|
||||
data = jQuery.parseJSON( response );
|
||||
|
||||
if ( data.status == 'ok' ) {
|
||||
$( '.baselinker-product-select[product-id="' + product_id + '"]' ).closest( '.baselinker-found-products' ).remove();
|
||||
$( 'span.baselinker-product-search[product-id="' + product_id + '"]' ).html( '<span title="' + baselinker_product_name + '">' + baselinker_product_name.substr( 0, 25 ) + '...</span>' ).removeClass( 'baselinker-product-search' ).removeClass( 'text-danger' );
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$( 'body' ).on( 'change', '.product_xml_name', function() {
|
||||
var product_id = $( this ).attr( 'product-id' );
|
||||
var product_xml_name = $( this ).val();
|
||||
|
||||
@@ -7,19 +7,6 @@ foreach ( $this -> apilo_order_status_list as $apilo_status )
|
||||
{
|
||||
$apilo_status_types_list[ $apilo_status['id'] ] = $apilo_status['name'];
|
||||
}
|
||||
// statusy sellasist
|
||||
$sellasist_status_types_list[''] = '--- wybierz status sellasist ---';
|
||||
foreach ( $this -> sellasist_status_types_list as $sellasist_status )
|
||||
{
|
||||
$sellasist_status_types_list[ $sellasist_status['id'] ] = $sellasist_status['name'];
|
||||
}
|
||||
|
||||
// baselinker order_status_list
|
||||
$baselinker_order_status_list[''] = '--- wybierz status baselinker ---';
|
||||
foreach ( $this -> baselinker_order_status_list as $baselinker_status )
|
||||
{
|
||||
$baselinker_order_status_list[ $baselinker_status['id'] ] = $baselinker_status['name'];
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<div id="settings-tabs">
|
||||
@@ -49,22 +36,6 @@ ob_start();
|
||||
'values' => $apilo_status_types_list,
|
||||
'value' => $this -> status['apilo_status_id']
|
||||
] );?>
|
||||
<!-- statust sellasist -->
|
||||
<?= \Html::select( [
|
||||
'label' => 'Status z Sellasist',
|
||||
'name' => 'sellasist_status_id',
|
||||
'id' => 'sellasist_status_id',
|
||||
'values' => $sellasist_status_types_list,
|
||||
'value' => $this -> status['sellasist_status_id']
|
||||
] );?>
|
||||
<!-- status baselinker -->
|
||||
<?= \Html::select( [
|
||||
'label' => 'Status z Baselinker',
|
||||
'name' => 'baselinker_status_id',
|
||||
'id' => 'baselinker_status_id',
|
||||
'values' => $baselinker_order_status_list,
|
||||
'value' => $this -> status['baselinker_status_id']
|
||||
] );?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,20 +5,6 @@ foreach ( $this -> apilo_order_status_list as $apilo_status )
|
||||
$apilo_order_status_list[ $apilo_status['id'] ] = $apilo_status['name'];
|
||||
}
|
||||
|
||||
// sellasist statuses
|
||||
$sellasist_status_types_list = [];
|
||||
foreach ( $this -> sellasist_order_status_list as $sellasist_status )
|
||||
{
|
||||
$sellasist_order_status_list[ $sellasist_status['id'] ] = $sellasist_status['name'];
|
||||
}
|
||||
|
||||
// baselinker order_status_list
|
||||
$baselinker_order_status_list = [];
|
||||
foreach ( $this -> baselinker_order_status_list as $baselinker_status )
|
||||
{
|
||||
$baselinker_order_status_list[ $baselinker_status['id'] ] = $baselinker_status['name'];
|
||||
}
|
||||
|
||||
$grid = new \grid( 'pp_shop_statuses' );
|
||||
$grid -> gdb_opt = $gdb;
|
||||
$grid -> debug = true;
|
||||
@@ -42,14 +28,6 @@ $grid -> columns_view = [
|
||||
'name' => 'Status Apilo',
|
||||
'db' => 'apilo_status_id',
|
||||
'replace' => [ 'array' => $apilo_order_status_list ],
|
||||
], [
|
||||
'name' => 'Status Sellasist',
|
||||
'db' => 'sellasist_status_id',
|
||||
'replace' => [ 'array' => $sellasist_order_status_list ],
|
||||
], [
|
||||
'name' => 'Status Baselinker',
|
||||
'db' => 'baselinker_status_id',
|
||||
'replace' => [ 'array' => $baselinker_order_status_list ],
|
||||
], [
|
||||
'name' => 'Edytuj',
|
||||
'action' => [ 'type' => 'edit', 'url' => '/admin/shop_statuses/status_edit/id=[id]' ],
|
||||
|
||||
@@ -7,12 +7,6 @@ foreach ( $this -> apilo_carrier_account_list as $carrier_account )
|
||||
{
|
||||
$carrier_accounts[ $carrier_account['id'] ] = $carrier_account['name'];
|
||||
}
|
||||
// sellasist_shipments_methods
|
||||
$sellasist_shipments_methods[''] = '--- wybierz metodę wysyłki ---';
|
||||
foreach ( $this -> sellasist_shipments_methods as $sellasist_shipments_method )
|
||||
{
|
||||
$sellasist_shipments_methods[ $sellasist_shipments_method['id'] ] = $sellasist_shipments_method['title'];
|
||||
}
|
||||
ob_start();
|
||||
?>
|
||||
<div id="settings-tabs">
|
||||
@@ -90,14 +84,6 @@ ob_start();
|
||||
'values' => $carrier_accounts,
|
||||
'value' => $this -> transport_details['apilo_carrier_account_id']
|
||||
] );?>
|
||||
<!-- sellasist_shipments_methods -->
|
||||
<?= \Html::select( [
|
||||
'label' => 'Metoda wysyłki z Sellasist',
|
||||
'name' => 'sellasist_shipment_method_id',
|
||||
'id' => 'sellasist_shipment_method_id',
|
||||
'values' => $sellasist_shipments_methods,
|
||||
'value' => $this -> transport_details['sellasist_shipment_method_id']
|
||||
] );?>
|
||||
</div>
|
||||
<div>
|
||||
<? if ( is_array( $this -> payments_list ) ): foreach ( $this -> payments_list as $payment_method ):?>
|
||||
|
||||
@@ -5,12 +5,6 @@ foreach ( $this -> apilo_carrier_account_list as $carrier_account )
|
||||
{
|
||||
$carrier_accounts[ $carrier_account['id'] ] = $carrier_account['name'];
|
||||
}
|
||||
// sellasist_shipments_methods
|
||||
$sellasist_shipments_methods = [];
|
||||
foreach ( $this -> sellasist_shipments_methods as $sellasist_shipments_method )
|
||||
{
|
||||
$sellasist_shipments_methods[ $sellasist_shipments_method['id'] ] = $sellasist_shipments_method['title'];
|
||||
}
|
||||
|
||||
$grid = new \grid( 'pp_shop_transports' );
|
||||
$grid -> gdb_opt = $gdb;
|
||||
@@ -67,12 +61,6 @@ $grid -> columns_view = [
|
||||
'th' => [ 'class' => 'g-center' ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'replace' => [ 'array' => $carrier_accounts ],
|
||||
], [
|
||||
'name' => 'Typ kuriera Sellasist',
|
||||
'db' => 'sellasist_shipment_method_id',
|
||||
'th' => [ 'class' => 'g-center' ],
|
||||
'td' => [ 'class' => 'g-center' ],
|
||||
'replace' => [ 'array' => $sellasist_shipments_methods ],
|
||||
], [
|
||||
'name' => 'Edytuj',
|
||||
'action' => [ 'type' => 'edit', 'url' => '/admin/shop_transport/transport_edit/id=[id]' ],
|
||||
|
||||
@@ -134,21 +134,11 @@
|
||||
Integracje
|
||||
</div>
|
||||
<ul>
|
||||
<li>
|
||||
<a href="/admin/integrations/sellasist_settings/">
|
||||
<i class="fa fa-cogs" aria-hidden="true"></i>sellasist.pl
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/integrations/apilo_settings/">
|
||||
<i class="fa fa-cogs" aria-hidden="true"></i>apilo.com
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/integrations/baselinker_settings/">
|
||||
<i class="fa fa-cogs" aria-hidden="true"></i>baselinker.com
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="/admin/integrations/shoppro_settings/">
|
||||
<i class="fa fa-cogs" aria-hidden="true"></i>shopPRO
|
||||
|
||||
408
autoload/Domain/Integrations/IntegrationsRepository.php
Normal file
408
autoload/Domain/Integrations/IntegrationsRepository.php
Normal file
@@ -0,0 +1,408 @@
|
||||
<?php
|
||||
namespace Domain\Integrations;
|
||||
|
||||
class IntegrationsRepository
|
||||
{
|
||||
private $db;
|
||||
|
||||
private const SETTINGS_TABLES = [
|
||||
'apilo' => 'pp_shop_apilo_settings',
|
||||
'shoppro' => 'pp_shop_shoppro_settings',
|
||||
];
|
||||
|
||||
public function __construct( $db )
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
// ── Settings ────────────────────────────────────────────────
|
||||
|
||||
private function settingsTable( string $provider ): string
|
||||
{
|
||||
if ( !isset( self::SETTINGS_TABLES[$provider] ) )
|
||||
throw new \InvalidArgumentException( "Unknown provider: $provider" );
|
||||
|
||||
return self::SETTINGS_TABLES[$provider];
|
||||
}
|
||||
|
||||
public function getSettings( string $provider ): array
|
||||
{
|
||||
$table = $this->settingsTable( $provider );
|
||||
$results = $this->db->query( "SELECT * FROM $table" )->fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $row )
|
||||
$settings[$row['name']] = $row['value'];
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
public function getSetting( string $provider, string $name ): ?string
|
||||
{
|
||||
$table = $this->settingsTable( $provider );
|
||||
$value = $this->db->get( $table, 'value', [ 'name' => $name ] );
|
||||
return $value !== false ? $value : null;
|
||||
}
|
||||
|
||||
public function saveSetting( string $provider, string $name, $value ): bool
|
||||
{
|
||||
$table = $this->settingsTable( $provider );
|
||||
if ( $this->db->count( $table, [ 'name' => $name ] ) ) {
|
||||
$this->db->update( $table, [ 'value' => $value ], [ 'name' => $name ] );
|
||||
} else {
|
||||
$this->db->insert( $table, [ 'name' => $name, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Product linking (Apilo) ─────────────────────────────────
|
||||
|
||||
public function linkProduct( int $productId, $externalId, $externalName ): bool
|
||||
{
|
||||
return (bool) $this->db->update( 'pp_shop_products', [
|
||||
'apilo_product_id' => $externalId,
|
||||
'apilo_product_name' => \S::remove_special_chars( $externalName ),
|
||||
], [ 'id' => $productId ] );
|
||||
}
|
||||
|
||||
public function unlinkProduct( int $productId ): bool
|
||||
{
|
||||
return (bool) $this->db->update( 'pp_shop_products', [
|
||||
'apilo_product_id' => null,
|
||||
'apilo_product_name' => null,
|
||||
], [ 'id' => $productId ] );
|
||||
}
|
||||
|
||||
// ── Apilo OAuth ─────────────────────────────────────────────
|
||||
|
||||
public function apiloAuthorize( string $clientId, string $clientSecret, string $authCode ): bool
|
||||
{
|
||||
$postData = [
|
||||
'grantType' => 'authorization_code',
|
||||
'token' => $authCode,
|
||||
];
|
||||
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $clientId . ":" . $clientSecret ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
curl_close( $ch );
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
if ( empty( $response['accessToken'] ) )
|
||||
return false;
|
||||
|
||||
$this->saveSetting( 'apilo', 'access-token', $response['accessToken'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] );
|
||||
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function apiloGetAccessToken(): ?string
|
||||
{
|
||||
$settings = $this->getSettings( 'apilo' );
|
||||
|
||||
if ( empty( $settings['access-token-expire-at'] ) || empty( $settings['access-token'] ) )
|
||||
return null;
|
||||
|
||||
$expireAt = new \DateTime( $settings['access-token-expire-at'] );
|
||||
$now = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
if ( $expireAt >= $now )
|
||||
return $settings['access-token'];
|
||||
|
||||
// Token expired - refresh
|
||||
$postData = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $settings['refresh-token'],
|
||||
];
|
||||
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $settings['client-id'] . ":" . $settings['client-secret'] ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
curl_close( $ch );
|
||||
return null;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
if ( empty( $response['accessToken'] ) )
|
||||
return null;
|
||||
|
||||
$this->saveSetting( 'apilo', 'access-token', $response['accessToken'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token', $response['refreshToken'] );
|
||||
$this->saveSetting( 'apilo', 'access-token-expire-at', $response['accessTokenExpireAt'] );
|
||||
$this->saveSetting( 'apilo', 'refresh-token-expire-at', $response['refreshTokenExpireAt'] );
|
||||
|
||||
return $response['accessToken'];
|
||||
}
|
||||
|
||||
// ── Apilo API fetch lists ───────────────────────────────────
|
||||
|
||||
private const APILO_ENDPOINTS = [
|
||||
'platform' => 'https://projectpro.apilo.com/rest/api/orders/platform/map/',
|
||||
'status' => 'https://projectpro.apilo.com/rest/api/orders/status/map/',
|
||||
'carrier' => 'https://projectpro.apilo.com/rest/api/orders/carrier-account/map/',
|
||||
'payment' => 'https://projectpro.apilo.com/rest/api/orders/payment/map/',
|
||||
];
|
||||
|
||||
private const APILO_SETTINGS_KEYS = [
|
||||
'platform' => 'platform-list',
|
||||
'status' => 'status-types-list',
|
||||
'carrier' => 'carrier-account-list',
|
||||
'payment' => 'payment-types-list',
|
||||
];
|
||||
|
||||
/**
|
||||
* Fetch list from Apilo API and save to settings.
|
||||
* @param string $type platform|status|carrier|payment
|
||||
*/
|
||||
public function apiloFetchList( string $type ): bool
|
||||
{
|
||||
if ( !isset( self::APILO_ENDPOINTS[$type] ) )
|
||||
throw new \InvalidArgumentException( "Unknown apilo list type: $type" );
|
||||
|
||||
$accessToken = $this->apiloGetAccessToken();
|
||||
if ( !$accessToken )
|
||||
return false;
|
||||
|
||||
$ch = curl_init( self::APILO_ENDPOINTS[$type] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $accessToken,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
curl_close( $ch );
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
|
||||
$data = json_decode( $response, true );
|
||||
if ( !$data )
|
||||
return false;
|
||||
|
||||
$this->saveSetting( 'apilo', self::APILO_SETTINGS_KEYS[$type], $data );
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Apilo product operations ────────────────────────────────
|
||||
|
||||
public function getProductSku( int $productId ): ?string
|
||||
{
|
||||
$sku = $this->db->get( 'pp_shop_products', 'sku', [ 'id' => $productId ] );
|
||||
return $sku ?: null;
|
||||
}
|
||||
|
||||
public function apiloProductSearch( string $sku ): array
|
||||
{
|
||||
$accessToken = $this->apiloGetAccessToken();
|
||||
if ( !$accessToken )
|
||||
return [ 'status' => 'error', 'msg' => 'Brak tokenu Apilo.' ];
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/?" . http_build_query( [ 'sku' => $sku ] );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $accessToken,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
curl_close( $ch );
|
||||
return [ 'status' => 'error', 'msg' => 'Błąd cURL: ' . curl_error( $ch ) ];
|
||||
}
|
||||
curl_close( $ch );
|
||||
|
||||
$data = json_decode( $response, true );
|
||||
if ( $data && isset( $data['products'] ) ) {
|
||||
$data['status'] = 'SUCCESS';
|
||||
return $data;
|
||||
}
|
||||
|
||||
return [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ];
|
||||
}
|
||||
|
||||
public function apiloCreateProduct( int $productId ): array
|
||||
{
|
||||
$accessToken = $this->apiloGetAccessToken();
|
||||
if ( !$accessToken )
|
||||
return [ 'success' => false, 'message' => 'Brak tokenu Apilo.' ];
|
||||
|
||||
$product = new \shop\Product( $productId );
|
||||
|
||||
$params = [
|
||||
'sku' => $product->sku,
|
||||
'ean' => $product->ean,
|
||||
'name' => $product->language['name'],
|
||||
'tax' => (int) $product->vat,
|
||||
'status' => 1,
|
||||
'quantity' => (int) $product->quantity,
|
||||
'priceWithTax' => $product->price_brutto,
|
||||
'description' => $product->language['description'] . '<br>' . $product->language['short_description'],
|
||||
'shortDescription' => '',
|
||||
'images' => [],
|
||||
];
|
||||
|
||||
foreach ( $product->images as $image )
|
||||
$params['images'][] = "https://" . $_SERVER['HTTP_HOST'] . $image['src'];
|
||||
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/api/warehouse/product/" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [ $params ] ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $accessToken,
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) ) {
|
||||
$error = curl_error( $ch );
|
||||
curl_close( $ch );
|
||||
return [ 'success' => false, 'message' => 'Błąd cURL: ' . $error ];
|
||||
}
|
||||
curl_close( $ch );
|
||||
|
||||
if ( !empty( $responseData['products'] ) ) {
|
||||
$this->db->update( 'pp_shop_products', [
|
||||
'apilo_product_id' => reset( $responseData['products'] ),
|
||||
'apilo_product_name' => $product->language['name'],
|
||||
], [ 'id' => $product->id ] );
|
||||
|
||||
return [ 'success' => true, 'message' => 'Produkt został dodany do magazynu APILO.' ];
|
||||
}
|
||||
|
||||
return [ 'success' => false, 'message' => 'Podczas dodawania produktu wystąpił błąd.' ];
|
||||
}
|
||||
|
||||
// ── ShopPRO import ──────────────────────────────────────────
|
||||
|
||||
public function shopproImportProduct( int $productId ): array
|
||||
{
|
||||
$settings = $this->getSettings( 'shoppro' );
|
||||
|
||||
$mdb2 = new \medoo( [
|
||||
'database_type' => 'mysql',
|
||||
'database_name' => $settings['db_name'],
|
||||
'server' => $settings['db_host'],
|
||||
'username' => $settings['db_user'],
|
||||
'password' => $settings['db_password'],
|
||||
'charset' => 'utf8'
|
||||
] );
|
||||
|
||||
$product = $mdb2->get( 'pp_shop_products', '*', [ 'id' => $productId ] );
|
||||
if ( !$product )
|
||||
return [ 'success' => false, 'message' => 'Podczas importowania produktu wystąpił błąd.' ];
|
||||
|
||||
$this->db->insert( 'pp_shop_products', [
|
||||
'price_netto' => $product['price_netto'],
|
||||
'price_brutto' => $product['price_brutto'],
|
||||
'vat' => $product['vat'],
|
||||
'stock_0_buy' => $product['stock_0_buy'],
|
||||
'quantity' => $product['quantity'],
|
||||
'wp' => $product['wp'],
|
||||
'sku' => $product['sku'],
|
||||
'ean' => $product['ean'],
|
||||
'custom_label_0' => $product['custom_label_0'],
|
||||
'custom_label_1' => $product['custom_label_1'],
|
||||
'custom_label_2' => $product['custom_label_2'],
|
||||
'custom_label_3' => $product['custom_label_3'],
|
||||
'custom_label_4' => $product['custom_label_4'],
|
||||
'additional_message' => $product['additional_message'],
|
||||
'additional_message_text' => $product['additional_message_text'],
|
||||
'additional_message_required'=> $product['additional_message_required'],
|
||||
'weight' => $product['weight'],
|
||||
] );
|
||||
|
||||
$newProductId = $this->db->id();
|
||||
if ( !$newProductId )
|
||||
return [ 'success' => false, 'message' => 'Podczas importowania produktu wystąpił błąd.' ];
|
||||
|
||||
// Import translations
|
||||
$languages = $mdb2->select( 'pp_shop_products_langs', '*', [ 'product_id' => $productId ] );
|
||||
if ( is_array( $languages ) ) {
|
||||
foreach ( $languages as $lang ) {
|
||||
$this->db->insert( 'pp_shop_products_langs', [
|
||||
'product_id' => $newProductId,
|
||||
'lang_id' => $lang['lang_id'],
|
||||
'name' => $lang['name'],
|
||||
'short_description' => $lang['short_description'],
|
||||
'description' => $lang['description'],
|
||||
'tab_name_1' => $lang['tab_name_1'],
|
||||
'tab_description_1' => $lang['tab_description_1'],
|
||||
'tab_name_2' => $lang['tab_name_2'],
|
||||
'tab_description_2' => $lang['tab_description_2'],
|
||||
'meta_title' => $lang['meta_title'],
|
||||
'meta_description' => $lang['meta_description'],
|
||||
'meta_keywords' => $lang['meta_keywords'],
|
||||
'seo_link' => $lang['seo_link'],
|
||||
'copy_from' => $lang['copy_from'],
|
||||
'warehouse_message_zero' => $lang['warehouse_message_zero'],
|
||||
'warehouse_message_nonzero'=> $lang['warehouse_message_nonzero'],
|
||||
'canonical' => $lang['canonical'],
|
||||
'xml_name' => $lang['xml_name'],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
// Import images
|
||||
$images = $mdb2->select( 'pp_shop_products_images', '*', [ 'product_id' => $productId ] );
|
||||
if ( is_array( $images ) ) {
|
||||
foreach ( $images as $image ) {
|
||||
$imageUrl = 'https://' . $settings['domain'] . $image['src'];
|
||||
|
||||
$ch = curl_init( $imageUrl );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
|
||||
$imageData = curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
|
||||
$imageName = basename( $imageUrl );
|
||||
$imageDir = '../upload/product_images/product_' . $newProductId;
|
||||
$imagePath = $imageDir . '/' . $imageName;
|
||||
|
||||
if ( !file_exists( $imageDir ) )
|
||||
mkdir( $imageDir, 0777, true );
|
||||
|
||||
file_put_contents( $imagePath, $imageData );
|
||||
|
||||
$this->db->insert( 'pp_shop_products_images', [
|
||||
'product_id' => $newProductId,
|
||||
'src' => '/upload/product_images/product_' . $newProductId . '/' . $imageName,
|
||||
'o' => $image['o'],
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
return [ 'success' => true, 'message' => 'Produkt został zaimportowany.' ];
|
||||
}
|
||||
}
|
||||
172
autoload/admin/Controllers/IntegrationsController.php
Normal file
172
autoload/admin/Controllers/IntegrationsController.php
Normal file
@@ -0,0 +1,172 @@
|
||||
<?php
|
||||
namespace admin\Controllers;
|
||||
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
|
||||
class IntegrationsController
|
||||
{
|
||||
private IntegrationsRepository $repository;
|
||||
|
||||
public function __construct( IntegrationsRepository $repository )
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
// ── Apilo settings ──────────────────────────────────────────
|
||||
|
||||
public function apilo_settings(): string
|
||||
{
|
||||
return \Tpl::view( 'integrations/apilo-settings', [
|
||||
'settings' => $this->repository->getSettings( 'apilo' ),
|
||||
] );
|
||||
}
|
||||
|
||||
public function apilo_settings_save(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$fieldId = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( $this->repository->saveSetting( 'apilo', $fieldId, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_authorization(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$settings = $this->repository->getSettings( 'apilo' );
|
||||
|
||||
if ( $this->repository->apiloAuthorize( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── Apilo data fetch ────────────────────────────────────────
|
||||
|
||||
public function get_platform_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'platform' ) )
|
||||
\S::alert( 'Lista platform została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_status_types_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'status' ) )
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_carrier_account_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'carrier' ) )
|
||||
\S::alert( 'Lista kont przewoźników została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function get_payment_types_list(): void
|
||||
{
|
||||
if ( $this->repository->apiloFetchList( 'payment' ) )
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── Apilo product operations ────────────────────────────────
|
||||
|
||||
public function apilo_create_product(): void
|
||||
{
|
||||
$productId = (int) \S::get( 'product_id' );
|
||||
$result = $this->repository->apiloCreateProduct( $productId );
|
||||
|
||||
\S::alert( $result['message'] );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_product_search(): void
|
||||
{
|
||||
$productId = (int) \S::get( 'product_id' );
|
||||
$sku = $this->repository->getProductSku( $productId );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode( $this->repository->apiloProductSearch( $sku ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_product_select_save(): void
|
||||
{
|
||||
if ( $this->repository->linkProduct( (int) \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
public function apilo_product_select_delete(): void
|
||||
{
|
||||
if ( $this->repository->unlinkProduct( (int) \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── ShopPRO settings ────────────────────────────────────────
|
||||
|
||||
public function shoppro_settings(): string
|
||||
{
|
||||
return \Tpl::view( 'integrations/shoppro-settings', [
|
||||
'settings' => $this->repository->getSettings( 'shoppro' ),
|
||||
] );
|
||||
}
|
||||
|
||||
public function shoppro_settings_save(): void
|
||||
{
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$fieldId = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( $this->repository->saveSetting( 'shoppro', $fieldId, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// ── ShopPRO product import ──────────────────────────────────
|
||||
|
||||
public function shoppro_product_import(): void
|
||||
{
|
||||
$productId = (int) \S::get( 'product_id' );
|
||||
$result = $this->repository->shopproImportProduct( $productId );
|
||||
|
||||
\S::alert( $result['message'] );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -311,6 +311,13 @@ class Site
|
||||
new \Domain\Layouts\LayoutsRepository( $mdb )
|
||||
);
|
||||
},
|
||||
'Integrations' => function() {
|
||||
global $mdb;
|
||||
|
||||
return new \admin\Controllers\IntegrationsController(
|
||||
new \Domain\Integrations\IntegrationsRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
|
||||
return self::$newControllers;
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
namespace admin\controls;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// widok wiązania produktów
|
||||
static public function bundling_products() {
|
||||
return \Tpl::view( 'baselinker/bundling-products', [
|
||||
'products' => \admin\factory\ShopProduct::products_list_for_baselinker(),
|
||||
'baselinker_products' => \admin\factory\Baselinker::products_list()
|
||||
] );
|
||||
}
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save() {
|
||||
\admin\factory\Baselinker::bundling_products_save( $_POST );
|
||||
header( 'Location: /admin/baselinker/bundling_products/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -1,846 +0,0 @@
|
||||
<?
|
||||
namespace admin\controls;
|
||||
|
||||
class Integrations {
|
||||
|
||||
// apilo_create_product
|
||||
static public function apilo_create_product()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = new \shop\Product( $product_id );
|
||||
|
||||
$methodParams = [
|
||||
"sku" => $product -> sku,
|
||||
"ean" => $product -> ean,
|
||||
"name" => $product -> language['name'],
|
||||
"tax" => (int) $product -> vat,
|
||||
'status' => 1,
|
||||
"quantity" => (int) $product -> quantity,
|
||||
"priceWithTax" => $product -> price_brutto,
|
||||
'description' => $product -> language['description'] . '<br>' . $product -> language['short_description'],
|
||||
'shortDescription' => '',
|
||||
'images' => []
|
||||
];
|
||||
|
||||
foreach ($product->images as $image) {
|
||||
$methodParams["images"][] = "https://" . $_SERVER['HTTP_HOST'] . $image['src'];
|
||||
}
|
||||
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/api/warehouse/product/" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [ $methodParams ] ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Content-Type: application/json",
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData['products'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => reset( $responseData['products'] ), 'apilo_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został dodany do magazynu APILO.' );
|
||||
}
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker_create_product
|
||||
static public function baselinker_create_product()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$product = \shop\Product::getFromCache( $product_id, 'pl' );
|
||||
|
||||
$methodParams = [
|
||||
"storage_id" => \admin\factory\Integrations::baselinker_settings('storage_id'),
|
||||
"ean" => $product->ean,
|
||||
"sku" => $product->sku,
|
||||
"name" => $product->language['name'],
|
||||
"quantity" => "0",
|
||||
"price_brutto" => $product->price_brutto,
|
||||
"tax_rate" => $product->vat,
|
||||
"description" => $product->language['short_description'],
|
||||
"description_extra1" => $product->language['description'],
|
||||
"images" => []
|
||||
];
|
||||
|
||||
foreach ($product->images as $image) {
|
||||
$methodParams["images"][] = "url:https://" . $_SERVER['HTTP_HOST'] . $image['src'];
|
||||
}
|
||||
|
||||
$methodParams = json_encode( $methodParams, JSON_UNESCAPED_SLASHES );
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "addProduct",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
if ( $response['product_id'] )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $response['product_id'], 'baselinker_product_name' => $product->language['name'] ], [ 'id' => $product -> id ] );
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został dodany do magazynu Baselinker.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Podczas dodawania produktu wystąpił błąd.' );
|
||||
}
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker pobierz listę magazynów
|
||||
static public function baselinker_get_storages_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getStoragesList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
\admin\factory\Integrations::baselinker_settings_save( 'storages_list', $response['storages'] );
|
||||
\S::alert( 'Lista magazynów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/baselinker_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker_get_order_status_list
|
||||
static public function baselinker_get_order_status_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getOrderStatusList",
|
||||
"parameters" => []
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
\admin\factory\Integrations::baselinker_settings_save( 'order_status_list', $response['statuses'] );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/baselinker_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_sellasist_carriers_list
|
||||
static public function get_sellasist_shipments_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/shipments" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'shipments_methods', $responseData );
|
||||
\S::alert( 'Lista przewoźników została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_sellasist_payment_types_list
|
||||
static public function get_sellasist_payment_types_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/payments" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'payment_types_list', $responseData );
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function get_sellasist_status_types_list()
|
||||
{
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( "https://projectpro.sellasist.pl/api/v1/statuses" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
else {
|
||||
if ( $responseData ) {
|
||||
\admin\factory\Integrations::sellasist_settings_save( 'status_types_list', $responseData );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
} else
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
header( 'Location: /admin/integrations/sellasist_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_platform_list
|
||||
static public function get_platform_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/platform/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'platform-list', $responseData );
|
||||
\S::alert( 'Lista platform została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_status_types_list
|
||||
static public function get_status_types_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/status/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'status-types-list', $responseData );
|
||||
\S::alert( 'Lista statusów została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_carrier_account_list
|
||||
static public function get_carrier_account_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/carrier-account/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'carrier-account-list', $responseData );
|
||||
\S::alert( 'Lista kont przewoźników została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// get_payment_types_list
|
||||
static public function get_payment_types_list()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/orders/payment/map/";
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
\S::alert( 'Błąd cURL: ' . curl_error( $ch ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData )
|
||||
{
|
||||
\admin\factory\Integrations::apilo_settings_save( 'payment-types-list', $responseData );
|
||||
\S::alert( 'Lista metod płatności została pobrana.' );
|
||||
}
|
||||
else
|
||||
{
|
||||
\S::alert( 'Brak wyników.' );
|
||||
}
|
||||
}
|
||||
header( 'Location: /admin/integrations/apilo_settings/' );
|
||||
exit;
|
||||
}
|
||||
|
||||
// settings for the sellasist integration
|
||||
static public function sellasist_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/sellasist-settings', [
|
||||
'settings' => \admin\factory\Integrations::sellasist_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// settings for the Baselinker integration
|
||||
static public function baselinker_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/baselinker-settings', [
|
||||
'settings' => \admin\factory\Integrations::baselinker_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// settings for shoppro
|
||||
static public function shoppro_settings()
|
||||
{
|
||||
return \Tpl::view( 'integrations/shoppro-settings', [
|
||||
'settings' => \admin\factory\Integrations::shoppro_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// Settings for the APILO plugin
|
||||
static public function apilo_settings()
|
||||
{
|
||||
|
||||
return \Tpl::view( 'integrations/apilo-settings', [
|
||||
'settings' => \admin\factory\Integrations::apilo_settings(),
|
||||
] );
|
||||
}
|
||||
|
||||
// save settings for the shoppro integration
|
||||
static public function shoppro_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::shoppro_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save()
|
||||
{
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Save settings for the APILO plugin
|
||||
static public function apilo_settings_save() {
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania ustawień wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$field_id = \S::get( 'field_id' );
|
||||
$value = \S::get( 'value' );
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_settings_save( $field_id, $value ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Ustawienia zostały zapisane.', 'value' => $value ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// Authorization in apilo.com
|
||||
static public function apilo_authorization() {
|
||||
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas autoryzacji wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$settings = \admin\factory\Integrations::apilo_settings();
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_authorization( $settings['client-id'], $settings['client-secret'], $settings['authorization-code'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Autoryzacja przebiegła pomyślnie.' ];
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist product search by sku
|
||||
static public function sellasist_product_search() {
|
||||
global $mdb, $settings;
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$url = "https://projectpro.sellasist.pl/api/v1/products";
|
||||
$params['symbol '] = $sku;
|
||||
$url .= '?' . http_build_query( $params );
|
||||
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) )
|
||||
{
|
||||
echo 'Błąd cURL: ' . curl_error( $ch );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $responseData['error'] )
|
||||
{
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
$return_data = array();
|
||||
$return_data['status'] = 'SUCCESS';
|
||||
$return_data['products'] = $responseData;
|
||||
echo json_encode( $return_data );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Brak wyników dla podanego SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product search by sku
|
||||
static public function apilo_product_search() {
|
||||
global $mdb, $settings;
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$access_token = \admin\factory\Integrations::apilo_get_access_token();
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/api/warehouse/product/";
|
||||
$params['sku'] = $sku;
|
||||
$url .= '?' . http_build_query( $params );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Bearer " . $access_token,
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( curl_errno( $ch ) ) {
|
||||
echo 'Błąd cURL: ' . curl_error( $ch );
|
||||
} else {
|
||||
if ( $responseData && isset( $responseData['products'] ) ) {
|
||||
$responseData['status'] = 'SUCCESS';
|
||||
echo json_encode( $responseData );
|
||||
exit;
|
||||
} else {
|
||||
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
echo json_encode( [ 'status' => 'SUCCESS', 'msg' => 'Brak wyników dla podanego SKU.', 'products' => '' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// wyszukiwanie produktu w bazie baselinkera
|
||||
static public function baselinker_product_search()
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$api_code = \admin\factory\Integrations::baselinker_settings( 'api_code' );
|
||||
|
||||
$sku = $mdb -> get( 'pp_shop_products', 'sku', [ 'id' => \S::get( 'product_id' ) ] );
|
||||
|
||||
if ( !$sku ) {
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podany produkt nie posiada kodu SKU.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1",
|
||||
"filter_sku": "' . $sku . '"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $api_code,
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
echo json_encode( $response );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product select delete
|
||||
static public function apilo_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_product_select_delete( \S::get( 'product_id' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas usuwania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::sellasist_product_select_save( \S::get( 'product_id' ), \S::get( 'sellasist_product_id' ), \S::get( 'sellasist_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::apilo_product_select_save( \S::get( 'product_id' ), \S::get( 'apilo_product_id' ), \S::get( 'apilo_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save() {
|
||||
global $mdb;
|
||||
|
||||
if ( \admin\factory\Integrations::baselinker_product_select_save( \S::get( 'product_id' ), \S::get( 'baselinker_product_id' ), \S::get( 'baselinker_product_name' ) ) )
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error', 'msg' => 'Podczas zapisywania produktu wystąpił błąd. Proszę spróbować ponownie.' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
// shoppro_product_import
|
||||
static public function shoppro_product_import()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$shoppro_settings = \admin\factory\Integrations::shoppro_settings();
|
||||
|
||||
$mdb2 = new \medoo( [
|
||||
'database_type' => 'mysql',
|
||||
'database_name' => $shoppro_settings[ 'db_name' ],
|
||||
'server' => $shoppro_settings[ 'db_host' ],
|
||||
'username' => $shoppro_settings[ 'db_user' ],
|
||||
'password' => $shoppro_settings[ 'db_password' ],
|
||||
'charset' => 'utf8'
|
||||
] );
|
||||
|
||||
$product_id = \S::get( 'product_id' );
|
||||
|
||||
$product = $mdb2 -> get( 'pp_shop_products', '*', [ 'id' => $product_id ] );
|
||||
if ( $product )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_products', [
|
||||
'price_netto' => $product[ 'price_netto' ],
|
||||
'price_brutto' => $product[ 'price_brutto' ],
|
||||
'vat' => $product[ 'vat' ],
|
||||
'stock_0_buy' => $product[ 'stock_0_buy' ],
|
||||
'quantity' => $product[ 'quantity' ],
|
||||
'wp' => $product[ 'wp' ],
|
||||
'sku' => $product[ 'sku' ],
|
||||
'ean' => $product[ 'ean' ],
|
||||
'custom_label_0' => $product[ 'custom_label_0' ],
|
||||
'custom_label_1' => $product[ 'custom_label_1' ],
|
||||
'custom_label_2' => $product[ 'custom_label_2' ],
|
||||
'custom_label_3' => $product[ 'custom_label_3' ],
|
||||
'custom_label_4' => $product[ 'custom_label_4' ],
|
||||
'additional_message' => $product[ 'additional_message' ],
|
||||
'additional_message_text' => $product[ 'additional_message_text' ],
|
||||
'additional_message_required' => $product[ 'additional_message_required' ],
|
||||
'weight' => $product[ 'weight' ]
|
||||
] );
|
||||
|
||||
$new_product_id = $mdb -> id();
|
||||
if ( $new_product_id )
|
||||
{
|
||||
$languages = $mdb2 -> select( 'pp_shop_products_langs', '*', [ 'product_id' => $product_id ] );
|
||||
if ( is_array( $languages ) )
|
||||
{
|
||||
foreach ( $languages as $language )
|
||||
{
|
||||
$mdb -> insert( 'pp_shop_products_langs', [
|
||||
'product_id' => $new_product_id,
|
||||
'lang_id' => $language['lang_id'],
|
||||
'name' => $language['name'],
|
||||
'short_description' => $language['short_description'],
|
||||
'description' => $language['description'],
|
||||
'tab_name_1' => $language['tab_name_1'],
|
||||
'tab_description_1' => $language['tab_description_1'],
|
||||
'tab_name_2' => $language['tab_name_2'],
|
||||
'tab_description_2' => $language['tab_description_2'],
|
||||
'meta_title' => $language['meta_title'],
|
||||
'meta_description' => $language['meta_description'],
|
||||
'meta_keywords' => $language['meta_keywords'],
|
||||
'seo_link' => $language['seo_link'],
|
||||
'copy_from' => $language['copy_from'],
|
||||
'warehouse_message_zero' => $language['warehouse_message_zero'],
|
||||
'warehouse_message_nonzero' => $language['warehouse_message_nonzero'],
|
||||
'canonical' => $language['canonical'],
|
||||
'xml_name' => $language['xml_name']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
$images = $mdb2 -> select( 'pp_shop_products_images', '*', [ 'product_id' => $product_id ] );
|
||||
if ( is_array( $images ) )
|
||||
{
|
||||
foreach ( $images as $image )
|
||||
{
|
||||
$image_url = 'https://' . $shoppro_settings['domain'] . $image['src'];
|
||||
|
||||
// pobierz zdjęcie za pomocą curl
|
||||
$ch = curl_init( $image_url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
|
||||
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
|
||||
$image_data = curl_exec( $ch );
|
||||
$image_data;
|
||||
curl_close( $ch );
|
||||
|
||||
// ścieżdka do nowego zdjęcia to "/upload/product_images/product_[product_id]/[nazwa_zdjęcia]
|
||||
$image_name = basename( $image_url );
|
||||
$image_path = '../upload/product_images/product_' . $new_product_id . '/' . $image_name;
|
||||
|
||||
// utwórz katalog dla zdjęć produktu jeśli nie istnieje
|
||||
if ( !file_exists( '../upload/product_images/product_' . $new_product_id ) )
|
||||
mkdir( '../upload/product_images/product_' . $new_product_id, 0777, true );
|
||||
|
||||
// zapisz zdjęcie
|
||||
file_put_contents( $image_path, $image_data );
|
||||
|
||||
// zapisz zdjęcie w bazie danych
|
||||
$mdb -> insert( 'pp_shop_products_images', [
|
||||
'product_id' => $new_product_id,
|
||||
'src' => '/upload/product_images/product_' . $new_product_id . '/' . $image_name,
|
||||
'o' => $image['o']
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
\S::alert( 'Produkt został zaimportowany.' );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
\S::alert( 'Podczas importowania produktu wystąpił błąd.' );
|
||||
header( 'Location: /admin/shop_product/view_list/' );
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ class ShopPaymentMethod
|
||||
{
|
||||
return \Tpl::view( 'shop-payment-method/view-list', [
|
||||
'apilo_payment_types_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'payment-types-list' ) ),
|
||||
'sellasist_payment_types_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'payment_types_list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,9 +297,7 @@ class ShopProduct
|
||||
'html' => \Tpl::view( 'shop-product/products-list-table', [
|
||||
'products' => $products['products'],
|
||||
'current_page' => \S::get( 'current_page' ),
|
||||
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
|
||||
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
|
||||
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
|
||||
'show_xml_data' => \S::get_session( 'show_xml_data' )
|
||||
] )
|
||||
];
|
||||
@@ -334,9 +332,7 @@ class ShopProduct
|
||||
'current_page' => $current_page,
|
||||
'query_array' => $query_array,
|
||||
'pagination_max' => ceil( \admin\factory\ShopProduct::count_product() / 10 ),
|
||||
'baselinker_enabled' => \admin\factory\Integrations::baselinker_settings( 'enabled' ),
|
||||
'apilo_enabled' => \admin\factory\Integrations::apilo_settings( 'enabled' ),
|
||||
'sellasist_enabled' => \admin\factory\Integrations::sellasist_settings( 'enabled' ),
|
||||
'show_xml_data' => \S::get_session( 'show_xml_data' ),
|
||||
'shoppro_enabled' => \admin\factory\Integrations::shoppro_settings( 'enabled' )
|
||||
] );
|
||||
|
||||
@@ -9,7 +9,7 @@ class ShopStatuses {
|
||||
$response = [ 'status' => 'error', 'msg' => 'Podczas zapisywania statusu wystąpił błąd. Proszę spróbować ponownie.' ];
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'], $values['sellasist_status_id'], $values['baselinker_status_id'] ) )
|
||||
if ( $id = \admin\factory\ShopStatuses::status_save( $values['id'], $values['color'], $values['apilo_status_id'] ) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Status został zapisany.', 'id' => $id ];
|
||||
|
||||
echo json_encode( $response );
|
||||
@@ -22,8 +22,6 @@ class ShopStatuses {
|
||||
return \Tpl::view( 'shop-statuses/status-edit', [
|
||||
'status' => \admin\factory\ShopStatuses::get_status( \S::get( 'id' ) ),
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
|
||||
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -31,8 +29,6 @@ class ShopStatuses {
|
||||
{
|
||||
return \Tpl::view( 'shop-statuses/view-list', [
|
||||
'apilo_order_status_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'status-types-list' ) ),
|
||||
'sellasist_order_status_list' => unserialize( \admin\factory\Integrations::sellasist_settings( 'status_types_list' ) ),
|
||||
'baselinker_order_status_list' => unserialize( \admin\factory\Integrations::baselinker_settings( 'order_status_list' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ class ShopTransport
|
||||
$values = json_decode( \S::get( 'values' ), true );
|
||||
|
||||
if ( $id = \admin\factory\ShopTransport::transport_save(
|
||||
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['sellasist_shipment_method_id'], $values['delivery_free']
|
||||
$values['id'], $values['name'], $values['name_visible'], $values['description'], $values['status'], $values['cost'], $values['payment_methods'], $values['max_wp'], $values['default'], $values['apilo_carrier_account_id'], $values['delivery_free']
|
||||
) )
|
||||
$response = [ 'status' => 'ok', 'msg' => 'Rodzaj transportu został zapisany.', 'id' => $id ];
|
||||
|
||||
@@ -22,7 +22,6 @@ class ShopTransport
|
||||
'transport_details' => \admin\factory\ShopTransport::transport_details( \S::get( 'id' ) ),
|
||||
'payments_list' => \admin\factory\ShopPaymentMethod::payments_list(),
|
||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
||||
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
|
||||
] );
|
||||
}
|
||||
|
||||
@@ -30,7 +29,6 @@ class ShopTransport
|
||||
{
|
||||
return \Tpl::view( 'shop-transport/view-list', [
|
||||
'apilo_carrier_account_list' => unserialize( \admin\factory\Integrations::apilo_settings( 'carrier-account-list' ) ),
|
||||
'sellasist_shipments_methods' => unserialize( \admin\factory\Integrations::sellasist_settings( 'shipments_methods' ) ),
|
||||
] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?
|
||||
namespace admin\factory;
|
||||
|
||||
class Baselinker {
|
||||
|
||||
// zapis wiązania produktów
|
||||
static public function bundling_products_save( $values ) {
|
||||
global $mdb;
|
||||
|
||||
foreach ( $values as $key => $val ) {
|
||||
$key = explode( '_', $key );
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $val ], [ 'id' => $key[1] ] );
|
||||
}
|
||||
}
|
||||
|
||||
// pobranie produktów z Baselinkera
|
||||
static public function products_list() {
|
||||
global $settings;
|
||||
|
||||
$methodParams = '{
|
||||
"storage_id": "bl_1"
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $settings['baselinker_api'],
|
||||
"method" => "getProductsList",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
return $response['products'];
|
||||
}
|
||||
}
|
||||
@@ -1,264 +1,64 @@
|
||||
<?
|
||||
<?php
|
||||
namespace admin\factory;
|
||||
|
||||
/**
|
||||
* Fasada kompatybilnosci wstecznej.
|
||||
* Deleguje do Domain\Integrations\IntegrationsRepository.
|
||||
* Uzywane przez: cron.php, shop\Order, admin\controls\ShopStatuses, admin\controls\ShopTransport, admin\controls\ShopPaymentMethod, admin\controls\ShopProduct.
|
||||
*/
|
||||
class Integrations {
|
||||
|
||||
// sellasist_product_select_delete
|
||||
static public function sellasist_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => null, 'sellasist_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// sellasist_product_select_save
|
||||
static public function sellasist_product_select_save( int $product_id, $sellasist_product_id, $sellasist_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'sellasist_product_id' => $sellasist_product_id, 'sellasist_product_name' => \S::remove_special_chars( $sellasist_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo delete product linking
|
||||
static public function apilo_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => null, 'apilo_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// baselinker delete product linking
|
||||
static public function baselinker_product_select_delete( int $product_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => null, 'baselinker_product_name' => null ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// apilo product select save
|
||||
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'apilo_product_id' => $apilo_product_id, 'apilo_product_name' => \S::remove_special_chars( $apilo_product_name ) ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
static public function baselinker_product_select_save( int $product_id, $baselinker_product_id, $baselinker_product_name ) {
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_products', [ 'baselinker_product_id' => $baselinker_product_id, 'baselinker_product_name' => $baselinker_product_name ], [ 'id' => $product_id ] );
|
||||
}
|
||||
|
||||
// get settings for shoppro integration
|
||||
static public function shoppro_settings( $name = '' )
|
||||
private static function repo(): \Domain\Integrations\IntegrationsRepository
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_shoppro_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_shoppro_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
return new \Domain\Integrations\IntegrationsRepository( $mdb );
|
||||
}
|
||||
|
||||
// get settings for the sellasist integration
|
||||
static public function sellasist_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
// ── Apilo settings ──────────────────────────────────────────
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_sellasist_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_sellasist_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the Baselinker integration
|
||||
static public function baselinker_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_baselinker_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_baselinker_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
// get settings for the APILO plugin
|
||||
static public function apilo_settings( $name = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $name )
|
||||
{
|
||||
return $mdb -> get( 'pp_shop_apilo_settings', 'value', [ 'name' => $name ] );
|
||||
}
|
||||
|
||||
$results = $mdb -> query( 'SELECT * FROM pp_shop_apilo_settings' ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
$settings = [];
|
||||
foreach ( $results as $result )
|
||||
{
|
||||
$settings[$result['name']] = $result['value'];
|
||||
}
|
||||
|
||||
return $settings;
|
||||
$repo = self::repo();
|
||||
return $name ? $repo->getSetting( 'apilo', $name ) : $repo->getSettings( 'apilo' );
|
||||
}
|
||||
|
||||
// save settings for shoppro integration
|
||||
static public function shoppro_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_shoppro_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_shoppro_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_shoppro_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the sellasist integration
|
||||
static public function sellasist_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_sellasist_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_sellasist_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_sellasist_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the Baselinker integration
|
||||
static public function baselinker_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_baselinker_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_baselinker_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_baselinker_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// save settings for the APILO plugin
|
||||
static public function apilo_settings_save( $field_id, $value )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_apilo_settings', [ 'name' => $field_id ] ) ) {
|
||||
$mdb -> update( 'pp_shop_apilo_settings', [ 'value' => $value ], [ 'name' => $field_id ] );
|
||||
} else {
|
||||
$mdb -> insert( 'pp_shop_apilo_settings', [ 'name' => $field_id, 'value' => $value ] );
|
||||
}
|
||||
return true;
|
||||
return self::repo()->saveSetting( 'apilo', $field_id, $value );
|
||||
}
|
||||
|
||||
// authorization in apilo.com
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$url = "https://projectpro.apilo.com/rest/auth/token/";
|
||||
|
||||
$postData['grantType'] = 'authorization_code';
|
||||
$postData['token'] = $authorization_code;
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $postData ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $client_id . ":" . $client_secret ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// get access token or refresh it apilo.com
|
||||
static public function apilo_get_access_token()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$apilo_settings = self::apilo_settings();
|
||||
|
||||
$date1 = new \DateTime( $apilo_settings['access-token-expire-at'] );
|
||||
$date2 = new \DateTime( date( 'Y-m-d H:i:s' ) );
|
||||
|
||||
if ( $date1 < $date2 )
|
||||
{
|
||||
$post_data = [
|
||||
'grantType' => 'refresh_token',
|
||||
'token' => $apilo_settings['refresh-token']
|
||||
];
|
||||
$ch = curl_init( "https://projectpro.apilo.com/rest/auth/token/" );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"Authorization: Basic " . base64_encode( $apilo_settings['client-id'] . ":" . $apilo_settings['client-secret'] ),
|
||||
"Accept: application/json"
|
||||
] );
|
||||
curl_setopt( $ch, CURLOPT_POST, true );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $post_data ) );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST" );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
if ( curl_errno( $ch ) ) {
|
||||
return false;
|
||||
}
|
||||
curl_close( $ch );
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
$access_token = $response['accessToken'];
|
||||
$refresh_token = $response['refreshToken'];
|
||||
$access_token_expire_at = $response['accessTokenExpireAt'];
|
||||
$refresh_token_expire_at = $response['refreshTokenExpireAt'];
|
||||
|
||||
if ( $access_token == '' ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::apilo_settings_save( 'access-token', $access_token );
|
||||
self::apilo_settings_save( 'refresh-token', $refresh_token );
|
||||
self::apilo_settings_save( 'access-token-expire-at', $access_token_expire_at );
|
||||
self::apilo_settings_save( 'refresh-token-expire-at', $refresh_token_expire_at );
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
||||
return $apilo_settings['access-token'];
|
||||
return self::repo()->apiloGetAccessToken();
|
||||
}
|
||||
}
|
||||
|
||||
static public function apilo_authorization( $client_id, $client_secret, $authorization_code )
|
||||
{
|
||||
return self::repo()->apiloAuthorize( $client_id, $client_secret, $authorization_code );
|
||||
}
|
||||
|
||||
// ── Apilo product linking ─────────────────────────────────────
|
||||
|
||||
static public function apilo_product_select_save( int $product_id, $apilo_product_id, $apilo_product_name )
|
||||
{
|
||||
return self::repo()->linkProduct( $product_id, $apilo_product_id, $apilo_product_name );
|
||||
}
|
||||
|
||||
static public function apilo_product_select_delete( int $product_id )
|
||||
{
|
||||
return self::repo()->unlinkProduct( $product_id );
|
||||
}
|
||||
|
||||
// ── ShopPRO settings ──────────────────────────────────────────
|
||||
|
||||
static public function shoppro_settings( $name = '' )
|
||||
{
|
||||
$repo = self::repo();
|
||||
return $name ? $repo->getSetting( 'shoppro', $name ) : $repo->getSettings( 'shoppro' );
|
||||
}
|
||||
|
||||
static public function shoppro_settings_save( $field_id, $value )
|
||||
{
|
||||
return self::repo()->saveSetting( 'shoppro', $field_id, $value );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,19 +65,6 @@ class ShopProduct
|
||||
return $mdb -> get( 'pp_shop_products_langs', 'name', [ 'AND' => [ 'product_id' => $product_id, 'lang_id' => $default_lang ] ] );
|
||||
}
|
||||
|
||||
// lista produktów do wiązania z baselinkerem
|
||||
static public function products_list_for_baselinker()
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_products', [ 'id', 'sku', 'baselinker_product_id' ], [ 'parent_id' => null, 'ORDER' => [ 'baselinker_product_id' => 'ASC', 'sku' => 'ASC' ] ] );
|
||||
foreach ( $results as $row ) {
|
||||
$row['name'] = self::product_default_name( $row['id'] );
|
||||
$products[] = $row;
|
||||
}
|
||||
return $products;
|
||||
}
|
||||
|
||||
// szybka zmiana google xml label
|
||||
static public function product_change_custom_label( int $product_id, $custom_label, $value )
|
||||
{
|
||||
|
||||
@@ -10,15 +10,13 @@ class ShopStatuses {
|
||||
}
|
||||
|
||||
// status_save
|
||||
public static function status_save( $status_id, $color, $apilo_status_id, $sellasi_status_id, $baselinker_status_id )
|
||||
public static function status_save( $status_id, $color, $apilo_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_statuses', [
|
||||
'color' => $color,
|
||||
'apilo_status_id' => $apilo_status_id ? $apilo_status_id : null,
|
||||
'sellasist_status_id' => $sellasi_status_id ? $sellasi_status_id : null,
|
||||
'baselinker_status_id' => $baselinker_status_id ? $baselinker_status_id : null
|
||||
], [ 'id' => $status_id ] );
|
||||
|
||||
return $status_id;
|
||||
|
||||
@@ -7,7 +7,7 @@ class ShopTransport
|
||||
return $mdb -> get( 'pp_shop_transports', 'cost', [ 'AND' => [ 'status' => 1, 'id' => [ 2, 4, 6, 8, 9 ], 'max_wp[>=]' => $wp ], 'ORDER' => [ 'cost' => 'ASC' ] ] );
|
||||
}
|
||||
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $sellasist_shipment_method_id, $delivery_free )
|
||||
public static function transport_save( $transport_id, $name, $name_visible, $description, $status, $cost, $payment_methods, $max_wp, $default, $apilo_carrier_account_id, $delivery_free )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -25,7 +25,6 @@ class ShopTransport
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
] );
|
||||
|
||||
@@ -67,7 +66,6 @@ class ShopTransport
|
||||
'cost' => $cost,
|
||||
'max_wp' => $max_wp ? $max_wp : null,
|
||||
'apilo_carrier_account_id' => $apilo_carrier_account_id ? $apilo_carrier_account_id : null,
|
||||
'sellasist_shipment_method_id' => $sellasist_shipment_method_id ? $sellasist_shipment_method_id : null,
|
||||
'delivery_free' => $delivery_free == 'on' ? 1 : 0
|
||||
], [
|
||||
'id' => $transport_id
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?
|
||||
namespace front\factory;
|
||||
class Shop
|
||||
{
|
||||
static public function baselinker_settings( $admin = false )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$settings = \Cache::fetch( 'baselinker_settings' ) or $admin )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_shop_baselinker_settings', '*' );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
$settings[ $row['name'] ] = $row['value'];
|
||||
|
||||
if ( !$admin)
|
||||
\Cache::store( 'baselinker_settings', $settings );
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
}
|
||||
@@ -136,9 +136,7 @@ class ShopOrder
|
||||
'summary' => \S::normalize_decimal( $basket_summary + $transport_cost ),
|
||||
'coupon_id' => $coupon ? $coupon -> id : null,
|
||||
'message' => $basket_message ? $basket_message : null,
|
||||
'baselinker_order_status_date' => date( 'Y-m-d H:i:s' ),
|
||||
'apilo_order_status_date' => date( 'Y-m-d H:i:s' ),
|
||||
'sellasist_order_status_date' => date( 'Y-m-d H:i:s' ),
|
||||
] );
|
||||
|
||||
$order_id = $mdb -> id();
|
||||
|
||||
@@ -3,12 +3,6 @@ namespace front\factory;
|
||||
|
||||
class ShopPaymentMethod
|
||||
{
|
||||
// get_sellasist_payment_method_id
|
||||
static public function get_sellasist_payment_method_id( $payment_method_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_payment_methods', 'sellasist_payment_type_id', [ 'id' => $payment_method_id ] );
|
||||
}
|
||||
|
||||
// get_apilo_payment_method_id
|
||||
static public function get_apilo_payment_method_id( $payment_method_id ) {
|
||||
global $mdb;
|
||||
|
||||
@@ -3,17 +3,6 @@ namespace front\factory;
|
||||
|
||||
class ShopProduct
|
||||
{
|
||||
// get_sellasist_product_id
|
||||
static public function get_sellasist_product_id( $product_id ) {
|
||||
global $mdb;
|
||||
if ( !$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' => $product_id ] ) ) {
|
||||
$sellasist_product_id = $mdb -> get( 'pp_shop_products', 'sellasist_product_id', [ 'id' =>
|
||||
$mdb -> get( 'pp_shop_products', 'parent_id', [ 'id' => $product_id ] )
|
||||
] );
|
||||
}
|
||||
return $sellasist_product_id;
|
||||
}
|
||||
|
||||
// get_product_sku
|
||||
static public function get_product_sku( $product_id, $parent = false )
|
||||
{
|
||||
|
||||
@@ -3,32 +3,17 @@ namespace front\factory;
|
||||
|
||||
class ShopStatuses {
|
||||
|
||||
// get_baselinker_order_status_id
|
||||
static public function get_baselinker_order_status_id( $status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'baselinker_status_id', [ 'id' => $status_id ] );
|
||||
}
|
||||
|
||||
// get_apilo_status_id
|
||||
static public function get_apilo_status_id( $status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'apilo_status_id', [ 'id' => $status_id ] );
|
||||
}
|
||||
|
||||
// get sellasist status id
|
||||
static public function get_sellasist_status_id( $status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'sellasist_status_id', [ 'id' => $status_id ] );
|
||||
}
|
||||
|
||||
// get_shop_status_by_integration_status_id
|
||||
static public function get_shop_status_by_integration_status_id( $integration, $integration_status_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( $integration == 'sellasist' )
|
||||
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'sellasist_status_id' => $integration_status_id ] );
|
||||
|
||||
if ( $integration == 'apilo' )
|
||||
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'apilo_status_id' => $integration_status_id ] );
|
||||
}
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
namespace front\factory;
|
||||
class ShopTransport
|
||||
{
|
||||
// get_sellasist_transport_id
|
||||
static public function get_sellasist_transport_id( $transport_method_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_transports', 'sellasist_shipment_method_id', [ 'id' => $transport_method_id ] );
|
||||
}
|
||||
|
||||
// get_apilo_carrier_account_id
|
||||
static public function get_apilo_carrier_account_id( $transport_method_id )
|
||||
{
|
||||
|
||||
@@ -8,9 +8,7 @@ class Order implements \ArrayAccess
|
||||
public $statuses;
|
||||
public $status;
|
||||
public $client_email;
|
||||
public $sellasist_order_id;
|
||||
public $summary;
|
||||
public $baselinker_order_id;
|
||||
public $apilo_order_id;
|
||||
public $date_order;
|
||||
public $payment_method_id;
|
||||
@@ -61,12 +59,6 @@ class Order implements \ArrayAccess
|
||||
return $statuses;
|
||||
}
|
||||
|
||||
public function update_baselinker_order_status_date( $date )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> update( 'pp_shop_orders', [ 'baselinker_order_status_date' => $date ], [ 'id' => $this -> id ] );
|
||||
}
|
||||
|
||||
public function update_aplio_order_status_date( $date )
|
||||
{
|
||||
global $mdb;
|
||||
@@ -77,28 +69,6 @@ class Order implements \ArrayAccess
|
||||
public function set_as_unpaid() {
|
||||
global $mdb;
|
||||
|
||||
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] ) {
|
||||
if ( $this -> sellasist_order_id ) {
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
|
||||
'paid' => 0,
|
||||
'payment_status' => 'unpaid'
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
|
||||
"accept: application/json",
|
||||
"apiKey: " . $sellasist_settings['api_code'],
|
||||
"Content-Type: application/json"
|
||||
) );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
}
|
||||
}
|
||||
|
||||
$mdb -> update( 'pp_shop_orders', [ 'paid' => 0 ], [ 'id' => $this -> id ] );
|
||||
return true;
|
||||
}
|
||||
@@ -108,53 +78,6 @@ class Order implements \ArrayAccess
|
||||
{
|
||||
global $mdb, $config;
|
||||
|
||||
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] )
|
||||
{
|
||||
if ( $this -> sellasist_order_id )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
|
||||
'paid' => str_replace( ',', '.', $this -> summary ),
|
||||
'payment_status' => 'paid'
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
|
||||
"accept: application/json",
|
||||
"apiKey: " . $sellasist_settings['api_code'],
|
||||
"Content-Type: application/json"
|
||||
) );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
}
|
||||
}
|
||||
|
||||
$baselinker_settings = \admin\factory\Integrations::baselinker_settings();
|
||||
if ( $baselinker_settings['enabled'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders'] )
|
||||
{
|
||||
if ( $this -> baselinker_order_id )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( [
|
||||
'token' => $baselinker_settings['api_code'],
|
||||
'method' => 'setOrderPayment',
|
||||
'parameters' => json_encode( [
|
||||
'order_id' => $this -> baselinker_order_id,
|
||||
'payment_done' => $this -> summary,
|
||||
'payment_date' => time( 'Y-m-d H:i:s' )
|
||||
] )
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
}
|
||||
}
|
||||
|
||||
// apilo
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders'] )
|
||||
@@ -233,51 +156,6 @@ class Order implements \ArrayAccess
|
||||
|
||||
$response['result'] = true;
|
||||
|
||||
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders'] )
|
||||
{
|
||||
if ( $this -> sellasist_order_id )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://projectpro.sellasist.pl/api/v1/orders/" . $this -> sellasist_order_id );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "PUT");
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( [
|
||||
'status' => \front\factory\ShopStatuses::get_sellasist_status_id( $status )
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, array(
|
||||
"accept: application/json",
|
||||
"apiKey: " . $sellasist_settings['api_code'],
|
||||
"Content-Type: application/json"
|
||||
) );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
}
|
||||
}
|
||||
|
||||
$baselinker_settings = \admin\factory\Integrations::baselinker_settings();
|
||||
if ( $baselinker_settings['enabled'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders'] )
|
||||
{
|
||||
if ( $this -> baselinker_order_id )
|
||||
{
|
||||
$ch = curl_init();
|
||||
curl_setopt( $ch, CURLOPT_URL, "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $ch, CURLOPT_POST, 1 );
|
||||
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( [
|
||||
'token' => $baselinker_settings['api_code'],
|
||||
'method' => 'setOrderStatus',
|
||||
'parameters' => json_encode( [
|
||||
'order_id' => $this -> baselinker_order_id,
|
||||
'status_id' => \shop\ShopStatus::get_baselinker_status_by_shop_status( $status )
|
||||
] )
|
||||
] ) );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$curl_result = curl_exec( $ch );
|
||||
curl_close( $ch );
|
||||
}
|
||||
}
|
||||
|
||||
// apilo
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders'] )
|
||||
|
||||
@@ -264,18 +264,6 @@ class Product implements \ArrayAccess
|
||||
return false;
|
||||
}
|
||||
|
||||
// pobierz id produktu z Baselinker
|
||||
static public function get_baselinker_product_id( int $product_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( 'pp_shop_products', [ 'parent_id', 'baselinker_product_id' ], [ 'id' => $product_id ] );
|
||||
if ( $result['baselinker_product_id'] )
|
||||
return $result['baselinker_product_id'];
|
||||
else
|
||||
return $mdb -> get( 'pp_shop_products', 'baselinker_product_id', [ 'id' => $result['parent_id'] ] );
|
||||
}
|
||||
|
||||
// pobierz kod SKU
|
||||
static public function get_product_sku( int $product_id )
|
||||
{
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
<?
|
||||
namespace shop;
|
||||
class ShopStatus {
|
||||
// get_status_by_baselinker_status
|
||||
static public function get_shop_status_by_baselinker_status( int $baselinker_status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'id', [ 'baselinker_status_id' => $baselinker_status_id ] );
|
||||
}
|
||||
|
||||
// get_baselinker_status_by_shop_status
|
||||
static public function get_baselinker_status_by_shop_status( int $shop_status_id ) {
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_statuses', 'baselinker_status_id', [ 'id' => $shop_status_id ] );
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ $database['long_query_time'] = 0.1;
|
||||
|
||||
$config['salt'] = 'dd6c0ee59bf35b208b6d9bf42dd60769';
|
||||
$config['google-ads-id'] = 'AW-810084545';
|
||||
$config['baselinker-start'] = '2031-06-09 21:26';
|
||||
|
||||
$config['redis']['host'] = '127.0.0.1';
|
||||
$config['redis']['port'] = 20470;
|
||||
$config['redis']['password'] = 'Gi7FzWtkry19hZ1BqT1LKEWfwokQpigh';
|
||||
|
||||
404
cron.php
404
cron.php
@@ -53,10 +53,7 @@ $mdb = new medoo( [
|
||||
] );
|
||||
|
||||
$settings = \front\factory\Settings::settings_details();
|
||||
$baselinker_settings = \front\factory\Shop::baselinker_settings();
|
||||
$apilo_settings = \admin\factory\Integrations::apilo_settings();
|
||||
$baselinker_settings = \admin\factory\Integrations::baselinker_settings();
|
||||
$sellasist_settings = \admin\factory\Integrations::sellasist_settings();
|
||||
|
||||
function parsePaczkomatAddress($input)
|
||||
{
|
||||
@@ -113,48 +110,6 @@ function getImageUrlById($id) {
|
||||
return isset($data['img']) ? $data['img'] : null;
|
||||
}
|
||||
|
||||
// pobieranie informacji o produkcie z sellasist.pl
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['sync_products'] and $sellasist_settings['api_code'] )
|
||||
{
|
||||
if ( $result = $mdb -> query( 'SELECT id, sellasist_product_id, sellasist_get_data_date, sellasist_product_name FROM pp_shop_products WHERE sellasist_product_id IS NOT NULL AND sellasist_product_id != 0 AND ( sellasist_get_data_date IS NULL OR sellasist_get_data_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-10 minutes', time() ) ) . '\' ) ORDER BY sellasist_get_data_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC ) )
|
||||
{
|
||||
$url = "https://projectpro.sellasist.pl/api/v1/products/" . $result['sellasist_product_id'] . "/";
|
||||
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( $responseData['id'] )
|
||||
{
|
||||
$price_brutto = $responseData['price'];
|
||||
$vat = $mdb -> get( 'pp_shop_products', 'vat', [ 'apilo_product_id' => $result['apilo_product_id'] ] );
|
||||
$price_netto = $price_brutto / ( ( 100 + $vat ) / 100 );
|
||||
|
||||
$mdb -> update( 'pp_shop_products', [ 'price_netto' => \S::normalize_decimal( $price_netto, 2 ), 'price_brutto' => \S::normalize_decimal( $price_brutto, 2 ) ], [ 'sellasist_product_id' => $result['sellasist_product_id'] ] );
|
||||
|
||||
\admin\factory\ShopProduct::update_product_combinations_prices( (int)$result['id'], $price_brutto, $vat, null );
|
||||
}
|
||||
|
||||
// aktualizowanie stanu magazynowego
|
||||
$mdb -> update( 'pp_shop_products', [ 'quantity' => $responseData['storages'][0]['quantity'] ], [ 'sellasist_product_id' => $result['sellasist_product_id'] ] );
|
||||
|
||||
$mdb -> update( 'pp_shop_products', [ 'sellasist_get_data_date' => date( 'Y-m-d H:i:s' ) ], [ 'sellasist_product_id' => $result['sellasist_product_id'] ] );
|
||||
|
||||
// Czyszczenie cache produktu
|
||||
\S::clear_product_cache( (int)$result['id'] );
|
||||
|
||||
echo '<p>Zaktualizowałem dane produktu <b>' . $result['sellasist_product_name'] . ' #' . $result['id'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
|
||||
// pobieranie informacji o produkcie z apilo.com
|
||||
if ( $apilo_settings['enabled'] and $apilo_settings['sync_products'] and $apilo_settings['access-token'] )
|
||||
{
|
||||
@@ -230,233 +185,6 @@ if ( $apilo_settings['enabled'] and $apilo_settings['access-token'] and ( !$apil
|
||||
echo '<p>Zaktualizowałem ceny produktów (APILO)</p>';
|
||||
}
|
||||
|
||||
// pobieranie informachji o produkcie w tym: cen, cen promocyjnych, wagi, stanów magazynowych
|
||||
if ( $baselinker_settings['enabled'] and $baselinker_settings['sync_products'] and $baselinker_settings['api_code'] )
|
||||
{
|
||||
if ( $result = $mdb -> query( 'SELECT id, baselinker_product_id, baselinker_get_data_date FROM pp_shop_products WHERE baselinker_product_id IS NOT NULL AND baselinker_product_id != 0 AND ( baselinker_get_data_date IS NULL OR baselinker_get_data_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-1440 minutes', time() ) ) . '\' ) ORDER BY baselinker_get_data_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC ) )
|
||||
{
|
||||
$methodParams = '{
|
||||
"inventory_id": "' . $baselinker_settings['inventory_id'] . '",
|
||||
"products": [' . $result['baselinker_product_id'] . ']
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $baselinker_settings['api_code'],
|
||||
"method" => "getInventoryProductsData",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
$i = 0;
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' and count( $response['products'] ) )
|
||||
{
|
||||
foreach ( $response['products'] as $baselinker_product_id => $baselinker_product )
|
||||
{
|
||||
// aktualizowanie ceny
|
||||
if ( $vat = $mdb -> get( 'pp_shop_products', 'vat', [ 'baselinker_product_id' => $baselinker_product_id ] ) )
|
||||
{
|
||||
$price_brutto = $baselinker_product['prices'][$baselinker_settings['price_group']];
|
||||
$price_netto = $baselinker_product['prices'][$baselinker_settings['price_group']] / ( ( 100 + $vat ) / 100 );
|
||||
|
||||
$price_brutto_promo = $baselinker_product['prices'][ $baselinker_settings['price_group_promo'] ];
|
||||
|
||||
if ( $price_brutto_promo and $price_brutto_promo != $price_brutto )
|
||||
{
|
||||
$price_netto_promo = $baselinker_product['prices'][$baselinker_settings['price_group_promo']] / ( ( 100 + $vat ) / 100 );
|
||||
$mdb -> update( 'pp_shop_products', [ 'price_netto_promo' => \S::normalize_decimal( $price_netto_promo, 2 ), 'price_brutto_promo' => \S::normalize_decimal( $price_brutto_promo, 2 ) ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
}
|
||||
else
|
||||
$mdb -> update( 'pp_shop_products', [ 'price_netto_promo' => null, 'price_brutto_promo' => null ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
$mdb -> update( 'pp_shop_products', [ 'price_netto' => \S::normalize_decimal( $price_netto, 2 ), 'price_brutto' => \S::normalize_decimal( $price_brutto, 2 ) ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
$product_id = $mdb -> get( 'pp_shop_products', 'id', [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
$vat = $mdb -> get( 'pp_shop_products', 'vat', [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
\admin\factory\ShopProduct::update_product_combinations_prices( (int)$product_id, $price_brutto, $vat, $price_brutto_promo );
|
||||
}
|
||||
|
||||
// aktualizowanie wagi
|
||||
$mdb -> update( 'pp_shop_products', [ 'weight' => $baselinker_product['weight'] ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
// aktualizowanie stanu magazynowego
|
||||
$mdb -> update( 'pp_shop_products', [ 'quantity' => $baselinker_product['stock'][$baselinker_settings['stock_id']] ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_get_data_date' => date( 'Y-m-d H:i:s' ) ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
|
||||
// Czyszczenie cache produktu
|
||||
\S::clear_product_cache( (int)$result['id'] );
|
||||
|
||||
echo '<p>Zaktualizowałem dane produktu <b>' . $baselinker_product['text_fields']['name'] . ' #' . $result['id'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_products', [ 'baselinker_get_data_date' => date( 'Y-m-d H:i:s' ) ], [ 'baselinker_product_id' => $baselinker_product_id ] );
|
||||
echo '<p>Z powodu błędu pominąłem produkt o ID: <b>' . $result['id'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sprawdzanie statusów zamówień w sellasist.pl jeżeli zamówienie nie jest zrealizowane, anulowane lub nieodebrane
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['sync_orders'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) )
|
||||
{
|
||||
$order = $mdb -> query( 'SELECT id, sellasist_order_id, sellasist_order_status_date, number FROM pp_shop_orders WHERE sellasist_order_id IS NOT NULL AND sellasist_order_id != 0 AND ( status != 6 AND status != 8 AND status != 9 ) AND ( sellasist_order_status_date IS NULL OR sellasist_order_status_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-30 minutes', time() ) ) . '\' ) ORDER BY sellasist_order_status_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC );
|
||||
if ( $order['sellasist_order_id'] )
|
||||
{
|
||||
$url = "https://projectpro.sellasist.pl/api/v1/orders/" . $order['sellasist_order_id'] . "/";
|
||||
|
||||
$api_code = \admin\factory\Integrations::sellasist_settings( 'api_code' );
|
||||
|
||||
$ch = curl_init( $url );
|
||||
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $ch, CURLOPT_HTTPHEADER, [
|
||||
"apiKey: " . $api_code,
|
||||
"accept: application/json"
|
||||
] );
|
||||
|
||||
$response = curl_exec( $ch );
|
||||
$responseData = json_decode( $response, true );
|
||||
|
||||
if ( $responseData['id'] and $responseData['status']['id'] ) {
|
||||
$shop_status_id = \front\factory\ShopStatuses::get_shop_status_by_integration_status_id( 'sellasist', $responseData['status']['id'] );
|
||||
$mdb -> update( 'pp_shop_orders', [ 'status' => $shop_status_id, 'sellasist_order_status_date' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Zaktualizowałem status zamówienia <b>' . $order['number'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wysyłanie zamówień do sellasist.pl
|
||||
if ( $sellasist_settings['enabled'] and $sellasist_settings['sync_orders'] and $sellasist_settings['api_code'] and $sellasist_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) )
|
||||
{
|
||||
$orders = $mdb -> select( 'pp_shop_orders', '*', [ 'AND' => [ 'sellasist_order_id' => null, 'date_order[<=]' => date( 'Y-m-d H:i:s', strtotime( '-1 minutes', time() ) ), 'date_order[>=]' => $sellasist_settings['sync_orders_date_start'] ], 'ORDER' => [ 'date_order' => 'ASC' ], 'LIMIT' => 1 ] );
|
||||
foreach ( $orders as $order )
|
||||
{
|
||||
$z = 0;
|
||||
|
||||
$products = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order['id'] ] );
|
||||
$products_array = [];
|
||||
foreach ( $products as $product )
|
||||
{
|
||||
$json_data['carts'][] = [
|
||||
'id' => $product['product_id'],
|
||||
'product_id' => \front\factory\ShopProduct::get_sellasist_product_id( $product['product_id'] ),
|
||||
'name' => $product['name'],
|
||||
'quantity' => $product['quantity'],
|
||||
'price' => $product['price_brutto_promo'] ? $product['price_brutto_promo'] : $product['price_brutto'],
|
||||
'message' => strip_tags( $product['attributes'] ) . ' | ' . $product['message']
|
||||
];
|
||||
}
|
||||
|
||||
$json_data['id'] = $order['id'];
|
||||
$json_data['currency'] = 'pln';
|
||||
$json_data['payment_status'] = $order['paid'] ? 'paid' : 'unpaid';
|
||||
$json_data['paid'] = $order['paid'] ? str_replace( ',', '.', $order['summary'] ) : 0;
|
||||
$json_data['status'] = \front\factory\ShopStatuses::get_sellasist_status_id( $order['status'] );
|
||||
$json_data['email'] = $order['client_email'];
|
||||
// date
|
||||
$json_data['date'] = date( 'Y-m-d H:i:s', strtotime( $order['date_order'] ) );
|
||||
// shipment_price
|
||||
$json_data['shipment_price'] = $order['transport_cost'];
|
||||
// payment_id
|
||||
$json_data['payment_id'] = \front\factory\ShopPaymentMethod::get_sellasist_payment_method_id( $order['payment_method_id'] );
|
||||
// payment_name
|
||||
$json_data['payment_name'] = $order['payment_method'];
|
||||
// shipment_id
|
||||
$json_data['shipment_id'] = \front\factory\ShopTransport::get_sellasist_transport_id( $order['transport_id'] );
|
||||
// shipment_name
|
||||
$json_data['shipment_name'] = strip_tags( $order['transport'] );
|
||||
// invoice
|
||||
$json_data['invoice'] = 0;
|
||||
// comment
|
||||
$json_data['comment'] = $order['message'];
|
||||
// bill_address
|
||||
$json_data['bill_address'] = [
|
||||
'name' => $order['client_name'],
|
||||
'surname' => $order['client_surname'],
|
||||
'street' => $order['client_street'],
|
||||
'city' => $order['client_city'],
|
||||
'postcode' => $order['client_postal_code'],
|
||||
'phone' => $order['client_phone'],
|
||||
'email' => $order['client_email'],
|
||||
'country' => [
|
||||
'id' => 170,
|
||||
'name' => 'Poland',
|
||||
'code' => 'PL'
|
||||
]
|
||||
];
|
||||
// shipment_address
|
||||
$json_data['shipment_address'] = [
|
||||
'name' => $order['client_name'],
|
||||
'surname' => $order['client_surname'],
|
||||
'street' => $order['client_street'],
|
||||
'city' => $order['client_city'],
|
||||
'postcode' => $order['client_postal_code'],
|
||||
'phone' => $order['client_phone'],
|
||||
'email' => $order['client_email'],
|
||||
'country' => [
|
||||
'id' => 170,
|
||||
'name' => 'Poland',
|
||||
'code' => 'PL'
|
||||
]
|
||||
];
|
||||
|
||||
// pickup_point
|
||||
if ( $order['inpost_paczkomat'] )
|
||||
{
|
||||
$pickup = explode( ' | ', $order['inpost_paczkomat'] );
|
||||
$pickup_code = $pickup[0];
|
||||
$pickup_address = $pickup[1];
|
||||
|
||||
$json_data['pickup_point'] = [
|
||||
'code' => $pickup_code,
|
||||
'type' => 'inpost',
|
||||
'address' => $pickup_address
|
||||
];
|
||||
}
|
||||
|
||||
// URL docelowe
|
||||
$url = "https://projectpro.sellasist.pl/api/v1/orders";
|
||||
|
||||
// Nagłówki
|
||||
$headers = array(
|
||||
"accept: application/json",
|
||||
"apiKey: " . $sellasist_settings['api_code'],
|
||||
"Content-Type: application/json"
|
||||
);
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_POST, 1);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($json_data) );
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
$response = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Błąd cURL: ' . curl_error($ch);
|
||||
}
|
||||
curl_close($ch);
|
||||
$response = json_decode( $response, true );
|
||||
|
||||
if ( $response['status'] == 'exist' ) {
|
||||
|
||||
$mdb -> update( 'pp_shop_orders', [ 'sellasist_order_id' => $response['order_id'] ], [ 'id' => $order['id'] ] );
|
||||
|
||||
} else if ( $response['id'] ) {
|
||||
|
||||
$mdb -> update( 'pp_shop_orders', [ 'sellasist_order_id' => $response['id'] ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Wysłałem zamówienie do sellasist.pl</p>';
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wysyłanie zamówień do apilo
|
||||
if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_settings['access-token'] and $apilo_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) )
|
||||
{
|
||||
@@ -796,138 +524,6 @@ if ( $apilo_settings['enabled'] and $apilo_settings['sync_orders'] and $apilo_se
|
||||
}
|
||||
}
|
||||
|
||||
// sprawdzanie statusów zamówień w baselinker.com jeżeli zamówienie nie jest zrealizowane, anulowane lub nieodebrane
|
||||
if ( $baselinker_settings['enabled'] and $baselinker_settings['sync_orders'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) )
|
||||
{
|
||||
$order = $mdb -> query( 'SELECT id, baselinker_order_id, baselinker_order_status_date, number FROM pp_shop_orders WHERE baselinker_order_id IS NOT NULL AND baselinker_order_id != 0 AND ( status != 6 AND status != 8 AND status != 9 ) AND ( baselinker_order_status_date IS NULL OR baselinker_order_status_date <= \'' . date( 'Y-m-d H:i:s', strtotime( '-30 minutes', time() ) ) . '\' ) ORDER BY baselinker_order_status_date ASC LIMIT 1' ) -> fetch( \PDO::FETCH_ASSOC );
|
||||
if ( $order['baselinker_order_id'] )
|
||||
{
|
||||
$methodParams = '{
|
||||
"order_id": ' . $order['baselinker_order_id'] . '
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $baselinker_settings['api_code'],
|
||||
"method" => "getOrders",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' and count( $response['orders'] ) )
|
||||
{
|
||||
$shop_status_id = \shop\ShopStatus::get_shop_status_by_baselinker_status( (int) $response['orders'][0]['order_status_id'] );
|
||||
|
||||
$order_tmp = new Order( $order['id'] );
|
||||
$order_tmp -> update_status( $shop_status_id, false );
|
||||
$order_tmp -> update_baselinker_order_status_date( date( 'Y-m-d H:i:s' ) );
|
||||
echo '<p>Zaktualizowałem status zamówienia <b>' . $order['number'] . '</b></p>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'baselinker_order_status_date' => date( 'Y-m-d H:i:s' ) ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Z powodu błędu pominąłem zamówienie o ID: <b>' . $order['id'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// wysyłanie zamówień do baselinker
|
||||
if ( $baselinker_settings['enabled'] and $baselinker_settings['sync_orders'] and $baselinker_settings['api_code'] and $baselinker_settings['sync_orders_date_start'] <= date( 'Y-m-d H:i:s' ) )
|
||||
{
|
||||
$orders = $mdb -> select( 'pp_shop_orders', '*', [ 'AND' => [ 'baselinker_order_id' => null, 'date_order[<=]' => date( 'Y-m-d H:i:s', strtotime( '-1 minutes', time() ) ), 'date_order[>=]' => $baselinker_settings['sync_orders_date_start'] ], 'ORDER' => [ 'date_order' => 'ASC' ], 'LIMIT' => 1 ] );
|
||||
foreach ( $orders as $order )
|
||||
{
|
||||
if ( $order['transport_id'] == 2 )
|
||||
{
|
||||
$pickup = explode( ' | ', $order['inpost_paczkomat'] );
|
||||
$pickup_name = $pickup[0];
|
||||
$pickup_address = $pickup[1];
|
||||
}
|
||||
|
||||
$methodParams = '{
|
||||
"order_status_id": "' . \front\factory\ShopStatuses::get_baselinker_order_status_id( $order['status'] ) . '",
|
||||
"date_add": "' . strtotime( $order['date_order'] ) . '",
|
||||
"user_comments": "' . preg_replace('/\s+/', ' ', \S::remove_special_chars( $order['message'] ) ) . '",
|
||||
"admin_comments": "' . $order['notes'] . '",
|
||||
"phone": "' . $order['client_phone'] . '",
|
||||
"email": "' . $order['client_email'] . '",
|
||||
"user_login": "' . $order['client_name'] . ' ' . $order['client_surname'] . '",
|
||||
"currency": "PLN",
|
||||
"payment_method": "' . $order['payment_method'] . '",
|
||||
"payment_method_cod": "' . ( $order['payment_method_id'] == 3 ? 1 : 0 ) . '",
|
||||
"paid": "' . $order['paid'] . '",
|
||||
"delivery_method": "' . strip_tags( $order['transport'] ) . '",
|
||||
"delivery_price": "' . $order['transport_cost'] . '",
|
||||
"delivery_fullname": "' . $order['client_name'] . ' ' . $order['client_surname'] . '",
|
||||
"delivery_company": "' . $order['client_firm'] . '",
|
||||
"delivery_address": "' . $order['client_street'] . '",
|
||||
"delivery_city": "' . $order['client_city'] . '",
|
||||
"delivery_postcode": "' . $order['client_postal_code'] . '",
|
||||
"delivery_country_code": "PL",
|
||||
"delivery_point_id": "' . $pickup_name . '",
|
||||
"delivery_point_name": "' . ( $pickup_name != '' ? 'Paczkomat ' . $pickup_name : '' ) . '",
|
||||
"delivery_point_address": "' . $pickup_address . '",
|
||||
"delivery_point_postcode": "",
|
||||
"delivery_point_city": "",
|
||||
"invoice_fullname": "",
|
||||
"invoice_company": "",
|
||||
"invoice_nip": "",
|
||||
"invoice_address": "",
|
||||
"invoice_city": "",
|
||||
"invoice_postcode": "",
|
||||
"invoice_country_code": "",
|
||||
"want_invoice": "0",
|
||||
"extra_field_1": "",
|
||||
"extra_field_2": "",
|
||||
"products": [';
|
||||
$products = $mdb -> select( 'pp_shop_order_products', '*', [ 'order_id' => $order['id'] ] );
|
||||
foreach ( $products as $product )
|
||||
{
|
||||
$methodParams .= '{
|
||||
"storage": "db",
|
||||
"storage_id": 0,
|
||||
"product_id": "' .\shop\Product::get_baselinker_product_id( (int)$product['product_id'] ) . '",
|
||||
"variant_id": "",
|
||||
"name": "' . htmlspecialchars( $product['name'] ) . '",
|
||||
"sku": "' . \shop\Product::get_product_sku( (int)$product['product_id'] ) . '",
|
||||
"ean": "",
|
||||
"attributes": "' . strip_tags( $product['attributes'] ) . ' | ' . strip_tags( str_replace( '<br>', ' | ', preg_replace( '/\s+/', ' ', $product['custom_fields'] ) ) ) . ' | ' . preg_replace( '/\s+/', ' ', htmlspecialchars( $product['message'] ) ) . '",
|
||||
"price_brutto": ' . ( $product['price_brutto_promo'] ? $product['price_brutto_promo'] : $product['price_brutto'] ) . ',
|
||||
"tax_rate": ' . $product['vat'] . ',
|
||||
"quantity": ' . $product['quantity'] . ',
|
||||
"weight": 1
|
||||
}';
|
||||
|
||||
if ( $product != end( $products ) )
|
||||
$methodParams .= ',';
|
||||
}
|
||||
$methodParams .= ']
|
||||
}';
|
||||
|
||||
$apiParams = [
|
||||
"token" => $baselinker_settings['api_code'],
|
||||
"method" => "addOrder",
|
||||
"parameters" => $methodParams
|
||||
];
|
||||
|
||||
$curl = curl_init( "https://api.baselinker.com/connector.php" );
|
||||
curl_setopt( $curl, CURLOPT_POST, 1 );
|
||||
curl_setopt( $curl, CURLOPT_POSTFIELDS, http_build_query( $apiParams ) );
|
||||
curl_setopt( $curl, CURLOPT_RETURNTRANSFER, true );
|
||||
$response = json_decode( curl_exec( $curl ), true );
|
||||
|
||||
if ( $response['status'] == 'SUCCESS' )
|
||||
{
|
||||
$mdb -> update( 'pp_shop_orders', [ 'baselinker_order_id' => $response['order_id'] ], [ 'id' => $order['id'] ] );
|
||||
echo '<p>Wysłałem zamówienie do Baselinker <b>' . $order['number'] . '</b></p>';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* zapisywanie historii cen produktów */
|
||||
$results = $mdb -> select( 'pp_shop_products', [ 'id', 'price_brutto', 'price_brutto_promo' ], [ 'OR' => [ 'price_history_date[!]' => date( 'Y-m-d' ), 'price_history_date' => null ], 'ORDER' => [ 'price_history_date' => 'ASC' ], 'LIMIT' => 100 ] );
|
||||
foreach ( $results as $row )
|
||||
|
||||
@@ -51,7 +51,6 @@ $mdb = new medoo( [
|
||||
] );
|
||||
|
||||
$settings = \front\factory\Settings::settings_details();
|
||||
$baselinker_settings = \front\factory\Shop::baselinker_settings();
|
||||
$lang_id = \front\factory\Languages::default_language();
|
||||
|
||||
\admin\factory\ShopProduct::generate_google_feed_xml();
|
||||
204
tests/Unit/Domain/Integrations/IntegrationsRepositoryTest.php
Normal file
204
tests/Unit/Domain/Integrations/IntegrationsRepositoryTest.php
Normal file
@@ -0,0 +1,204 @@
|
||||
<?php
|
||||
namespace Tests\Unit\Domain\Integrations;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
|
||||
class IntegrationsRepositoryTest extends TestCase
|
||||
{
|
||||
private $mockDb;
|
||||
private IntegrationsRepository $repository;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->mockDb = $this->createMock(\medoo::class);
|
||||
$this->repository = new IntegrationsRepository($this->mockDb);
|
||||
}
|
||||
|
||||
public function testGetSettingsReturnsArray(): void
|
||||
{
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->expects($this->once())
|
||||
->method('fetchAll')
|
||||
->with(\PDO::FETCH_ASSOC)
|
||||
->willReturn([
|
||||
['name' => 'client-id', 'value' => 'abc123'],
|
||||
['name' => 'client-secret', 'value' => 'secret'],
|
||||
]);
|
||||
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('query')
|
||||
->with('SELECT * FROM pp_shop_apilo_settings')
|
||||
->willReturn($stmt);
|
||||
|
||||
$settings = $this->repository->getSettings('apilo');
|
||||
|
||||
$this->assertIsArray($settings);
|
||||
$this->assertSame('abc123', $settings['client-id']);
|
||||
$this->assertSame('secret', $settings['client-secret']);
|
||||
}
|
||||
|
||||
public function testGetSettingReturnsValue(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_apilo_settings', 'value', ['name' => 'client-id'])
|
||||
->willReturn('abc123');
|
||||
|
||||
$this->assertSame('abc123', $this->repository->getSetting('apilo', 'client-id'));
|
||||
}
|
||||
|
||||
public function testGetSettingReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_apilo_settings', 'value', ['name' => 'nonexistent'])
|
||||
->willReturn(false);
|
||||
|
||||
$this->assertNull($this->repository->getSetting('apilo', 'nonexistent'));
|
||||
}
|
||||
|
||||
public function testSaveSettingUpdatesExistingValue(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('count')
|
||||
->with('pp_shop_apilo_settings', ['name' => 'client-id'])
|
||||
->willReturn(1);
|
||||
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with('pp_shop_apilo_settings', ['value' => 'new-value'], ['name' => 'client-id']);
|
||||
|
||||
$this->assertTrue($this->repository->saveSetting('apilo', 'client-id', 'new-value'));
|
||||
}
|
||||
|
||||
public function testSaveSettingInsertsNewValue(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('count')
|
||||
->with('pp_shop_shoppro_settings', ['name' => 'domain'])
|
||||
->willReturn(0);
|
||||
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('insert')
|
||||
->with('pp_shop_shoppro_settings', ['name' => 'domain', 'value' => 'example.com']);
|
||||
|
||||
$this->assertTrue($this->repository->saveSetting('shoppro', 'domain', 'example.com'));
|
||||
}
|
||||
|
||||
public function testInvalidProviderThrowsException(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->repository->getSettings('sellasist');
|
||||
}
|
||||
|
||||
public function testLinkProductUpdatesDatabase(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with(
|
||||
'pp_shop_products',
|
||||
$this->callback(function ($data) {
|
||||
return isset($data['apilo_product_id']) && isset($data['apilo_product_name']);
|
||||
}),
|
||||
['id' => 42]
|
||||
)
|
||||
->willReturn(1);
|
||||
|
||||
$this->assertTrue($this->repository->linkProduct(42, 'ext-123', 'Test Product'));
|
||||
}
|
||||
|
||||
public function testUnlinkProductClearsFields(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('update')
|
||||
->with(
|
||||
'pp_shop_products',
|
||||
['apilo_product_id' => null, 'apilo_product_name' => null],
|
||||
['id' => 42]
|
||||
)
|
||||
->willReturn(1);
|
||||
|
||||
$this->assertTrue($this->repository->unlinkProduct(42));
|
||||
}
|
||||
|
||||
public function testGetProductSkuReturnsValue(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_products', 'sku', ['id' => 10])
|
||||
->willReturn('SKU-100');
|
||||
|
||||
$this->assertSame('SKU-100', $this->repository->getProductSku(10));
|
||||
}
|
||||
|
||||
public function testGetProductSkuReturnsNullForMissing(): void
|
||||
{
|
||||
$this->mockDb->expects($this->once())
|
||||
->method('get')
|
||||
->with('pp_shop_products', 'sku', ['id' => 999])
|
||||
->willReturn(false);
|
||||
|
||||
$this->assertNull($this->repository->getProductSku(999));
|
||||
}
|
||||
|
||||
public function testApiloGetAccessTokenReturnsNullWithoutSettings(): void
|
||||
{
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([]);
|
||||
|
||||
$this->mockDb->method('query')->willReturn($stmt);
|
||||
|
||||
$this->assertNull($this->repository->apiloGetAccessToken());
|
||||
}
|
||||
|
||||
public function testApiloFetchListThrowsForInvalidType(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->repository->apiloFetchList('invalid');
|
||||
}
|
||||
|
||||
public function testAllPublicMethodsExist(): void
|
||||
{
|
||||
$expectedMethods = [
|
||||
'getSettings', 'getSetting', 'saveSetting',
|
||||
'linkProduct', 'unlinkProduct',
|
||||
'apiloAuthorize', 'apiloGetAccessToken',
|
||||
'apiloFetchList', 'apiloProductSearch', 'apiloCreateProduct',
|
||||
'getProductSku', 'shopproImportProduct',
|
||||
];
|
||||
|
||||
foreach ($expectedMethods as $method) {
|
||||
$this->assertTrue(
|
||||
method_exists($this->repository, $method),
|
||||
"Method $method does not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testSettingsTableMapping(): void
|
||||
{
|
||||
// Verify apilo maps correctly
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([]);
|
||||
$this->mockDb->method('query')
|
||||
->with($this->stringContains('pp_shop_apilo_settings'))
|
||||
->willReturn($stmt);
|
||||
|
||||
$this->assertIsArray($this->repository->getSettings('apilo'));
|
||||
}
|
||||
|
||||
public function testShopproProviderWorks(): void
|
||||
{
|
||||
$stmt = $this->createMock(\PDOStatement::class);
|
||||
$stmt->method('fetchAll')->willReturn([
|
||||
['name' => 'domain', 'value' => 'test.com'],
|
||||
]);
|
||||
$this->mockDb->method('query')
|
||||
->with($this->stringContains('pp_shop_shoppro_settings'))
|
||||
->willReturn($stmt);
|
||||
|
||||
$settings = $this->repository->getSettings('shoppro');
|
||||
$this->assertSame('test.com', $settings['domain']);
|
||||
}
|
||||
}
|
||||
171
tests/Unit/admin/Controllers/IntegrationsControllerTest.php
Normal file
171
tests/Unit/admin/Controllers/IntegrationsControllerTest.php
Normal file
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
namespace Tests\Unit\admin\Controllers;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use admin\Controllers\IntegrationsController;
|
||||
use Domain\Integrations\IntegrationsRepository;
|
||||
|
||||
class IntegrationsControllerTest extends TestCase
|
||||
{
|
||||
private $repository;
|
||||
private IntegrationsController $controller;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->repository = $this->createMock(IntegrationsRepository::class);
|
||||
$this->controller = new IntegrationsController($this->repository);
|
||||
}
|
||||
|
||||
public function testConstructorAcceptsDependencies(): void
|
||||
{
|
||||
$controller = new IntegrationsController($this->repository);
|
||||
$this->assertInstanceOf(IntegrationsController::class, $controller);
|
||||
}
|
||||
|
||||
public function testConstructorRequiresRepository(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass(IntegrationsController::class);
|
||||
$constructor = $reflection->getConstructor();
|
||||
$params = $constructor->getParameters();
|
||||
|
||||
$this->assertCount(1, $params);
|
||||
$this->assertEquals(
|
||||
'Domain\Integrations\IntegrationsRepository',
|
||||
$params[0]->getType()->getName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testHasAllApiloSettingsMethods(): void
|
||||
{
|
||||
$methods = [
|
||||
'apilo_settings',
|
||||
'apilo_settings_save',
|
||||
'apilo_authorization',
|
||||
];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertTrue(
|
||||
method_exists($this->controller, $method),
|
||||
"Method $method does not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasAllApiloDataFetchMethods(): void
|
||||
{
|
||||
$methods = [
|
||||
'get_platform_list',
|
||||
'get_status_types_list',
|
||||
'get_carrier_account_list',
|
||||
'get_payment_types_list',
|
||||
];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertTrue(
|
||||
method_exists($this->controller, $method),
|
||||
"Method $method does not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasAllApiloProductMethods(): void
|
||||
{
|
||||
$methods = [
|
||||
'apilo_create_product',
|
||||
'apilo_product_search',
|
||||
'apilo_product_select_save',
|
||||
'apilo_product_select_delete',
|
||||
];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertTrue(
|
||||
method_exists($this->controller, $method),
|
||||
"Method $method does not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testHasAllShopproMethods(): void
|
||||
{
|
||||
$methods = [
|
||||
'shoppro_settings',
|
||||
'shoppro_settings_save',
|
||||
'shoppro_product_import',
|
||||
];
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertTrue(
|
||||
method_exists($this->controller, $method),
|
||||
"Method $method does not exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testApiloSettingsReturnsString(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
$this->assertEquals('string', (string) $reflection->getMethod('apilo_settings')->getReturnType());
|
||||
}
|
||||
|
||||
public function testShopproSettingsReturnsString(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
$this->assertEquals('string', (string) $reflection->getMethod('shoppro_settings')->getReturnType());
|
||||
}
|
||||
|
||||
public function testVoidReturnTypes(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
|
||||
$voidMethods = [
|
||||
'apilo_settings_save',
|
||||
'apilo_authorization',
|
||||
'get_platform_list',
|
||||
'get_status_types_list',
|
||||
'get_carrier_account_list',
|
||||
'get_payment_types_list',
|
||||
'apilo_create_product',
|
||||
'apilo_product_search',
|
||||
'apilo_product_select_save',
|
||||
'apilo_product_select_delete',
|
||||
'shoppro_settings_save',
|
||||
'shoppro_product_import',
|
||||
];
|
||||
|
||||
foreach ($voidMethods as $method) {
|
||||
$this->assertEquals(
|
||||
'void',
|
||||
(string) $reflection->getMethod($method)->getReturnType(),
|
||||
"Method $method should return void"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDoesNotHaveSellasistMethods(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
$methods = array_map(fn($m) => $m->getName(), $reflection->getMethods());
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertStringNotContainsString(
|
||||
'sellasist',
|
||||
strtolower($method),
|
||||
"Controller should not have sellasist method: $method"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testDoesNotHaveBaselinkerMethods(): void
|
||||
{
|
||||
$reflection = new \ReflectionClass($this->controller);
|
||||
$methods = array_map(fn($m) => $m->getName(), $reflection->getMethods());
|
||||
|
||||
foreach ($methods as $method) {
|
||||
$this->assertStringNotContainsString(
|
||||
'baselinker',
|
||||
strtolower($method),
|
||||
"Controller should not have baselinker method: $method"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,7 @@ if (!class_exists('S')) {
|
||||
public static function clear_redis_cache() {}
|
||||
public static function clear_product_cache($id) {}
|
||||
public static function send_email($to, $subject, $body) { return true; }
|
||||
public static function remove_special_chars($str) { return str_ireplace(['\'', '"', ',', ';', '<', '>'], ' ', $str); }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
updates/0.20/ver_0.263.zip
Normal file
BIN
updates/0.20/ver_0.263.zip
Normal file
Binary file not shown.
8
updates/0.20/ver_0.263_files.txt
Normal file
8
updates/0.20/ver_0.263_files.txt
Normal file
@@ -0,0 +1,8 @@
|
||||
F: ../admin/templates/baselinker/bundling-products.php
|
||||
F: ../admin/templates/integrations/baselinker-settings.php
|
||||
F: ../admin/templates/integrations/sellasist-settings.php
|
||||
F: ../autoload/admin/controls/class.Baselinker.php
|
||||
F: ../autoload/admin/controls/class.Integrations.php
|
||||
F: ../autoload/admin/factory/class.Baselinker.php
|
||||
F: ../autoload/front/factory/class.Shop.php
|
||||
F: ../autoload/shop/class.ShopStatus.php
|
||||
@@ -1,4 +1,11 @@
|
||||
<b>ver. 0.262 - 13.02.2026</b><br />
|
||||
<b>ver. 0.263 - 13.02.2026</b><br />
|
||||
- NEW - migracja modulu `Integrations` do architektury Domain + DI (`Domain\Integrations\IntegrationsRepository`, `admin\Controllers\IntegrationsController`)
|
||||
- CLEANUP - usunieto integracje Sellasist i Baselinker z calego projektu (kontrolery, factory, szablony, referencje w cron/Order/ShopStatuses/ShopTransport/ShopPaymentMethod/ShopProduct)
|
||||
- UPDATE - `admin\factory\Integrations` jako fasada delegujaca do repozytorium (tylko Apilo + ShopPRO)
|
||||
- FIX - naprawione polskie znaki w `product-edit.php` (usuniety podwojny encoding UTF-8/CP1250)
|
||||
- CLEANUP - usuniete pliki: `controls/Integrations`, `controls/Baselinker`, `factory/Baselinker`, `front/factory/Shop`, `shop/ShopStatus`, szablony sellasist/baselinker
|
||||
- UPDATE - pliki aktualizacji: `updates/0.20/ver_0.263.zip`, `ver_0.263_files.txt`
|
||||
<hr><b>ver. 0.262 - 13.02.2026</b><br />
|
||||
- NEW - migracja modulu `Pages` do architektury Domain + DI (`Domain\\Pages\\PagesRepository`, `admin\\Controllers\\PagesController`)
|
||||
- UPDATE - widoki `/admin/pages/*` przepiete na nowy routing i komponent `components/form-edit` (menu/page edit)
|
||||
- FIX - przywrocony przycisk generowania linku SEO w edycji strony (zakladka SEO, pola jezykowe)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?
|
||||
$current_ver = 262;
|
||||
$current_ver = 263;
|
||||
|
||||
for ($i = 1; $i <= $current_ver; $i++)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user