artesaos / seotools

SEO Tools for Laravel
MIT License
3.1k stars 505 forks source link

How to use JSONLD for Product #222

Closed kadnan closed 2 years ago

kadnan commented 4 years ago

I want to use parameters like SKU, 'Availability` etc. Currently it is generating like:

<script type="application/ld+json">{"@context":"https:\/\/schema.org","@type":"Product","name":"Maria B Lawn","description":"Get Maria B lawn Replica here"}</script>

While I want to generate like:

<script type="application/ld+json">{"@context":"https:\/\/schema.org","@graph":[{"@type":"Product","sku":"tees-11","name":"Buy Queen Pink Half Sleeves Printed T-Shirt - Nisaa.Pk - Pakistan's online shopping site for women","description":"Nationwide Free Delivery 100% High-Quality Genuine Product Delivery Time: 2 to 3 Working Days 7 Days Return &amp; Exchange Policy","releaseDate":"2020-08-18T13:13:51+00:00","category":"Summer Clothing > Women's Fashion > T-shirts","image":{"@type":"ImageObject","url":"http:\/\/www.nisaa.pk\/wp-content\/uploads\/2020\/08\/tees-11.jpg","width":800,"height":800},"offers":{"@type":"Offer","price":"695.00","priceValidUntil":"2021-12-31","priceCurrency":"PKR","availability":"http:\/\/schema.org\/InStock","seller":{"@type":"Organization","@id":"http:\/\/www.nisaa.pk\/","name":"Nisaa PK - Pakistan's online shopping site for women","url":"http:\/\/www.nisaa.pk","logo":false},"url":"http:\/\/www.nisaa.pk\/product\/queen-pink-half-sleeves-printed-t-shirt\/"}},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"http:\/\/www.nisaa.pk","name":"Home"}},{"@type":"ListItem","position":2,"item":{"@id":"http:\/\/www.nisaa.pk\/product-category\/womens-fashion\/summer-clothing\/t-shirts\/","name":"T-shirts"}},{"@type":"ListItem","position":3,"item":{"@id":"http:\/\/www.nisaa.pk\/product\/queen-pink-half-sleeves-printed-t-shirt\/","name":"Queen Pink Half Sleeves Printed T-Shirt"}}]}]}</script>

I could not find ways to generate similar LD Code.

StApostol commented 3 years ago

@kadnan You can use this method https://github.com/artesaos/seotools/blob/master/src/SEOTools/JsonLd.php#L155

$someJsonLd = new JsonLd();
$someJsonLd->addValue('SKU', 'tees-11');