mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-02-24 18:39:35 +00:00
Make Canopy provider configurable via UI
This commit is contained in:
parent
0b9b2cbf58
commit
300382f6e3
4 changed files with 70 additions and 4 deletions
|
|
@ -75,7 +75,7 @@ class CanopyProvider implements InfoProviderInterface
|
||||||
|
|
||||||
private function productPageFromASIN(string $asin): string
|
private function productPageFromASIN(string $asin): string
|
||||||
{
|
{
|
||||||
return "https://www.amazon.{$this->settings->domain}/dp/{$asin}";
|
return "https://www.{$this->settings->getRealDomain()}/dp/{$asin}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,23 +29,68 @@ use Jbtronics\SettingsBundle\Metadata\EnvVarMode;
|
||||||
use Jbtronics\SettingsBundle\Settings\Settings;
|
use Jbtronics\SettingsBundle\Settings\Settings;
|
||||||
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
use Jbtronics\SettingsBundle\Settings\SettingsParameter;
|
||||||
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
use Jbtronics\SettingsBundle\Settings\SettingsTrait;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||||
|
use Symfony\Component\Form\Extension\Core\Type\CountryType;
|
||||||
use Symfony\Component\Translation\TranslatableMessage as TM;
|
use Symfony\Component\Translation\TranslatableMessage as TM;
|
||||||
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
|
||||||
#[Settings(label: new TM("settings.ips.canopy"), description: new TM("settings.ips.canopy.help"))]
|
#[Settings(label: new TM("settings.ips.canopy"))]
|
||||||
#[SettingsIcon("fa-plug")]
|
#[SettingsIcon("fa-plug")]
|
||||||
class CanopySettings
|
class CanopySettings
|
||||||
{
|
{
|
||||||
|
public const ALLOWED_DOMAINS = [
|
||||||
|
"amazon.de" => "DE",
|
||||||
|
"amazon.com" => "US",
|
||||||
|
"amazon.co.uk" => "UK",
|
||||||
|
"amazon.fr" => "FR",
|
||||||
|
"amazon.it" => "IT",
|
||||||
|
"amazon.es" => "ES",
|
||||||
|
"amazon.ca" => "CA",
|
||||||
|
"amazon.com.au" => "AU",
|
||||||
|
"amazon.com.br" => "BR",
|
||||||
|
"amazon.com.mx" => "MX",
|
||||||
|
"amazon.in" => "IN",
|
||||||
|
"amazon.co.jp" => "JP",
|
||||||
|
"amazon.nl" => "NL",
|
||||||
|
"amazon.pl" => "PL",
|
||||||
|
"amazon.sa" => "SA",
|
||||||
|
"amazon.sg" => "SG",
|
||||||
|
"amazon.se" => "SE",
|
||||||
|
"amazon.com.tr" => "TR",
|
||||||
|
"amazon.ae" => "AE",
|
||||||
|
"amazon.com.be" => "BE",
|
||||||
|
"amazon.com.cn" => "CN",
|
||||||
|
];
|
||||||
|
|
||||||
use SettingsTrait;
|
use SettingsTrait;
|
||||||
|
|
||||||
#[SettingsParameter(label: new TM("settings.ips.canopy.apiKey"),
|
#[SettingsParameter(label: new TM("settings.ips.mouser.apiKey"),
|
||||||
formType: APIKeyType::class,
|
formType: APIKeyType::class,
|
||||||
formOptions: ["help_html" => true], envVar: "PROVIDER_CANOPY_API_KEY", envVarMode: EnvVarMode::OVERWRITE)]
|
formOptions: ["help_html" => true], envVar: "PROVIDER_CANOPY_API_KEY", envVarMode: EnvVarMode::OVERWRITE)]
|
||||||
public ?string $apiKey = null;
|
public ?string $apiKey = null;
|
||||||
|
|
||||||
public string $domain = "de";
|
/**
|
||||||
|
* @var string The domain used internally for the API requests. This is not necessarily the same as the domain shown to the user, which is determined by the keys of the ALLOWED_DOMAINS constant
|
||||||
|
*/
|
||||||
|
#[SettingsParameter(label: new TM("settings.ips.tme.country"), formType: ChoiceType::class, formOptions: ["choices" => self::ALLOWED_DOMAINS])]
|
||||||
|
public string $domain = "DE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var bool If true, the provider will always retrieve details for a part, resulting in an additional API request
|
* @var bool If true, the provider will always retrieve details for a part, resulting in an additional API request
|
||||||
*/
|
*/
|
||||||
|
#[SettingsParameter(label: new TM("settings.ips.canopy.alwaysGetDetails"), description: new TM("settings.ips.canopy.alwaysGetDetails.help"))]
|
||||||
public bool $alwaysGetDetails = false;
|
public bool $alwaysGetDetails = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the real domain (e.g. amazon.de) based on the selected domain (e.g. DE)
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getRealDomain(): string
|
||||||
|
{
|
||||||
|
$domain = array_search($this->domain, self::ALLOWED_DOMAINS);
|
||||||
|
if ($domain === false) {
|
||||||
|
throw new \InvalidArgumentException("Invalid domain selected");
|
||||||
|
}
|
||||||
|
return $domain;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -72,4 +72,7 @@ class InfoProviderSettings
|
||||||
|
|
||||||
#[EmbeddedSettings]
|
#[EmbeddedSettings]
|
||||||
public ?ConradSettings $conrad = null;
|
public ?ConradSettings $conrad = null;
|
||||||
|
|
||||||
|
#[EmbeddedSettings]
|
||||||
|
public ?CanopySettings $canopy = null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12569,5 +12569,23 @@ Buerklin-API Authentication server:
|
||||||
<target>Amazon barcode</target>
|
<target>Amazon barcode</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="BQWuR_G" name="settings.ips.canopy">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.canopy</source>
|
||||||
|
<target>Canopy</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="44BfYzy" name="settings.ips.canopy.alwaysGetDetails">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.canopy.alwaysGetDetails</source>
|
||||||
|
<target>Always fetch details</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="so_ms3t" name="settings.ips.canopy.alwaysGetDetails.help">
|
||||||
|
<segment>
|
||||||
|
<source>settings.ips.canopy.alwaysGetDetails.help</source>
|
||||||
|
<target>When selected, more details will be fetched from canopy when creating a part. This causes an additional API request, but gives product bullet points and category info.</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue