Skip to content

Commit

Permalink
Adapt to new LCSC provider
Browse files Browse the repository at this point in the history
Change each provider's .env var _ENABLE to match PROVIDER_LCSC_ENABLED
- Also adapt documentation for those vars
- Change isActive() to match the one in LCSCProvider

Remove LCSC from structured data provider as it now has a dedicated one
- currency code fix. Otherwise, it would make sense to re-use LCSCProvider's getUsedCurrency()
- example in docs
  • Loading branch information
jyevon committed May 17, 2024
1 parent e9af05e commit e9e3647
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .docker/symfony.conf
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
PassEnv PROVIDER_OCTOPART_CLIENT_ID PROVIDER_OCTOPART_SECRET PROVIDER_OCTOPART_CURRENCY PROVIDER_OCTOPART_COUNTRY PROVIDER_OCTOPART_SEARCH_LIMIT PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS
PassEnv PROVIDER_MOUSER_KEY PROVIDER_MOUSER_SEARCH_OPTION PROVIDER_MOUSER_SEARCH_LIMIT PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE
PassEnv PROVIDER_LCSC_ENABLED PROVIDER_LCSC_CURRENCY
PassEnv PROVIDER_STRUCDATA_ENABLE PROVIDER_STRUCDATA_TRUSTED_DOMAINS PROVIDER_STRUCDATA_ADD_GTIN_TO_ORDERNO
PassEnv PROVIDER_POLLIN_ENABLE PROVIDER_POLLIN_STORE_ID PROVIDER_POLLIN_SEARCH_LIMIT PROVIDER_POLLIN_ADD_GTIN_TO_ORDERNO
PassEnv PROVIDER_REICHELT_ENABLE PROVIDER_REICHELT_LANGUAGE PROVIDER_REICHELT_COUNTRY PROVIDER_REICHELT_CURRENCY PROVIDER_REICHELT_GET_NET_PRICES PROVIDER_REICHELT_ADD_GTIN_TO_ORDERNO
PassEnv PROVIDER_STRUCDATA_ENABLED PROVIDER_STRUCDATA_TRUSTED_DOMAINS PROVIDER_STRUCDATA_ADD_GTIN_TO_ORDERNO
PassEnv PROVIDER_POLLIN_ENABLED PROVIDER_POLLIN_STORE_ID PROVIDER_POLLIN_SEARCH_LIMIT PROVIDER_POLLIN_ADD_GTIN_TO_ORDERNO
PassEnv PROVIDER_REICHELT_ENABLED PROVIDER_REICHELT_LANGUAGE PROVIDER_REICHELT_COUNTRY PROVIDER_REICHELT_CURRENCY PROVIDER_REICHELT_GET_NET_PRICES PROVIDER_REICHELT_ADD_GTIN_TO_ORDERNO
PassEnv EDA_KICAD_CATEGORY_DEPTH

# For most configuration files from conf-available/, which are
Expand Down
14 changes: 7 additions & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -172,22 +172,22 @@ PROVIDER_MOUSER_SEARCH_WITH_SIGNUP_LANGUAGE='true'
# LCSC does not provide an offical API, so this used the API LCSC uses to render their webshop.
# LCSC did not intended the use of this API and it could break any time, so use it at your own risk.

# We dont require an API key for LCSC, just set this to 1 to enable LCSC support
# We don't require an API key for LCSC, just set this to 1 to enable LCSC support
PROVIDER_LCSC_ENABLED=0
# The currency to get prices in (e.g. EUR, USD, etc.)
PROVIDER_LCSC_CURRENCY=EUR

# Structured Data Provider
# Set to 1 to enable this provider
PROVIDER_STRUCDATA_ENABLE=0
# We don't require an API key to retrieve structured data, just set this to 1 to enable support
PROVIDER_STRUCDATA_ENABLED=0
# Filter (RegEx) for domains that can be queried (e.g. '^(.+\.)*(lcsc.com|ebay\.(com|de|ch|at|pl|it|fr|nl|be|es|co\.uk))$')
PROVIDER_STRUCDATA_TRUSTED_DOMAINS=0
# Whether to append GTIN (aka EAN) to 'Supplier part number ' field
PROVIDER_STRUCDATA_ADD_GTIN_TO_ORDERNO=1

