| 1 |
<?php |
| 2 |
|
| 3 |
namespace StoreEngine\Utils\traits; |
| 4 |
|
| 5 |
use StoreEngine\Classes\Data\IntegrationRepositoryData; |
| 6 |
use StoreEngine\Classes\Exceptions\StoreEngineException; |
| 7 |
use StoreEngine\Classes\IntegrationRepository; |
| 8 |
use StoreEngine\Classes\Price; |
| 9 |
use StoreEngine\Classes\Product\SimpleProduct; |
| 10 |
use StoreEngine\Classes\ProductFactory; |
| 11 |
|
| 12 |
trait Integration { |
| 13 |
|
| 14 |
/** |
| 15 |
* @param int $price_id |
| 16 |
* |
| 17 |
* @return \StoreEngine\Classes\Integration[] |
| 18 |
* @throws StoreEngineException |
| 19 |
*/ |
| 20 |
public static function get_integrations_by_price_id( int $price_id ): array { |
| 21 |
try { |
| 22 |
return ( new Price( $price_id ) )->get_integrations(); |
| 23 |
} catch ( StoreEngineException $e ) { |
| 24 |
return []; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
/** |
| 29 |
* @param int $product_id |
| 30 |
* |
| 31 |
* @return IntegrationRepositoryData[] |
| 32 |
* @throws StoreEngineException |
| 33 |
*/ |
| 34 |
public static function get_integrations_by_product_id( int $product_id ): array { |
| 35 |
return ProductFactory::getProduct( $product_id )->get_integrations(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* @param string $provider |
| 40 |
* @param int $integration_id |
| 41 |
* |
| 42 |
* @return IntegrationRepositoryData[] |
| 43 |
*/ |
| 44 |
public static function get_integration_repository_by_id( string $provider, int $integration_id ): array { |
| 45 |
return ( new IntegrationRepository( $provider ) )->get_by_id( $integration_id )->get_objects(); |
| 46 |
} |
| 47 |
|
| 48 |
/** |
| 49 |
* @param string $provider |
| 50 |
* @param int $price_id |
| 51 |
* |
| 52 |
* @return ?IntegrationRepositoryData |
| 53 |
*/ |
| 54 |
public static function get_integration_repository_by_price_id( string $provider, int $price_id ): ?IntegrationRepositoryData { |
| 55 |
return ( new IntegrationRepository( $provider ) )->get_by_price_id( $price_id ); |
| 56 |
} |
| 57 |
|
| 58 |
/** |
| 59 |
* @param string $provider |
| 60 |
* @param array $args |
| 61 |
* |
| 62 |
* @return IntegrationRepositoryData[] |
| 63 |
*/ |
| 64 |
public static function get_integration_repository_by_provider( string $provider, array $args = [] ): array { |
| 65 |
return ( new IntegrationRepository( $provider ) )->get_by_provider( $args )->get_objects(); |
| 66 |
} |
| 67 |
|
| 68 |
} |
| 69 |
|