-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ea43992
commit 9b60fe3
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace Bildvitta\IssSupernova\Observers; | ||
|
||
use Bildvitta\IssSupernova\IssSupernova; | ||
use Illuminate\Support\Facades\App; | ||
use Illuminate\Support\Facades\Config; | ||
use Illuminate\Support\Facades\Log; | ||
|
||
class SaleAccessoryObserver | ||
{ | ||
public function created($saleAccessory) | ||
{ | ||
if (!Config::get('iss-supernova.base_uri')) { | ||
return; | ||
} | ||
|
||
$saleAccessory->loadMissing( | ||
'category', | ||
'accessory', | ||
'sale' | ||
); | ||
if ($saleAccessory->sale) { | ||
$saleAccessory->sale->loadMissing( | ||
'blueprint', | ||
'unit' | ||
); | ||
} | ||
$data = $saleAccessory->toArray(); | ||
$data['sync_to'] = 'sys'; | ||
|
||
try { | ||
$issSupernova = new IssSupernova(); | ||
$response = $issSupernova->saleAccessories()->create($data); | ||
return $response; | ||
} catch (\Throwable $exception) { | ||
Log::error($exception->getMessage()); | ||
throw $exception; | ||
} | ||
} | ||
|
||
public function updated($saleAccessory) | ||
{ | ||
if (!Config::get('iss-supernova.base_uri')) { | ||
return; | ||
} | ||
|
||
$saleAccessory->loadMissing( | ||
'category', | ||
'accessory', | ||
'sale' | ||
); | ||
if ($saleAccessory->sale) { | ||
$saleAccessory->sale->loadMissing( | ||
'blueprint', | ||
'unit' | ||
); | ||
} | ||
$data = $saleAccessory->toArray(); | ||
$data['sync_to'] = 'sys'; | ||
|
||
try { | ||
$issSupernova = new IssSupernova(); | ||
$response = $issSupernova->saleAccessories()->update($data); | ||
return $response; | ||
} catch (\Throwable $exception) { | ||
Log::error($exception->getMessage()); | ||
throw $exception; | ||
} | ||
} | ||
|
||
public function deleted($saleAccessory) | ||
{ | ||
// | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Bildvitta\IssSupernova\Resources; | ||
|
||
use Bildvitta\IssSupernova\IssSupernova; | ||
|
||
class SaleAccessories | ||
{ | ||
private IssSupernova $issSupernova; | ||
|
||
public function __construct(IssSupernova $issSupernova) | ||
{ | ||
$this->issSupernova = $issSupernova; | ||
} | ||
|
||
public function create($data) | ||
{ | ||
return $this->issSupernova->request->post( | ||
'/sales/accessories', | ||
$data | ||
)->throw()->object(); | ||
} | ||
|
||
public function update($data) | ||
{ | ||
return $this->issSupernova->request->put( | ||
'/sales/accessories', | ||
$data | ||
)->throw()->object(); | ||
} | ||
} |