diff --git a/blueprints.yaml b/blueprints.yaml index 0e9f76d..0267498 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -97,6 +97,16 @@ form: 0: PLUGIN_ADMIN.DISABLED validate: type: bool + product: + type: toggle + label: Enable Product Microdata + highlight: 1 + default: 1 + options: + 1: PLUGIN_ADMIN.ENABLED + 0: PLUGIN_ADMIN.DISABLED + validate: + type: bool facebookid: type: text label: Facebook App ID diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 0c7a00f..c085c66 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -363,7 +363,7 @@ form: - header.conditional_new_entries: + header.conditional_event: type: conditional condition: "config.plugins.seo.event ? 'true' : 'false'" fields: @@ -550,6 +550,103 @@ form: .duration: type: text label: PLUGIN_SEO.MUSICALBUM_TRACK_DURATION + header.product_condition: + type: conditional + condition: "config.plugins.seo.product ? 'true' : 'false'" + fields: + header.productfieldset: + type: fieldset + icon: shopping-bag + title: Product Microdata + collapsed: true + collapsible: true + fields: + header.productenabled: + type: toggle + highlight: 1 + label: Add Product Microdata to this page + default: 0 + options: + 1: PLUGIN_ADMIN.YES + 0: PLUGIN_ADMIN.NO + validate: + type: bool + header.product.name: + type: text + label: Name of the Product + field_classes: togglerestaurant + header.product.category: + type: text + label: Category of the product + header.product.ratingValue: + type: range + label: Star Rating + help: Choose a value between 0 and 5 which should be the average ratings for your product. Make sure the value is consistent with your actual reviews. + validate: + min: 0 + max: 5 + step: 0.1 + header.product.reviewCount: + type: number + label: Number of reviews you used for calculating your rating. + header.product.brand: + type: text + label: Product Brand + header.product.brandlogo: + type: mediapicker + label: Logo of the brand + placeholder: Please click to open the mediapicker + header.product.image: + type: list + label: Add an image for this product + style: vertical + btnLabel: Add image + fields: + .productimg: + type: mediapicker + label: Choose an image + placeholder: Please click to open the mediapicker + header.product.description: + type: textarea + label: Product Description + header.product.addoffer: + type: list + label: Add an offer for this product + btnLabel: Add offer + controls: both + style: vertical + fields: + .offer_availability: + type: select + options: + 'http://schema.org/PreOrder': PLUGIN_SEO.PREORDER + 'http://schema.org/OutOfStock': PLUGIN_SEO.OUTOFSTOCK + 'http://schema.org/PreSale': PLUGIN_SEO.PRESALE + 'http://schema.org/InStock': PLUGIN_SEO.INSTOCK + 'http://schema.org/Discontinued': PLUGIN_SEO.DISCONTINUED + 'http://schema.org/InStoreOnly': PLUGIN_SEO.INSTOREONLY + 'http://schema.org/SoldOut': PLUGIN_SEO.SOLDOUT + 'http://schema.org/OnlineOnly': PLUGIN_SEO.ONLINEONLY + .offer_price: + type: text + label: Price of the product + placeholder: "e.g: 19.99 (no currency symbol)" + .offer_validFrom: + type: datetime + label: Offer is valid from (optional) + .offer_validUntil: + type: datetime + label: Offer is valid until (optional) + + .offer_priceCurrency: + type: select + label: PLUGIN_SEO.PRICE_CURRENCY + options: + GBP: GBP + EUR: EUR + USD: USD + + header.restaurant_condition: type: conditional condition: "config.plugins.seo.restaurant ? 'true' : 'false'" diff --git a/seo.php b/seo.php index 06e5f31..8fba885 100644 --- a/seo.php +++ b/seo.php @@ -438,6 +438,60 @@ public function onPageInitialized() ]; + } + } + if (property_exists($page->header(),'productenabled')){ + if ($page->header()->productenabled and $this->config['plugins']['seo']['product']) { + if (isset($page->header()->product['image'])){ + $productimagearray = []; + $productimages = $page->header()->product['image']; + + + foreach ($productimages as $key => $value){ + $imagearray = $productimages[$key]; + foreach($imagearray as $newkey => $newvalue){ + $imagedata = $this->seoGetimage($imagearray[$newkey]); + $productimage[] = + $this->grav['uri']->base() . $imagedata['url']; + + }; + + }; + $offers = $page->header()->product['addoffer']; + foreach ($offers as $key => $value){ + $offer[$key] = [ + '@type' => 'Offer', + 'priceCurrency' => @$offers[$key]['offer_priceCurrency'], + 'price' => @$offers[$key]['offer_price'], + 'validFrom' => @$offers[$key]['offer_validFrom'], + 'priceValidUntil' => @$offers[$key]['offer_validUntil'], + 'availability' => @$offers[$key]['offer_availability'], + ]; + }; + + + } + $microdata[] = [ + '@context' => 'http://schema.org', + '@type' => 'Product', + 'name' => @$page->header()->product['name'], + 'category' => @$page->header()->product['category'], + 'brand' => [ + '@type' => 'Thing', + 'name' => @$page->header()->product['brand'], + ], + 'offers' => $offer, + 'description' => @$page->header()->product['description'], + 'image' => @$productimage, + 'aggregateRating' => [ + '@type' => 'AggregateRating', + 'ratingValue' => @$page->header()->product['ratingValue'], + 'reviewCount' => @$page->header()->product['reviewCount'], + + ] + ]; + + } } if (property_exists($page->header(),'articleenabled')){