Skip to content

Commit

Permalink
[Fixed advertisement locale issue]
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-webkul committed Aug 3, 2023
1 parent 1596f67 commit 2455ffa
Showing 1 changed file with 64 additions and 25 deletions.
89 changes: 64 additions & 25 deletions src/Queries/Shop/Common/HomePageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,76 @@ public function getSliders($rootValue, array $args, GraphQLContext $context)

public function getAdvertisements($rootValue, array $args)
{
$data = [];
$data = [
'advertisementFour' => [
[
'image' => asset('/themes/velocity/assets/images/big-sale-banner.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/seasons.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/deals.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/kids.webp'),
'slug' => null
],
],
'advertisementThree' => [
[
'image' => asset('/themes/velocity/assets/images/headphones.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/watch.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/kids-2.webp'),
'slug' => null
],
],
'advertisementTwo' => [
[
'image' => asset('/themes/velocity/assets/images/toster.webp'),
'slug' => null
], [
'image' => asset('/themes/velocity/assets/images/trimmer.webp'),
'slug' => null
],
],
];

if (core()->getCurrentChannel()->theme == 'velocity') {
$advertisementRecord = $this->velocityMetadataRepository->where(['locale' => core()->getRequestedLocaleCode(), 'channel' => core()->getDefaultChannelCode()])->first();

if ($advertisementRecord) {
$advertisement = json_decode($advertisementRecord->advertisement, true);

$advertisementFour = $this->advertisement(4, $advertisement);
$advertisementThree = $this->advertisement(3, $advertisement);
$advertisementTwo = $this->advertisement(2, $advertisement);
if (! $advertisementRecord) {
return $data;
}

$homeContent = preg_replace('/\s+/', '', $advertisementRecord->home_page_content);

foreach (explode("@include", $homeContent) as $template) {
if (Str::contains($template, 'shop::home.advertisements.advertisement-four')
) {
$advertisementFour = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-four',", $template, $advertisementFour);

} else if (Str::contains($template, 'shop::home.advertisements.advertisement-three')) {
$advertisementThree = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-three',", $template, $advertisementThree);

} else if (Str::contains($template, 'shop::home.advertisements.advertisement-two')) {
$advertisementTwo = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-two',", $template, $advertisementTwo);
}
$advertisement = json_decode($advertisementRecord->advertisement, true);

$advertisementFour = $this->advertisement(4, $advertisement);
$advertisementThree = $this->advertisement(3, $advertisement);
$advertisementTwo = $this->advertisement(2, $advertisement);

$homeContent = preg_replace('/\s+/', '', $advertisementRecord->home_page_content);

foreach (explode("@include", $homeContent) as $template) {
if (Str::contains($template, 'shop::home.advertisements.advertisement-four')
) {
$advertisementFour = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-four',", $template, $advertisementFour);

} else if (Str::contains($template, 'shop::home.advertisements.advertisement-three')) {
$advertisementThree = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-three',", $template, $advertisementThree);

} else if (Str::contains($template, 'shop::home.advertisements.advertisement-two')) {
$advertisementTwo = $this->getAdvertisementSlug("'shop::home.advertisements.advertisement-two',", $template, $advertisementTwo);
}

$data['advertisementFour'] = $advertisementFour;
$data['advertisementThree'] = $advertisementThree;
$data['advertisementTwo'] = $advertisementTwo;
}

$data['advertisementFour'] = $advertisementFour;
$data['advertisementThree'] = $advertisementThree;
$data['advertisementTwo'] = $advertisementTwo;
} else {
$data['advertisementFour'] = $data['advertisementTwo'] = [];
$data['advertisementThree'] = [
Expand All @@ -208,7 +247,7 @@ public function getAdvertisements($rootValue, array $args)
],
];
}

return $data;
}

Expand Down

0 comments on commit 2455ffa

Please sign in to comment.