From 15ef5d47138f6abf69ffa569081c244632c69c96 Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Fri, 28 Apr 2023 18:35:47 +0200 Subject: [PATCH 1/7] adding microdata and author url in review --- pixel_googlemybusiness.php | 1 + pixel_googlemybusiness.tpl | 25 ++++++++++++++++--------- src/Command/ImportPlace.php | 1 + src/Entity/GoogleReview.php | 27 +++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index ca19c64..b64f529 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -294,6 +294,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, diff --git a/pixel_googlemybusiness.tpl b/pixel_googlemybusiness.tpl index daaea23..9fae6a3 100644 --- a/pixel_googlemybusiness.tpl +++ b/pixel_googlemybusiness.tpl @@ -1,12 +1,14 @@
{foreach from=$places item=place} -
+
{if 'name'|in_array:$display} -
{$place->getName()}
+
{$place->getName()}
{/if} {if 'rating'|in_array:$display} -
+
{if $place->getUserRatingsTotal()} + + {l s='Note:' d='Modules.Pixelgooglemybusiness.Shop'} {$place->getRating()}/5 ({$place->getUserRatingsTotal()} {l s='reviews' d='Modules.Pixelgooglemybusiness.Shop'}) {else} @@ -18,19 +20,24 @@ {if 'opening-hours'|in_array:$display}
    {foreach from=$place->getOpeningHoursWeekdayText()|json_decode:1 item=hour} -
  • {$hour}
  • +
  • {$hour}
  • {/foreach}
{/if} {if 'reviews'|in_array:$display}
{foreach from=$place->getReviews() item=review} -
- {$review->getAuthorName()} - {$review->getTime()|date_format:"%e %B %Y"} - {$review->getRating()}/5 +
+ + + + {$review->getRating()}/5 + + + + {if $review->getComment()} -
+
{$review->getComment()}
{/if} diff --git a/src/Command/ImportPlace.php b/src/Command/ImportPlace.php index d1ad2f2..2bcd06d 100644 --- a/src/Command/ImportPlace.php +++ b/src/Command/ImportPlace.php @@ -107,6 +107,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']) diff --git a/src/Entity/GoogleReview.php b/src/Entity/GoogleReview.php index d008434..c99b9d9 100644 --- a/src/Entity/GoogleReview.php +++ b/src/Entity/GoogleReview.php @@ -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 @@ -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 */ @@ -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(), From 463370d50ecd37dd73e07eb6ec9493a82e5efe05 Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Tue, 2 May 2023 15:26:17 +0200 Subject: [PATCH 2/7] add data for microdata --- pixel_googlemybusiness.php | 2 ++ pixel_googlemybusiness.tpl | 3 +++ src/Command/ImportPlace.php | 4 ++- src/Entity/GooglePlace.php | 54 +++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index b64f529..fff010a 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -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) NOT 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_evel` INT DEFAULT NULL, PRIMARY KEY(`id`), UNIQUE KEY(`place_id`, `language`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8; diff --git a/pixel_googlemybusiness.tpl b/pixel_googlemybusiness.tpl index 9fae6a3..bd711c6 100644 --- a/pixel_googlemybusiness.tpl +++ b/pixel_googlemybusiness.tpl @@ -3,6 +3,9 @@
{if 'name'|in_array:$display}
{$place->getName()}
+ {/if} {if 'rating'|in_array:$display}
diff --git a/src/Command/ImportPlace.php b/src/Command/ImportPlace.php index 2bcd06d..f82f4a8 100644 --- a/src/Command/ImportPlace.php +++ b/src/Command/ImportPlace.php @@ -81,10 +81,12 @@ protected function execute(InputInterface $input, OutputInterface $output) ->setPlaceId($placeId) ->setLanguage($language) ->setName($result['name']) + ->setPhone($result['international_phone_number']) ->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(); diff --git a/src/Entity/GooglePlace.php b/src/Entity/GooglePlace.php index e1f3a31..3d2ffbf 100644 --- a/src/Entity/GooglePlace.php +++ b/src/Entity/GooglePlace.php @@ -42,6 +42,13 @@ class GooglePlace */ private $name; + /** + * @var string + * + * @ORM\Column(name="phone", type="text", nullable=true) + */ + private $phone; + /** * @var string * @@ -70,6 +77,13 @@ class GooglePlace */ private $userRatingsTotal; + /** + * @var int + * + * @ORM\Column(name="price_level", type="integer", nullable=true) + */ + private $priceLevel; + /** * @var GoogleReview[] */ @@ -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 */ @@ -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[] */ From e58599b2aed920a449d335ef4a908fc20827ef0c Mon Sep 17 00:00:00 2001 From: Carmine Di Gruttola Date: Tue, 2 May 2023 15:28:07 +0200 Subject: [PATCH 3/7] change column name --- pixel_googlemybusiness.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index fff010a..7334158 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -287,7 +287,7 @@ protected function createTables(): bool `opening_hours_weekday_text` TEXT DEFAULT NULL, `rating` NUMERIC(4, 2) DEFAULT NULL, `user_ratings_total` INT DEFAULT NULL, - `price_evel` INT DEFAULT NULL, + `price_level` INT DEFAULT NULL, PRIMARY KEY(`id`), UNIQUE KEY(`place_id`, `language`) ) ENGINE=' . _MYSQL_ENGINE_ . ' DEFAULT CHARSET=UTF8; From 1268e556ac4ba5fec665350f9411979ba00d5845 Mon Sep 17 00:00:00 2001 From: magentix Date: Fri, 12 May 2023 23:52:44 +0200 Subject: [PATCH 4/7] Fix missing phone and price level in response --- src/Command/ImportPlace.php | 6 +++--- src/Entity/GooglePlace.php | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Command/ImportPlace.php b/src/Command/ImportPlace.php index f82f4a8..ee395dc 100644 --- a/src/Command/ImportPlace.php +++ b/src/Command/ImportPlace.php @@ -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, @@ -81,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ->setPlaceId($placeId) ->setLanguage($language) ->setName($result['name']) - ->setPhone($result['international_phone_number']) + ->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)) @@ -109,7 +109,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $googleReview ->setPlaceId($placeId) ->setAuthorName($review['author_name']) - ->setAuthorUrl($review['author_url']) + ->setAuthorUrl($review['author_url'] ?? '') ->setLanguage($review['language'] ?? null) ->setOriginalLanguage($review['original_language'] ?? null) ->setProfilePhotoUrl($review['profile_photo_url']) diff --git a/src/Entity/GooglePlace.php b/src/Entity/GooglePlace.php index 3d2ffbf..0dbc216 100644 --- a/src/Entity/GooglePlace.php +++ b/src/Entity/GooglePlace.php @@ -172,7 +172,7 @@ public function setName(string $name): GooglePlace /** * @return string */ - public function getPhone(): string + public function getPhone(): ?string { return $this->phone; } @@ -182,7 +182,7 @@ public function getPhone(): string * * @return GooglePlace */ - public function setPhone(string $phone): GooglePlace + public function setPhone(?string $phone): GooglePlace { $this->phone = $phone; @@ -317,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(), ]; } } From 42d3ec4f217f337f8e50e440929c0ee40fa4a8d0 Mon Sep 17 00:00:00 2001 From: magentix Date: Fri, 12 May 2023 23:53:49 +0200 Subject: [PATCH 5/7] Phone as optional option --- pixel_googlemybusiness.php | 6 +++--- pixel_googlemybusiness.tpl | 20 +++++++++++--------- views/css/gmb.css | 4 ++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/pixel_googlemybusiness.php b/pixel_googlemybusiness.php index 7334158..03405bf 100644 --- a/pixel_googlemybusiness.php +++ b/pixel_googlemybusiness.php @@ -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; @@ -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; @@ -282,7 +282,7 @@ protected function createTables(): bool `place_id` VARCHAR(255) NOT NULL, `language` VARCHAR(2) NULL, `name` VARCHAR(255) NOT NULL, - `phone` 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, diff --git a/pixel_googlemybusiness.tpl b/pixel_googlemybusiness.tpl index bd711c6..18dfc35 100644 --- a/pixel_googlemybusiness.tpl +++ b/pixel_googlemybusiness.tpl @@ -3,15 +3,15 @@
{if 'name'|in_array:$display}
{$place->getName()}
- + {/if} + {if 'phone'|in_array:$display and $place->getPhone()} + {/if} {if 'rating'|in_array:$display}
{if $place->getUserRatingsTotal()} - - + + {l s='Note:' d='Modules.Pixelgooglemybusiness.Shop'} {$place->getRating()}/5 ({$place->getUserRatingsTotal()} {l s='reviews' d='Modules.Pixelgooglemybusiness.Shop'}) {else} @@ -31,13 +31,15 @@
{foreach from=$place->getReviews() item=review}
- + + + {$review->getRating()}/5 - - - + + + {if $review->getComment()}
diff --git a/views/css/gmb.css b/views/css/gmb.css index 3284e97..b55f122 100644 --- a/views/css/gmb.css +++ b/views/css/gmb.css @@ -8,6 +8,10 @@ font-size: 1.1rem; } +.google-places .place .phone { + margin-bottom: 1rem; +} + .google-places .place .rating { margin-bottom: 1rem; } From b858a3a7cef2ca344b113276bfad607b86900344 Mon Sep 17 00:00:00 2001 From: magentix Date: Fri, 12 May 2023 23:54:17 +0200 Subject: [PATCH 6/7] Update tables on upgrade --- upgrade/upgrade-1.0.4.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 upgrade/upgrade-1.0.4.php diff --git a/upgrade/upgrade-1.0.4.php b/upgrade/upgrade-1.0.4.php new file mode 100644 index 0000000..e6c6528 --- /dev/null +++ b/upgrade/upgrade-1.0.4.php @@ -0,0 +1,19 @@ +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; + '); +} From 159c4e8a68907fb4ce6b62ca3febc7444ce384ed Mon Sep 17 00:00:00 2001 From: magentix Date: Fri, 12 May 2023 23:54:37 +0200 Subject: [PATCH 7/7] Documentation updated --- CHANGELOG.md | 6 ++++++ README.md | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 646bbba..6d9169b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index a0236b2..25909fd 100644 --- a/README.md +++ b/README.md @@ -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