Skip to content

Commit

Permalink
Merge pull request #19 from PrestaShopCorp/fix/retrocompat-for-tosurl…
Browse files Browse the repository at this point in the history
…-privacyurl

revert: use tosLink and privacyLink instead of tosUrl and privacyUrl for backward compatibility
  • Loading branch information
TakeshiDaveau authored Aug 31, 2023
2 parents e3abaf6 + 5b5700c commit b04e70a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,19 @@ chmod +x phpunit
```
./phpunit tests
```
### Introduce a breaking change in module-lib-billing
PrestaShop module system is not able to handle multiple version of the same library.
**Here is an example:**
- Module A requires the v1 of a libA
- Module B requires the v2 of this same libA
If someone install module A then module B, only the v1 of libA will be loaded for both Module A and Module B.
#### Workaround
When introducing a breaking change to a class or method signature, you should instead create a new class rather to changing the existing one.
By creating a new class it will force the autoloader to use the last version of the lib.
24 changes: 14 additions & 10 deletions src/Presenter/BillingPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function present($params)

$getEnv = $this->getBillingContextWrapper()->getBillingEnv() ?: '';
$billingEnv = $this->getEnvBuilder()->buildBillingEnv($getEnv);
$tosUrl = !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink'];
$privacyUrl = !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink'];

return [
'psBillingContext' => [
Expand All @@ -107,8 +109,8 @@ public function present($params)
'id' => $this->getModule()->name,
'displayName' => $this->getModule()->displayName,
'logoSrc' => $this->encodeImage($this->getModuleLogo()),
'privacyUrl' => !empty($params['privacyUrl']) ? $params['privacyUrl'] : '',
'tosUrl' => !empty($params['tosUrl']) ? $params['tosUrl'] : '',
'privacyUrl' => !empty($privacyUrl) ? $privacyUrl : '',
'tosUrl' => !empty($tosUrl) ? $tosUrl : '',
],
],
],
Expand All @@ -126,17 +128,19 @@ public function present($params)
*/
private function validateContextArgs($params)
{
if (empty($params['tosUrl'])) {
throw new BillingContextException('"tosUrl" must be provided (value=' . $params['tosUrl'] . ')');
$tosUrl = !empty($params['tosUrl']) ? $params['tosUrl'] : $params['tosLink'];
$privacyUrl = !empty($params['privacyUrl']) ? $params['privacyUrl'] : $params['privacyLink'];
if (empty($tosUrl)) {
throw new BillingContextException('"tosUrl" must be provided (value=' . $tosUrl . ')');
}
if (!\Validate::isAbsoluteUrl($params['tosUrl'])) {
throw new BillingContextException('"tosUrl" must be a valid url (value=' . $params['tosUrl'] . ')');
if (!\Validate::isAbsoluteUrl($tosUrl)) {
throw new BillingContextException('"tosUrl" must be a valid url (value=' . $tosUrl . ')');
}
if (empty($params['privacyUrl'])) {
throw new BillingContextException('"privacyUrl" must be provided (value=' . $params['privacyUrl'] . ')');
if (empty($privacyUrl)) {
throw new BillingContextException('"privacyUrl" must be provided (value=' . $privacyUrl . ')');
}
if (!\Validate::isAbsoluteUrl($params['privacyUrl'])) {
throw new BillingContextException('"privacyUrl" must be a valid url (value=' . $params['privacyUrl'] . ')');
if (!\Validate::isAbsoluteUrl($privacyUrl)) {
throw new BillingContextException('"privacyUrl" must be a valid url (value=' . $privacyUrl . ')');
}
}

Expand Down

0 comments on commit b04e70a

Please sign in to comment.