Vinoteca: модуль, шаблон и компоненты интернет-магазина вина на 1С-Битрикс
This commit is contained in:
commit
bb7d8af290
469 files changed
+26426
No files matched your search
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Jinove\Vinoteca;
|
||||
|
||||
use Bitrix\Main\Type\DateTime;
|
||||
|
||||
final class OfferSchema
|
||||
{
|
||||
private const CONTEXT = "https://schema.org";
|
||||
|
||||
public static function list(array $items, string $path, string $name, string $description): array
|
||||
{
|
||||
$url = Config::host() . $path;
|
||||
$list = [];
|
||||
foreach (array_values($items) as $index => $item) {
|
||||
$list[] = ["@type" => "ListItem", "position" => $index + 1, "url" => $item["url"], "name" => $item["name"]];
|
||||
}
|
||||
|
||||
return [
|
||||
"@context" => self::CONTEXT,
|
||||
"@graph" => [
|
||||
[
|
||||
"@type" => "CollectionPage",
|
||||
"@id" => $url . "#webpage",
|
||||
"url" => $url,
|
||||
"name" => $name,
|
||||
"description" => $description,
|
||||
"inLanguage" => LANGUAGE_ID,
|
||||
"about" => ["@id" => Config::host() . "/#store"],
|
||||
"mainEntity" => ["@id" => $url . "#offers"],
|
||||
"workTranslation" => PageSchema::translations($path, "CollectionPage"),
|
||||
],
|
||||
[
|
||||
"@type" => "ItemList",
|
||||
"@id" => $url . "#offers",
|
||||
"url" => $url,
|
||||
"numberOfItems" => count($list),
|
||||
"itemListElement" => $list,
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function detail(array $offer): array
|
||||
{
|
||||
$url = Config::host() . $offer["path"];
|
||||
$store = ["@id" => Config::host() . "/#store"];
|
||||
$event = [
|
||||
"@type" => "SaleEvent",
|
||||
"@id" => $url . "#event",
|
||||
"url" => $url,
|
||||
"name" => $offer["name"],
|
||||
"description" => $offer["description"],
|
||||
"inLanguage" => LANGUAGE_ID,
|
||||
"eventStatus" => "https://schema.org/EventScheduled",
|
||||
"eventAttendanceMode" => "https://schema.org/MixedEventAttendanceMode",
|
||||
"location" => $store,
|
||||
"organizer" => $store,
|
||||
];
|
||||
foreach (["startDate" => "start", "endDate" => "end"] as $property => $key) {
|
||||
if ($offer[$key] !== "") {
|
||||
$event[$property] = $offer[$key];
|
||||
}
|
||||
}
|
||||
$page = [
|
||||
"@type" => "WebPage",
|
||||
"@id" => $url . "#webpage",
|
||||
"url" => $url,
|
||||
"name" => $offer["name"],
|
||||
"description" => $offer["description"],
|
||||
"inLanguage" => LANGUAGE_ID,
|
||||
"mainEntity" => ["@id" => $url . "#event"],
|
||||
"workTranslation" => PageSchema::translations($offer["path"], "WebPage"),
|
||||
];
|
||||
if ($offer["image"]) {
|
||||
$event["image"] = PageSchema::image($url . "#image", $offer["image"]["url"], $offer["image"]["width"], $offer["image"]["height"]);
|
||||
$page["primaryImageOfPage"] = ["@id" => $url . "#image"];
|
||||
}
|
||||
|
||||
return ["@context" => self::CONTEXT, "@graph" => [$page, $event]];
|
||||
}
|
||||
|
||||
public static function date(string $value): string
|
||||
{
|
||||
return $value !== "" ? date(DATE_ATOM, DateTime::createFromUserTime($value)->getTimestamp()) : "";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user