Skip to content

Commit

Permalink
Merge pull request #2 from Pixel-Open/cdigruttola-feature/microdata
Browse files Browse the repository at this point in the history
1.0.4
  • Loading branch information
magentix authored May 12, 2023
2 parents 533b129 + 159c4e8 commit e41470c
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 14 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.0.4

- Microdata added to template (@cdigruttola)
- Phone and price level added to place (@cdigruttola)
- Author URL added to review (@cdigruttola)

## 1.0.3

- Custom widget template
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,13 @@ It is only possible to retrieve the last 5 reviews. Import often to accumulate t
In any template, add the following Widget:

```smarty
{widget name='pixel_googlemybusiness' display='name,rating,opening-hours,reviews'}
{widget name='pixel_googlemybusiness' display='name,phone,rating,opening-hours,reviews'}
```

**Display excepted options:**

* name: Place name (Eiffel tower)
* phone: International phone number (+33 1 22 33 44 55)
* rating: Average Rating (4/5)
* opening-hours: Opening hours (Monday: 12:00 – 19:00, Tuesday: 10:00 – 19:00...)
* review: the last reviews
Expand Down
7 changes: 5 additions & 2 deletions pixel_googlemybusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Pixel_googlemybusiness extends Module implements WidgetInterface
public function __construct()
{
$this->name = 'pixel_googlemybusiness';
$this->version = '1.0.3';
$this->version = '1.0.4';
$this->author = 'Pixel Open';
$this->tab = 'front_office_features';
$this->need_instance = 0;
Expand Down Expand Up @@ -102,7 +102,7 @@ public function getWidgetVariables($hookName, array $configuration): array
explode(',', $configuration['place_ids'] ?? '')
);
$display = array_filter(
explode(',', $configuration['display'] ?? 'name,rating,opening-hours,reviews')
explode(',', $configuration['display'] ?? 'name,phone,rating,opening-hours,reviews')
);
$reviewNumber = $configuration['review_number'] ?? 5;
$reviewMinRating = $configuration['review_min_rating'] ?? 0;
Expand Down Expand Up @@ -282,10 +282,12 @@ protected function createTables(): bool
`place_id` VARCHAR(255) NOT NULL,
`language` VARCHAR(2) NULL,
`name` VARCHAR(255) NOT NULL,
`phone` VARCHAR(255) DEFAULT NULL,
`opening_hours_periods` TEXT DEFAULT NULL,
`opening_hours_weekday_text` TEXT DEFAULT NULL,
`rating` NUMERIC(4, 2) DEFAULT NULL,
`user_ratings_total` INT DEFAULT NULL,
`price_level` INT DEFAULT NULL,
PRIMARY KEY(`id`),
UNIQUE KEY(`place_id`, `language`)
) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8;
Expand All @@ -294,6 +296,7 @@ protected function createTables(): bool
`id` INT(11) AUTO_INCREMENT NOT NULL,
`place_id` VARCHAR(255) NOT NULL,
`author_name` VARCHAR(255) DEFAULT NULL,
`author_url` VARCHAR(255) DEFAULT NULL,
`language` VARCHAR(2) NULL,
`original_language` VARCHAR(2) DEFAULT NULL,
`profile_photo_url` VARCHAR(255) DEFAULT NULL,
Expand Down
30 changes: 21 additions & 9 deletions pixel_googlemybusiness.tpl
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<div class="google-places">
{foreach from=$places item=place}
<div class="place">
<div class="place" itemscope itemtype="https://schema.org/Place">
{if 'name'|in_array:$display}
<div class="name">{$place->getName()}</div>
<div class="name" itemprop="name">{$place->getName()}</div>
{/if}
{if 'phone'|in_array:$display and $place->getPhone()}
<div class="phone"><a href="tel:{$place->getPhone()}"><span itemprop="telephone">{$place->getPhone()}</span></a></div>
{/if}
{if 'rating'|in_array:$display}
<div class="rating">
<div class="rating" itemprop="aggregateRating" itemscope itemtype="https://schema.org/AggregateRating">
{if $place->getUserRatingsTotal()}
<meta itemprop="ratingValue" content="{$place->getRating()}" />
<meta itemprop="reviewCount" content="{$place->getUserRatingsTotal()}" />
{l s='Note:' d='Modules.Pixelgooglemybusiness.Shop'} <strong>{$place->getRating()}/5</strong> ({$place->getUserRatingsTotal()} {l s='reviews' d='Modules.Pixelgooglemybusiness.Shop'})
{else}
<a href="https://www.google.com/maps/search/?api=1&query=Google&query_place_id={$place->getPlaceId()}" target="_blank" rel="noopener noreferrer">
Expand All @@ -18,19 +23,26 @@
{if 'opening-hours'|in_array:$display}
<ul class="opening-hours">
{foreach from=$place->getOpeningHoursWeekdayText()|json_decode:1 item=hour}
<li>{$hour}</li>
<li itemprop="openingHours">{$hour}</li>
{/foreach}
</ul>
{/if}
{if 'reviews'|in_array:$display}
<div class="reviews">
{foreach from=$place->getReviews() item=review}
<div class="review">
<span class="author">{$review->getAuthorName()}</span>
<span class="date">{$review->getTime()|date_format:"%e %B %Y"}</span>
<span class="note">{$review->getRating()}/5</span>
<div class="review" itemprop="review" itemscope itemtype="https://schema.org/Review">
<a href="{$review->getAuthorUrl()}" title="{$review->getAuthorName()}" rel="nofollow">
<span class="author" itemprop="author">{$review->getAuthorName()}</span>
</a>
<span class="date" itemprop="datePublished" content="{$review->getTime()|date_format:"%Y-%m-%d"}">{$review->getTime()|date_format:"%e %B %Y"}</span>
<span class="note" itemprop="reviewRating" itemscope itemtype="https://schema.org/Rating">
{$review->getRating()}/5
<meta itemprop="worstRating" content = "1" />
<meta itemprop="ratingValue" content="{$review->getRating()}" />
<meta itemprop="bestRating" content = "5" />
</span>
{if $review->getComment()}
<div class="comment">
<div class="comment" itemprop="reviewBody">
{$review->getComment()}
</div>
{/if}
Expand Down
7 changes: 5 additions & 2 deletions src/Command/ImportPlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

foreach ($placeIds as $placeId) {
$params = [
'fields' => 'name,rating,opening_hours,user_ratings_total,reviews',
'fields' => 'name,international_phone_number,rating,opening_hours,user_ratings_total,reviews,price_level',
'reviews_sort' => 'newest',
'key' => Configuration::get('GOOGLE_MY_BUSINESS_API_KEY'),
'placeid' => $placeId,
Expand Down Expand Up @@ -81,10 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
->setPlaceId($placeId)
->setLanguage($language)
->setName($result['name'])
->setPhone($result['international_phone_number'] ?? null)
->setOpeningHoursPeriods(json_encode($result['opening_hours']['periods'] ?? []))
->setOpeningHoursWeekdayText(json_encode($result['opening_hours']['weekday_text'] ?? []))
->setRating((float)($result['rating'] ?? 5))
->setUserRatingsTotal((int)($result['user_ratings_total'] ?? 0));
->setUserRatingsTotal((int)($result['user_ratings_total'] ?? 0))
->setPriceLevel((int)($result['price_level'] ?? 0));

$entityManager->persist($googlePlace);
$entityManager->flush();
Expand All @@ -107,6 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$googleReview
->setPlaceId($placeId)
->setAuthorName($review['author_name'])
->setAuthorUrl($review['author_url'] ?? '')
->setLanguage($review['language'] ?? null)
->setOriginalLanguage($review['original_language'] ?? null)
->setProfilePhotoUrl($review['profile_photo_url'])
Expand Down
58 changes: 58 additions & 0 deletions src/Entity/GooglePlace.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class GooglePlace
*/
private $name;

/**
* @var string
*
* @ORM\Column(name="phone", type="text", nullable=true)
*/
private $phone;

/**
* @var string
*
Expand Down Expand Up @@ -70,6 +77,13 @@ class GooglePlace
*/
private $userRatingsTotal;

/**
* @var int
*
* @ORM\Column(name="price_level", type="integer", nullable=true)
*/
private $priceLevel;

/**
* @var GoogleReview[]
*/
Expand Down Expand Up @@ -155,6 +169,26 @@ public function setName(string $name): GooglePlace
return $this;
}

/**
* @return string
*/
public function getPhone(): ?string
{
return $this->phone;
}

/**
* @param string $phone
*
* @return GooglePlace
*/
public function setPhone(?string $phone): GooglePlace
{
$this->phone = $phone;

return $this;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -235,6 +269,26 @@ public function setUserRatingsTotal(?int $userRatingsTotal): GooglePlace
return $this;
}

/**
* @return int|null
*/
public function getPriceLevel(): ?int
{
return $this->priceLevel;
}

/**
* @param int|null $priceLevel
*
* @return GooglePlace
*/
public function setPriceLevel(?int $priceLevel): GooglePlace
{
$this->priceLevel = $priceLevel;

return $this;
}

/**
* @return GoogleReview[]
*/
Expand Down Expand Up @@ -263,11 +317,15 @@ public function toArray(): array
return [
'id' => $this->getId(),
'place_id' => $this->getPlaceId(),
'name' => $this->getName(),
'phone' => $this->getPhone(),
'opening_hours_periods' => $this->getOpeningHoursPeriods(),
'opening_hours_weekday_text' => $this->getOpeningHoursWeekdayText(),
'rating' => $this->getRating(),
'user_ratings_total' => $this->getUserRatingsTotal(),
'reviews' => $this->getReviews(),
'price_level' => $this->getPriceLevel(),
'language' => $this->getLanguage(),
];
}
}
27 changes: 27 additions & 0 deletions src/Entity/GoogleReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class GoogleReview
* @ORM\Column(name="author_name", type="string", length=255, nullable=true)
*/
private $authorName;
/**
* @var string
*
* @ORM\Column(name="author_url", type="string", length=255, nullable=true)
*/
private $authorUrl;

/**
* @var string
Expand Down Expand Up @@ -157,6 +163,26 @@ public function setAuthorName(?string $authorName): GoogleReview
return $this;
}

/**
* @return string|null
*/
public function getAuthorUrl(): ?string
{
return $this->authorUrl;
}

/**
* @param string|null $authorUrl
*
* @return GoogleReview
*/
public function setAuthorUrl(?string $authorUrl): GoogleReview
{
$this->authorUrl = $authorUrl;

return $this;
}

/**
* @return string|null
*/
Expand Down Expand Up @@ -346,6 +372,7 @@ public function toArray(): array
'id' => $this->getId(),
'place_id' => $this->getPlaceId(),
'author_name' => $this->getAuthorName(),
'author_url' => $this->getAuthorUrl(),
'language' => $this->getLanguage(),
'original_language' => $this->getOriginalLanguage(),
'profile_photo_url' => $this->getProfilePhotoUrl(),
Expand Down
19 changes: 19 additions & 0 deletions upgrade/upgrade-1.0.4.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

if (!defined('_PS_VERSION_')) {
exit;
}

function upgrade_module_1_0_4($module)
{
return (bool)Db::getInstance()->execute('
ALTER TABLE `' . _DB_PREFIX_ . 'google_place`
ADD COLUMN `phone` VARCHAR(255) DEFAULT NULL;
ALTER TABLE `' . _DB_PREFIX_ . 'google_place`
ADD COLUMN `price_level` INT DEFAULT NULL;
ALTER TABLE `' . _DB_PREFIX_ . 'google_review`
ADD COLUMN `author_url` VARCHAR(255) DEFAULT NULL;
');
}
4 changes: 4 additions & 0 deletions views/css/gmb.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
font-size: 1.1rem;
}

.google-places .place .phone {
margin-bottom: 1rem;
}

.google-places .place .rating {
margin-bottom: 1rem;
}
Expand Down

0 comments on commit e41470c

Please sign in to comment.