# Pollin Provider:
# Set to 1 to enable this provider
PROVIDER_POLLIN_ENABLE=0
# We don't require an API key for Pollin, just set this to 1 to enable Pollin support
PROVIDER_POLLIN_ENABLED=0
# Configure the store domain you want to use, e.g. pollin.de or pollin.at. This decides the language and currency of results.
PROVIDER_POLLIN_STORE_ID=pollin.de
# The number of results to get from Pollin while searching (loading time increases drastically with higher numbers!)
Expand All @@ -196,8 +196,8 @@ PROVIDER_POLLIN_SEARCH_LIMIT=12
PROVIDER_POLLIN_ADD_GTIN_TO_ORDERNO=1

# Reichelt Provider:
# Set to 1 to enable this provider
PROVIDER_REICHELT_ENABLE=0
# We don't require an API key for Reichelt, just set this to 1 to enable Reichelt support
PROVIDER_REICHELT_ENABLED=0
# The language to get results in (DE, EN, FR, PL, NL, IT)
PROVIDER_REICHELT_LANGUAGE=EN
# The country to get results for (see docs for codes)
Expand Down
6 changes: 3 additions & 3 deletions config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -314,20 +314,20 @@ services:

App\Services\InfoProviderSystem\Providers\StructuredDataProvider:
arguments:
$enable: '%env(bool:PROVIDER_STRUCDATA_ENABLE)%'
$enable: '%env(bool:PROVIDER_STRUCDATA_ENABLED)%'
$trusted_domains: '%env(string:PROVIDER_STRUCDATA_TRUSTED_DOMAINS)%'
$add_gtin_to_orderno: '%env(bool:PROVIDER_STRUCDATA_ADD_GTIN_TO_ORDERNO)%'

App\Services\InfoProviderSystem\Providers\PollinProvider:
arguments:
$enable: '%env(bool:PROVIDER_POLLIN_ENABLE)%'
$enable: '%env(bool:PROVIDER_POLLIN_ENABLED)%'
$store_id: '%env(string:PROVIDER_POLLIN_STORE_ID)%'
$search_limit: '%env(int:PROVIDER_POLLIN_SEARCH_LIMIT)%'
$add_gtin_to_orderno: '%env(bool:PROVIDER_POLLIN_ADD_GTIN_TO_ORDERNO)%'

