Skip to content

Commit

Permalink
Merge pull request #35 from paulmassen/json_producto
Browse files Browse the repository at this point in the history
Json product
  • Loading branch information
paulmassen authored Dec 17, 2017
2 parents d8b11ee + 9f40aba commit 167b450
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 1 deletion.
10 changes: 10 additions & 0 deletions blueprints.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
99 changes: 98 additions & 1 deletion blueprints/seo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ form:



header.conditional_new_entries:
header.conditional_event:
type: conditional
condition: "config.plugins.seo.event ? 'true' : 'false'"
fields:
Expand Down Expand Up @@ -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'"
Expand Down
54 changes: 54 additions & 0 deletions seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')){
Expand Down

0 comments on commit 167b450

Please sign in to comment.