Advertisement
Shoporama

JSON+LD til produkter

Nov 18th, 2020
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <{assign var="reviews" value=$product->getProductReviews()}>
  2. <{if $reviews}>
  3.    
  4.     <{assign var="antalreviews" value=0}>
  5.     <{assign var="reeltantalreviews" value=0}>
  6.     <{assign var="totalscore" value=0}>
  7.     <{section name="p" loop=$reviews}>
  8.         <{math assign="antalreviews" equation=x+1 x=$antalreviews}>
  9.         <{math assign="reeltantalreviews" equation=x+1 x=$reeltantalreviews}>
  10.         <{math assign="totalscore" equation=x+y x=$totalscore y=$reviews[p]->getRating()}>
  11.     <{/section}>
  12.    
  13.    
  14.     <{if $product->getSimilarProducts()}>
  15.         <{* Henter anmeldelser fra søskendeprodukter *}>
  16.         <{assign var="soskende" value=$product->getSimilarProducts()}>
  17.         <{if $soskende}>
  18.            
  19.             <{section name="q" loop=$soskende}>
  20.                
  21.                
  22.                 <{assign var="tempreviews" value=$soskende[q]->getProductReviews()}>
  23.                 <{if $tempreviews}>
  24.                     <{section name="w" loop=$tempreviews}>
  25.                         <{assign var="thisreview" value=$tempreviews[w]->getRating()}>
  26.                         <{math assign="antalreviews" equation=x+1 x=$antalreviews}>
  27.                         <{math assign="totalscore" equation=x+y x=$totalscore y=$thisreview}>
  28.                        
  29.                     <{/section}>
  30.                 <{/if}>
  31.                
  32.             <{/section}>
  33.         <{/if}>
  34.     <{/if}>
  35.    
  36.     <{math assign="gennemsnit" equation=x/y x=$totalscore y=$antalreviews}>
  37.    
  38. <{/if}>
  39.  
  40.  
  41.  
  42.  
  43. <{assign var="tempdato" value=$smarty.now}>
  44. <{math assign="nextyear" equation=x+1 x=$tempdato|date_format:"%Y"}>       
  45. <script type="application/ld+json">
  46. {
  47.   "@context": "http://schema.org/",
  48.   "@type": "Product",
  49.   <{if $reviews}>
  50.   "aggregateRating": {
  51.     "@type": "AggregateRating",
  52.     "ratingValue": "<{$gennemsnit|number_format:2:",":"."}>",
  53.     "reviewCount": "<{$antalreviews}>"
  54.   },
  55.   <{/if}>
  56.   "name": "<{$product->getName()}>",
  57.   "url": "<{$product->getRemoteUrl()}>",
  58.   <{if $product->getGtin()}>
  59.       "gtin8": "<{$product->getGtin()}>",  
  60.   <{/if}>
  61.   <{if $images}>
  62.     <{section name="j" loop=$images start=0 max=1}>
  63.         "image": "<{$webshop->getUrl()}><{$images[j]->getSrc(400 , 400, 'box')}>",
  64.     <{/section}>
  65.   <{/if}>
  66.   "description": "<{$product->getParsedDescription()|strip_tags:true|replace:'"':'\''}>",
  67.  "sku": "<{$product->getOwnId()}>",
  68.  "brand": {
  69.    "@type": "Thing"
  70.    <{if $supplier}>
  71.        , "name": "<{$supplier->getName()}>"
  72.    <{/if}>
  73.  },
  74.  "offers": {
  75.    "@type": "Offer",
  76.    "priceCurrency": "<{$webshop->getCurrency()}>",
  77.    "price": "<{$product->getRealPrice(1)|number_format:2:".":""}>",
  78.    "itemCondition": "NewCondition",
  79.    "priceValidUntil": "<{$nextyear}>-<{$tempdato|date_format:"%m"}>-<{$tempdato|date_format:"%d"}>",
  80.    "url": "<{$product->getRemoteUrl()}>",
  81.    <{if $product->getIsInStock() || $product->getAllowNegativeStock()}>
  82.        "availability": "InStock"
  83.    <{else}>
  84.        "availability": "OutOfStock"
  85.    <{/if}>
  86.  }<{if $reviews}>,
  87.  
  88.  
  89.  
  90.     "review": [
  91.     <{assign var="tempcounter" value=0}>
  92.     <{section name="p" loop=$reviews}>
  93.         <{math assign="tempcounter" equation=x+1 x=$tempcounter}>
  94.         <{assign var="order" value=$reviews[p]->getOrder()}>       
  95.             {
  96.              "@type": "Review",
  97.              "author": "<{$order->getDelName()}>",
  98.              "datePublished": "<{$reviews[p]->getCreated()|escape|truncate:10:""}>",
  99.              "name": "Anmeldelse af <{$product->getName()}>",
  100.              "reviewBody": "<{$reviews[p]->getDescription()|escape}>",
  101.              "reviewRating": {
  102.                 "@type": "Rating",
  103.                 "bestRating": "5",
  104.                 "ratingValue": "<{$reviews[p]->getRating()}>",
  105.                 "worstRating": "1"
  106.               }
  107.            
  108.            }<{if $reeltantalreviews>$tempcounter}>,<{/if}>
  109.     <{/section}>
  110.     ]
  111.  <{/if}>
  112.    
  113.  
  114. }
  115. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement