From 4de61fce87f46929afbfadb80a838cef22a34eda Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 15 Dec 2017 16:31:57 +0000 Subject: [PATCH 1/5] changed default name for conditional --- blueprints/seo.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 0c7a00f..7822cbd 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: From 15e9bd64d7609a9bf0f49edb4d8c1352515952af Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 15 Dec 2017 17:19:51 +0000 Subject: [PATCH 2/5] added blueprints for product --- blueprints/seo.yaml | 80 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 7822cbd..0fd3e0f 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -550,6 +550,86 @@ 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.brand: + type: text + label: Product Brand + header.product.brandlogo: + type: mediapicker + label: Logo of the brand + header.product.image: + type: list + label: Add an image for this product + 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 + 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 + type: text + .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'" From 996916f69115386c05f4ff92f4ffa987941ea57d Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 15 Dec 2017 17:51:43 +0000 Subject: [PATCH 3/5] added php draft for product --- blueprints/seo.yaml | 1 + seo.php | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 0fd3e0f..87dfb68 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -584,6 +584,7 @@ form: 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 diff --git a/seo.php b/seo.php index 06e5f31..83dab71 100644 --- a/seo.php +++ b/seo.php @@ -438,6 +438,39 @@ 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){ + $productimagearray[] = $this->grav['uri']->base() . array_shift($productimages[$key]) ; + }; + + + } + $microdata[] = [ + '@context' => 'http://schema.org', + '@type' => 'Product', + 'name' => @$page->header()->product['name'], + + 'address' => [ + '@type' => 'PostalAddress', + 'addressLocality' => @$page->header()->restaurant['address_addressLocality'], + 'addressRegion' => @$page->header()->restaurant['address_addressRegion'], + 'streetAddress' => @$page->header()->restaurant['address_streetAddress'], + 'postalCode' => @$page->header()->restaurant['address_postalCode'], + ], + 'servesCuisine' => @$page->header()->restaurant['servesCuisine'], + 'category' => @$page->header()->product['category'], + 'brand' => @$page->header()->product['brand'], + 'description' => @$page->header()->product['description'], + 'image' => @$productimagearray + ]; + + } } if (property_exists($page->header(),'articleenabled')){ From c2adc6dc158aecb53b2144e3fb186694620110d2 Mon Sep 17 00:00:00 2001 From: Paul Date: Sat, 16 Dec 2017 17:32:02 +0000 Subject: [PATCH 4/5] added image loop --- blueprints.yaml | 10 ++++++++++ seo.php | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) 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/seo.php b/seo.php index 83dab71..6354c2f 100644 --- a/seo.php +++ b/seo.php @@ -445,8 +445,17 @@ public function onPageInitialized() if (isset($page->header()->product['image'])){ $productimagearray = []; $productimages = $page->header()->product['image']; + + foreach ($productimages as $key => $value){ - $productimagearray[] = $this->grav['uri']->base() . array_shift($productimages[$key]) ; + $imagearray = $productimages[$key]; + foreach($imagearray as $newkey => $newvalue){ + $imagedata = $this->seoGetimage($imagearray[$newkey]); + $productimage[] = + $this->grav['uri']->base() . $imagedata['url']; + + }; + }; @@ -467,7 +476,7 @@ public function onPageInitialized() 'category' => @$page->header()->product['category'], 'brand' => @$page->header()->product['brand'], 'description' => @$page->header()->product['description'], - 'image' => @$productimagearray + 'image' => @$productimage ]; From 9f40aba41b8668275f1c3476f478ad2b8063060b Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 17 Dec 2017 11:13:33 +0000 Subject: [PATCH 5/5] product microdata ok --- blueprints/seo.yaml | 20 ++++++++++++++++++-- seo.php | 34 +++++++++++++++++++++++----------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/blueprints/seo.yaml b/blueprints/seo.yaml index 87dfb68..c085c66 100644 --- a/blueprints/seo.yaml +++ b/blueprints/seo.yaml @@ -578,6 +578,17 @@ form: 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 @@ -588,6 +599,7 @@ form: header.product.image: type: list label: Add an image for this product + style: vertical btnLabel: Add image fields: .productimg: @@ -602,6 +614,7 @@ form: label: Add an offer for this product btnLabel: Add offer controls: both + style: vertical fields: .offer_availability: type: select @@ -620,8 +633,11 @@ form: placeholder: "e.g: 19.99 (no currency symbol)" .offer_validFrom: type: datetime - label: Offer is valid from - type: text + 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 diff --git a/seo.php b/seo.php index 6354c2f..8fba885 100644 --- a/seo.php +++ b/seo.php @@ -457,6 +457,17 @@ public function onPageInitialized() }; }; + $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'], + ]; + }; } @@ -464,19 +475,20 @@ public function onPageInitialized() '@context' => 'http://schema.org', '@type' => 'Product', 'name' => @$page->header()->product['name'], - - 'address' => [ - '@type' => 'PostalAddress', - 'addressLocality' => @$page->header()->restaurant['address_addressLocality'], - 'addressRegion' => @$page->header()->restaurant['address_addressRegion'], - 'streetAddress' => @$page->header()->restaurant['address_streetAddress'], - 'postalCode' => @$page->header()->restaurant['address_postalCode'], - ], - 'servesCuisine' => @$page->header()->restaurant['servesCuisine'], 'category' => @$page->header()->product['category'], - 'brand' => @$page->header()->product['brand'], + 'brand' => [ + '@type' => 'Thing', + 'name' => @$page->header()->product['brand'], + ], + 'offers' => $offer, 'description' => @$page->header()->product['description'], - 'image' => @$productimage + 'image' => @$productimage, + 'aggregateRating' => [ + '@type' => 'AggregateRating', + 'ratingValue' => @$page->header()->product['ratingValue'], + 'reviewCount' => @$page->header()->product['reviewCount'], + + ] ];