App\Services\InfoProviderSystem\Providers\ReicheltProvider:
arguments:
$enable: '%env(bool:PROVIDER_REICHELT_ENABLE)%'
$enable: '%env(bool:PROVIDER_REICHELT_ENABLED)%'
$lang: '%env(string:PROVIDER_REICHELT_LANGUAGE)%'
$country: '%env(string:PROVIDER_REICHELT_COUNTRY)%'
$currency: '%env(string:PROVIDER_REICHELT_CURRENCY)%'
Expand Down
7 changes: 3 additions & 4 deletions docs/usage/information_provider_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,9 @@ information with [BreadcrumbList](https://schema.org/BreadcrumbList), [WebSite](
URL into [Schema.org's validator](https://validator.schema.org/). Try, for instance:
* `https://www.voelkner.de/products/142706`
* `https://www.ebay.com/itm/185851714840`
* `https://www.lcsc.com/product-detail/Light-Emitting-Diodes-LED_Worldsemi-WS2812D-F5_C190565.html`

Following env configuration options are available:
* `PROVIDER_STRUCDATA_ENABLE`: Set to `1` to enable this provider (mandatory, default: `0`)
* `PROVIDER_STRUCDATA_ENABLED`: Set this to `1` to enable the structured data provider
* `PROVIDER_STRUCDATA_TRUSTED_DOMAINS`: Set a filter (RegEx) for URLs that can be called (strongly recommended!,
default: `0`)
* `PROVIDER_STRUCDATA_ADD_GTIN_TO_ORDERNO`: If this is set to `1` and a GTIN (aka EAN) was found, it is appended to the
Expand All @@ -246,7 +245,7 @@ shopping information from [Pollin](https://www.pollin.de/) since there exists no
on extracting data from HTML, but can still get disrupted by any future change to their website.

Following env configuration options are available:
* `PROVIDER_POLLIN_ENABLE`: Set to `1` to enable this provider (mandatory, default: `0`)
* `PROVIDER_POLLIN_ENABLED`: Set this to `1` to enable the Pollin provider
* `PROVIDER_POLLIN_SEARCH_LIMIT`: The maximum number of results to return per search (optional, default: `12`).
The loading time increases drastically with higher numbers because, currently, the product page of every result is called!
* `PROVIDER_POLLIN_STORE_ID`: The store domain you want to use, e.g. `pollin.de` or `pollin.at`.
Expand All @@ -262,7 +261,7 @@ shopping information from [Reichelt](https://www.reichelt.com/) since there exis
possible on extracting data from HTML, but can still get disrupted by any future change to their website.

Following env configuration options are available:
* `PROVIDER_REICHELT_ENABLE`: Set to `1` to enable this provider (mandatory, default: `0`)
* `PROVIDER_REICHELT_ENABLED`: Set this to `1` to enable the Reichelt provider
* `PROVIDER_REICHELT_LANGUAGE`: The language you want to get results in (`DE`, `EN`, `FR`, `PL`, `NL` and `IT`)
(optional, default: `EN`)
* `PROVIDER_REICHELT_COUNTRY`: The country you want to get results for (codes see below) (optional,
Expand Down
4 changes: 2 additions & 2 deletions src/Services/InfoProviderSystem/Providers/PollinProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getProviderInfo(): array
'name' => 'Pollin',
'description' => 'This provider scrapes Pollin online shop to search for parts.',
'url' => 'https://www.pollin.de/',
'disabled_help' => 'Set the PROVIDER_POLLIN_ENABLE env option.'
'disabled_help' => 'Set the PROVIDER_POLLIN_ENABLED env option to 1 (or true).'
];
}

Expand All @@ -55,7 +55,7 @@ public function getProviderKey(): string

public function isActive(): bool
{
return !empty($this->enable);
return $this->enable;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getProviderInfo(): array
'name' => 'Reichelt',
'description' => 'This provider scrapes Reichelt online shop to search for parts.',
'url' => self::BASE_URL,
'disabled_help' => 'Set the PROVIDER_REICHELT_ENABLE env option.'
'disabled_help' => 'Set the PROVIDER_REICHELT_ENABLED env option to 1 (or true).'
];
}

Expand All @@ -60,7 +60,7 @@ public function getProviderKey(): string

public function isActive(): bool
{
return !empty($this->enable);
return $this->enable;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getProviderInfo(): array
'name' => 'Structured Data (by URL)',
'description' => 'This provider calls, e.g. a product page, by URL and allows to import embedded machine-readable data as a part.',
'url' => 'https://schema.org/',
'disabled_help' => 'Set the PROVIDER_STRUCDATA_ENABLE env option.'
'disabled_help' => 'Set the PROVIDER_STRUCDATA_ENABLED env option to 1 (or true).'
];
}

Expand All @@ -61,7 +61,7 @@ public function getProviderKey(): string

public function isActive(): bool
{
return !empty($this->enable);
return $this->enable;
}

/**
Expand Down Expand Up @@ -309,8 +309,6 @@ protected function productToDTO(Schema\Product $product,
$quantity = $offer->eligibleQuantity->getFirstValue();

if (is_string($price)) {
if($priceCurrency == "US$") $priceCurrency = 'USD'; // for lcsc.com (ISO codes are seemingly overrated ...)

$prices[] = new PriceDTO(
minimum_discount_amount: ($quantity !== null) ? $quantity->minValue->getFirstNonEmptyStringValue() : 1,
price: str_replace(',', '', (string) $price) ?? '0',
Expand Down

0 comments on commit e9e3647

Please sign in to comment.