Skip to content

Instantly share code, notes, and snippets.

@cesarockstar1985
Last active February 20, 2023 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cesarockstar1985/0c08dd23d60015f2c4e853d081ebe3ab to your computer and use it in GitHub Desktop.
Save cesarockstar1985/0c08dd23d60015f2c4e853d081ebe3ab to your computer and use it in GitHub Desktop.
<?php
/**
* @var \App\View\AppView $this
*/
if (isset($cmsPage) && !empty($cmsPage->jsonld)) {
$ldJson = json_decode($cmsPage->jsonld, true);
} elseif (!empty($bondType)) {
$ldJson = [
"@context" => "https://schema.org/",
"@type" => "Product",
"name" => $bondType->slug,
"description" => $bondType->display_name_state . ($bondType->description ? ': ' . $bondType->description : ''),
"brand" => [
"@type" => "Thing",
"name" => "Surety Bond"
],
"review"=> [
"@type"=> "Review",
"reviewRating"=> [
"@type"=> "Rating",
"ratingValue"=> "4",
"bestRating"=> "5"
],
"author"=> [
"@type"=> "Person",
"name"=> "Fred Benson"
]
],
"aggregateRating" => [
"@type"=> "AggregateRating",
"ratingValue"=> "4.4",
"reviewCount"=> "89"
],
"offers"=> [
"@type" => "Offer",
"url" => "https=>//example.com/anvil",
"priceCurrency" => "USD",
"price" => "119.99",
"priceValidUntil" => "2020-11-20",
"itemCondition" => "https://schema.org/UsedCondition",
"availability" => "https://schema.org/InStock"
]
];
if ($bondType->instant) {
$ldJson["offers"] = [
"@type" => "AggregateOffer",
"lowPrice" => \CakeDC\Accounting\Utility\MoneyUtil::float($bondType->low_price),
"highPrice" => \CakeDC\Accounting\Utility\MoneyUtil::float($bondType->high_price),
"priceCurrency" => "USD"
];
}
}
?>
<?php if (!empty($ldJson)) : ?>
<?= $this->Html->scriptBlock(json_encode($ldJson), ['type' => 'application/ld+json']) ?>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment