Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgetbay, calculate iframe height from /api/widgetbox-count-availabl… #95

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/shortcode-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
'text' => 'Questo contenuto è ospitato su una piattaforma esterna. Per visualizzarlo, è necessario <a href="javascript:void(0)" class="iubenda-cs-preferences-link">accettare i cookie</a>',
],
'widgetbay' => [
'endpoint' => 'https://widgetbay.3labs.it/widgetbox',
'endpoint' => 'https://widgetbay.3labs.it',
],

'linksToParse' => [
Expand Down
16 changes: 13 additions & 3 deletions src/Shortcodes/WidgetbayShortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class WidgetbayShortcode
{
public function register($shortcode)
{
$endpoint = config('shortcode-plus.widgetbay.endpoint');
$endpoint = config('shortcode-plus.widgetbay.endpoint').'/widgetbox';

$widgetbayLink = '';
$heightListClass = null;
Expand Down Expand Up @@ -41,8 +41,13 @@ public function register($shortcode)

protected function calculateIframeHeight($products, $layout = null)
{
$products = explode(',', $products);
$count = count($products);
$endpoint = config('shortcode-plus.widgetbay.endpoint').'/api/widgetbox-count-available-products?link='.$products;

//create HTTP request
$request = new \GuzzleHttp\Client;
$response = $request->get($endpoint);
$count = json_decode($response->getBody()->getContents(), true);

$prefix = $layout === 'hero' ? 'shortcode_widgetbay_list_hero_' : 'shortcode_widgetbay_list_';

if ($count > 1) {
Expand All @@ -51,4 +56,9 @@ protected function calculateIframeHeight($products, $layout = null)

return null;
}

protected function checkIfProductIsAvailable($product)
{
return $product->isAvailable();
}
}