8888use App \Services \InfoProviderSystem \DTOs \PriceDTO ;
8989use App \Services \InfoProviderSystem \DTOs \PurchaseInfoDTO ;
9090use App \Services \InfoProviderSystem \DTOs \ParameterDTO ;
91+ use App \Settings \InfoProviderSystem \OEMSecretsSettings ;
92+ use App \Settings \InfoProviderSystem \OEMSecretsSortMode ;
9193use Symfony \Contracts \HttpClient \HttpClientInterface ;
9294use Psr \Cache \CacheItemPoolInterface ;
9395
@@ -99,12 +101,7 @@ class OEMSecretsProvider implements InfoProviderInterface
99101
100102 public function __construct (
101103 private readonly HttpClientInterface $ oemsecretsClient ,
102- private readonly string $ api_key ,
103- private readonly string $ country_code ,
104- private readonly string $ currency ,
105- private readonly string $ zero_price ,
106- private readonly string $ set_param ,
107- private readonly string $ sort_criteria ,
104+ private readonly OEMSecretsSettings $ settings ,
108105 private readonly CacheItemPoolInterface $ partInfoCache
109106 )
110107 {
@@ -268,7 +265,7 @@ public function getProviderKey(): string
268265 */
269266 public function isActive (): bool
270267 {
271- return $ this ->api_key !== '' ;
268+ return $ this ->settings -> apiKey !== '' ;
272269 }
273270
274271
@@ -324,9 +321,9 @@ public function searchByKeyword(string $keyword): array
324321 $ response = $ this ->oemsecretsClient ->request ('GET ' , self ::ENDPOINT_URL , [
325322 'query ' => [
326323 'searchTerm ' => $ keyword ,
327- 'apiKey ' => $ this ->api_key ,
328- 'currency ' => $ this ->currency ,
329- 'countryCode ' => $ this ->country_code ,
324+ 'apiKey ' => $ this ->settings -> apiKey ,
325+ 'currency ' => $ this ->settings -> currency ,
326+ 'countryCode ' => $ this ->settings -> country ,
330327 ],
331328 ]);
332329
@@ -533,7 +530,7 @@ private function processBatch(
533530
534531 // Extract prices
535532 $ priceDTOs = $ this ->getPrices ($ product );
536- if (empty ($ priceDTOs ) && ( int ) $ this ->zero_price === 0 ) {
533+ if (empty ($ priceDTOs ) && ! $ this ->settings -> keepZeroPrices ) {
537534 return null ; // Skip products without valid prices
538535 }
539536
@@ -557,7 +554,7 @@ private function processBatch(
557554 }
558555
559556 $ imagesResults [$ provider_id ] = $ this ->getImages ($ product , $ imagesResults [$ provider_id ] ?? []);
560- if ($ this ->set_param == 1 ) {
557+ if ($ this ->settings -> parseParams ) {
561558 $ parametersResults [$ provider_id ] = $ this ->getParameters ($ product , $ parametersResults [$ provider_id ] ?? []);
562559 } else {
563560 $ parametersResults [$ provider_id ] = [];
@@ -582,7 +579,7 @@ private function processBatch(
582579 $ regionB = $ this ->countryCodeToRegionMap [$ countryCodeB ] ?? '' ;
583580
584581 // If the map is empty or doesn't contain the key for $this->country_code, assign a placeholder region.
585- $ regionForEnvCountry = $ this ->countryCodeToRegionMap [$ this ->country_code ] ?? '' ;
582+ $ regionForEnvCountry = $ this ->countryCodeToRegionMap [$ this ->settings -> country ] ?? '' ;
586583
587584 // Convert to string before comparison to avoid mixed types
588585 $ countryCodeA = (string ) $ countryCodeA ;
@@ -599,9 +596,9 @@ private function processBatch(
599596 }
600597
601598 // Step 1: country_code from the environment
602- if ($ countryCodeA === $ this ->country_code && $ countryCodeB !== $ this ->country_code ) {
599+ if ($ countryCodeA === $ this ->settings -> country && $ countryCodeB !== $ this ->settings -> country ) {
603600 return -1 ;
604- } elseif ($ countryCodeA !== $ this ->country_code && $ countryCodeB === $ this ->country_code ) {
601+ } elseif ($ countryCodeA !== $ this ->settings -> country && $ countryCodeB === $ this ->settings -> country ) {
605602 return 1 ;
606603 }
607604
@@ -681,8 +678,8 @@ private function getPrices(array $product): array
681678
682679 if (is_array ($ prices )) {
683680 // Step 1: Check if prices exist in the preferred currency
684- if (isset ($ prices [$ this ->currency ]) && is_array ($ prices [$ this ->currency ])) {
685- $ priceDetails = $ prices [$ this ->currency ];
681+ if (isset ($ prices [$ this ->settings -> currency ]) && is_array ($ prices [$ this -> settings ->currency ])) {
682+ $ priceDetails = $ prices [$ this ->$ this -> settings -> currency ];
686683 foreach ($ priceDetails as $ priceDetail ) {
687684 if (
688685 is_array ($ priceDetail ) &&
@@ -694,7 +691,7 @@ private function getPrices(array $product): array
694691 $ priceDTOs [] = new PriceDTO (
695692 minimum_discount_amount: (float )$ priceDetail ['unit_break ' ],
696693 price: (string )$ priceDetail ['unit_price ' ],
697- currency_iso_code: $ this ->currency ,
694+ currency_iso_code: $ this ->settings -> currency ,
698695 includes_tax: false ,
699696 price_related_quantity: 1.0
700697 );
@@ -1293,7 +1290,7 @@ private function generateInquiryUrl(string $partNumber, string $oemInquiry = 'co
12931290 private function sortResultsData (array &$ resultsData , string $ searchKeyword ): void
12941291 {
12951292 // If the SORT_CRITERIA is not 'C' or 'M', do not sort
1296- if ($ this ->sort_criteria !== ' C ' && $ this ->sort_criteria !== ' M ' ) {
1293+ if ($ this ->settings -> sortMode !== OEMSecretsSortMode:: COMPLETENESS && $ this ->settings -> sortMode !== OEMSecretsSortMode:: MANUFACTURER ) {
12971294 return ;
12981295 }
12991296 usort ($ resultsData , function ($ a , $ b ) use ($ searchKeyword ) {
@@ -1332,9 +1329,9 @@ private function sortResultsData(array &$resultsData, string $searchKeyword): vo
13321329 }
13331330
13341331 // Final sorting: by completeness or manufacturer, if necessary
1335- if ($ this ->sort_criteria === ' C ' ) {
1332+ if ($ this ->settings -> sortMode === OEMSecretsSortMode:: COMPLETENESS ) {
13361333 return $ this ->compareByCompleteness ($ a , $ b );
1337- } elseif ($ this ->sort_criteria === ' M ' ) {
1334+ } elseif ($ this ->settings -> sortMode === OEMSecretsSortMode:: MANUFACTURER ) {
13381335 return strcasecmp ($ a ->manufacturer , $ b ->manufacturer );
13391336 }
13401337
0 commit comments