Skip to content

Commit ce377a0

Browse files
committed
Add unlockPricing documentation.
1 parent cb5116d commit ce377a0

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

source/includes/_utilities.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,70 @@ Will return the following object:
168168
});
169169
})(window.DDC.APILoader);
170170
```
171+
172+
## API.utils.getUnlockedVehicles()
173+
The utility method `getUnlockedVehicles` returns an array of vehicle UUIDs where the vehicle's pricing has already been unlocked.
174+
175+
This can be useful when paired with the `unlockPricing` method. When `vehicle-data-updated-v1` triggers, a list of currently displayed vehicles is provided. You could gather the list of vehicles, skip the ones which are already unlocked, and then call your service for a smaller subset of vehicles which may need to be unlocked.
176+
177+
> Usage:
178+
179+
```javascript
180+
(async APILoader => {
181+
const API = await APILoader.create(document.currentScript);
182+
API.subscribe('vehicle-data-updated-v1', data => {
183+
const unlockedUuids = await API.utils.getUnlockedVehicles();
184+
});
185+
})(window.DDC.APILoader);
186+
```
187+
188+
> Another example:
189+
190+
```javascript
191+
(async APILoader => {
192+
const API = await APILoader.create(document.currentScript);
193+
API.subscribe('vehicle-data-updated-v1', data => {
194+
// Get the list of unlocked vehicles
195+
const unlockedUuids = await API.utils.getUnlockedVehicles();
196+
197+
// Get the list of all vehicles
198+
const uuids = API.utils.getAttributeForVehicles('uuid');
199+
200+
// Filter the unlocked UUIDs from the UUIDs.
201+
const finalUuids = uuids.filter((el) => !unlockedUuids.includes(el));
202+
203+
// Call your service with the list of finalUuids here, to reduce network overhead.
204+
// Note: `callToYourService` is just an example here and not an implemented function in the API.
205+
const uuidsToUnlock = await callToYourService(finalUuids);
206+
207+
// Unlock vehicles which are not already unlocked, and your service indicates should be unlocked.
208+
API.utils.unlockPricing(uuidsToUnlock);
209+
210+
});
211+
})(window.DDC.APILoader);
212+
```
213+
214+
## API.utils.unlockPricing(uuids)
215+
The utility method `unlockPricing` is used to unlock special pricing for specific vehicles on a page.
216+
217+
You can provide the vehicles to unlock by passing an array of vehicle UUIDs to the method. If you would like to unlock all vehicles on the page, omit the `uuids` parameter from the function call.
218+
219+
The method must be called on each page where you want the vehicles to be unlocked. If a vehicle has been previously unlocked, it will be initially displayed unlocked on a subsequent view of the vehicle. However, when faceting and searching vehicles it is common for a mix of locked and unlocked vehicles to be rendered. Therefore, it is necessary to call the function each time the `vehicle-data-updated-v1` event is triggered.
220+
221+
> Usage:
222+
223+
```javascript
224+
(async APILoader => {
225+
const API = await APILoader.create(document.currentScript);
226+
API.subscribe('vehicle-data-updated-v1', data => {
227+
// You could call a service here to determine the list of vehicles to unlock based on the set
228+
// of vehicles presented on the current view, then construct the array of uuids accordingly.
229+
const uuids = [
230+
'f4b436e10a0e09a844d99ec8c92cf29c',
231+
'1db75afc0a0e09713efa52d69381e2f1',
232+
'808bb6a00a0e09716fa39a4a8b079353'
233+
];
234+
API.utils.unlockPricing(uuids);
235+
});
236+
})(window.DDC.APILoader);
237+
```

0 commit comments

Comments
 (0)