Skip to content

Commit

Permalink
Dynamically generate deeplink URL template
Browse files Browse the repository at this point in the history
Keeps the code DRY and ensures that other query params like an access token are included in the generated URL.
  • Loading branch information
lukasbestle committed Nov 12, 2022
1 parent 5e5c0d1 commit 0cf022a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 43 deletions.
8 changes: 0 additions & 8 deletions src/classes/ConfiguratorBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,6 @@ public function options(): array
{
$defaults = [];

// URL template for the configurator URL;
// the #CONFIGURATIONID# placeholder is dynamically replaced by Roomle
$defaults['deeplink'] = (
$this->parent()->url() .
'?' . $this->htmlId() . '=#CONFIGURATIONID#' .
'#' . $this->htmlId()
);

// locale settings from the site's language code
$language = $this->kirby()->language();
if ($language !== null) {
Expand Down
7 changes: 7 additions & 0 deletions src/frontend/public/configurator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export default class {
const options = this.props.options;
options.id = this.currentId;

// define the deeplink based on the current URL;
// use an intermediate placeholder to avoid that the `#` chars get escaped
options.deeplink = this.idToUrl(
this.props.htmlId + "-PLACEHOLDER",
true
).href.replace(this.props.htmlId + "-PLACEHOLDER", "#CONFIGURATIONID#");

// initialize the configured or passed product
this.configurator = await RoomleConfiguratorApi.createConfigurator(
this.props.configuratorId,
Expand Down
35 changes: 0 additions & 35 deletions tests/Roomle/ConfiguratorBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,6 @@ public function testFrontendJson()
'configuratorId' => 'defaultConfigurator',
'htmlId' => 'roomle-12345678-90ab-cdef-1234-567890abcdef',
'options' => [
'deeplink' => (
'https://example.com/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'some' => 'default',
'other' => 'default',
'id' => 'some:product',
Expand Down Expand Up @@ -257,11 +252,6 @@ public function testFrontendProps()
'configuratorId' => 'defaultConfigurator',
'htmlId' => 'roomle-12345678-90ab-cdef-1234-567890abcdef',
'options' => [
'deeplink' => (
'https://example.com/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'some' => 'default',
'other' => 'default',
'id' => 'some:product',
Expand Down Expand Up @@ -403,11 +393,6 @@ public function testOptions_Defaults()
]);

$this->assertSame([
'deeplink' => (
'https://example.com/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'some' => 'default',
'other' => 'default',
'id' => 'some:product',
Expand Down Expand Up @@ -441,11 +426,6 @@ public function testOptions_Locale1()
]);

$this->assertSame([
'deeplink' => (
'https://example.com/de/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'locale' => 'de',
'some' => 'default',
'other' => 'default',
Expand Down Expand Up @@ -480,11 +460,6 @@ public function testOptions_Locale2()
]);

$this->assertSame([
'deeplink' => (
'https://example.com/de-at/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'locale' => 'de',
'overrideCountry' => 'at',
'some' => 'default',
Expand Down Expand Up @@ -535,11 +510,6 @@ public function testOptions_NoTarget()
]);

$this->assertSame([
'deeplink' => (
'https://example.com/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'buttons' => [
'requestproduct' => false
],
Expand Down Expand Up @@ -568,11 +538,6 @@ public function testOptions_Overrides()
]);

$this->assertSame([
'deeplink' => (
'https://example.com/test' .
'?roomle-12345678-90ab-cdef-1234-567890abcdef=#CONFIGURATIONID#' .
'#roomle-12345678-90ab-cdef-1234-567890abcdef'
),
'some' => 'custom value',
'other' => 'default',
'skin' => [
Expand Down

0 comments on commit 0cf022a

Please sign in to comment.