AlkantarClanX12
Your IP : 216.73.216.59
<?php
namespace App\View\Composers;
use Illuminate\Support\Facades\Cache;
use Roots\Acorn\View\Composer;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use App\View\Composers\GraphqlData;
use App\Facades\Genius;
class Model extends Composer
{
/**
* List of views served by this composer.
*
* @var array
*/
protected static $views = [
'template-sitemap',
'template-model-goauto',
'template-model-gm',
'template-model-atum',
'template-model',
'blocks.lbx-component',
];
/**
* Data to be passed to view before rendering.
*
* @return array
*/
public function with()
{
$this->modelLanguageUrl();
$this->enqueueScripts();
return [
'modelData' => $this->getUrlType(),
'urlParams' => $this->getParamsFromUrl(),
];
}
/**
* Enqueue of the scripts belonging to the composer.
*
* @return mixed
*/
protected function enqueueScripts()
{
return add_action('wp_enqueue_scripts', function() {
wp_register_script('leadbox-model-lightbox-defer', asset('scripts/bladeScripts/simple-lightbox.js')->uri(), [], false, true);
wp_enqueue_script('leadbox-model-lightbox-defer');
wp_register_script('leadbox-model-script-defer', asset('scripts/bladeScripts/model.js')->uri(), [], false, true);
wp_enqueue_script('leadbox-model-script-defer');
wp_register_script('leadbox-model-colorizer-script-defer', asset('scripts/bladeScripts/model-colorizer.js')->uri(), [], false, true);
wp_enqueue_script('leadbox-model-colorizer-script-defer');
$trimData = $this->trimData()['trimData'] ?? [];
wp_localize_script('leadbox-model-script-defer', 'srpCalculator_ajax_object', array(
'tax_and_lic_label' => get_tax_and_lic_label(),
'province_tax_value' => get_tax_from_province(),
'trim_finance_offers' => $trimData['financeOffers'] ?? [],
'trim_lease_offers' => $trimData['leaseOffers'] ?? [],
));
});
}
/**
* Gets the params from URL for the model template.
*
* @var array $arr_url
* @var string $params
*
* @return string
*/
protected function getParamsFromUrl() : string {
$segment = isFrench() ? '/neufs/' : '/new/';
$arr_url = Str::of($_SERVER['REQUEST_URI'])->explode($segment)->all();
if (isset($arr_url[1])) {
$arr_url_parts = Str::of($arr_url[1])->explode('/')->all();
$params = isset($arr_url_parts[0]) ? Str::of($arr_url_parts[0])->replace('/', '') : '';
} else {
$params = '';
}
if(stripos($params, "?")!== false)
$params = substr($params, 0, stripos($params, "?"));
return $params;
}
/**
* Gets the number of vehicles based on the model received through the parameter.
*
* @param string $model
*
* @var array $inventory
* @var int $inventoryFiltered
*
* @return int
*/
public function getModelsAvailable($model) {
$inventory = get_inventory();
$inventoryFiltered = collect($inventory['vehicles'])->filter(function ($vehicle) use ($model) {
return Str::lower($vehicle['model']) === Str::lower($model) && Str::lower($vehicle['condition']) === 'new';
})->count();
return $inventoryFiltered;
}
/**
* Depending on the URL, get the model or trim data.
*
* @var array $modelDataArray
*
* @return array
*/
protected function getUrlType() {
$modelDataArray = $this->modelData();
if (count($modelDataArray) > 0) {
return $modelDataArray;
} else {
return Model::trimData();
}
}
/**
* Concatenates to the Polylang translation link the parameters of the model.
*
* @var array $arr_url
* @var string $params
*
* @param string $url
*
* @return string
*/
protected function modelLanguageUrl()
{
if ( is_page_template('template-model.blade.php') || is_page_template('template-model-atum.blade.php') ) {
add_filter('pll_the_language_link', function ($url) {
if( isFrench() ) {
$arr_url = Str::of($_SERVER['REQUEST_URI'])->explode('/neufs/')->all();
$params = Str::of($arr_url[1])->replace('/', '');
} else {
$arr_url = Str::of($_SERVER['REQUEST_URI'])->explode('/new/')->all();
$params = Str::of($arr_url[1])->replace('/', '');
}
return strtolower( $url . $params . '/' );
}, 10, 2);
}
}
/**
* Returns the collection at position ['modelList'] of the array where all the model information is located.
* @var string $query
*
* @return array
*/
protected function modelData() : array
{
if( !Model::getParamsFromUrl() ) {
return [];
}
$query = '
{
modelList(id: "'.Model::getParamsFromUrl().'", idType: SLUG) {
title
featuredImage {
node {
sourceUrl
}
}
modelData {
year
make
model
category
startingPrice
features
description
descriptionFr
buildPrice
content {
heading
text
image {
sourceUrl
}
}
contentFr {
heading
text
image {
sourceUrl
}
}
financeOffers {
term
rate
regionKey
}
leaseOffers {
term
rate
mileage
residual
regionKey
}
trims {
... on ModelTrim {
trimData {
name
jellybean {
sourceUrl(size: LARGE)
}
colorizer {
colorName
images {
url
imageType
image {
sourceUrl(size: MEDIUM)
}
}
}
}
}
}
galleryExt {
sourceUrl(size: MEDIUM)
sourceUrlLarge: sourceUrl(size: LARGE)
}
galleryInt {
sourceUrl(size: MEDIUM)
sourceUrlLarge: sourceUrl(size: LARGE)
}
colorizer {
isJellybean
colorName
hexCode
colorNameFr
images {
url
imageType
image {
sourceUrl(size: MEDIUM)
}
}
}
}
}
}
';
return (new GraphqlData)->getGraphData($query, "model")
// We filter the array $row to exclude models that may be selected in the setting
->reject(function ($row) {
if (!is_array($row)) {
return false;
}
$options = get_option('dealer-settings-showroom-options');
$excludedModelsOption = isset($options['excluded_models']) ? Str::lower($options['excluded_models']) : '';
if (strlen($excludedModelsOption) === 0) {
return false;
}
$excludedModels = Str::of($excludedModelsOption)
->explode(',')
->transform(function ($model) {
return Str::of($model)->trim();
})
->all();
return in_array(Str::lower($row['model']), $excludedModels);
})
->map(function ($row) {
if (is_array($row)) {
// Merge of medium sized exterior and interior images.
$mediumGalleryExt = [];
$mediumGalleryInt = [];
if (isset($row['galleryExt']) && is_array($row['galleryExt'])) {
$mediumGalleryExt = collect($row['galleryExt'])->transform(function ($row) {
return $row;
})->all();
}
if (isset($row['galleryInt']) && is_array($row['galleryInt'])) {
$mediumGalleryInt = collect($row['galleryInt'])->transform(function ($row) {
return $row;
})->all();
}
$row['galleryImages'] = array_merge($mediumGalleryExt, $mediumGalleryInt);
// Randomizing the gallery images
shuffle($row['galleryImages']);
// Get the finance offers for the dealer province
$financeOffer = null;
if (isset($row['financeOffers']) && is_array($row['financeOffers'])) {
$financeOffer = collect($row['financeOffers'])
->first(function ($nestedValue) {
return $nestedValue['regionKey'] == get_dealer_contact()['address_province'];
});
}
$row['financeOffers'] = $financeOffer;
// Get the lease offers for the dealer province
$leaseOffer = null;
if (isset($row['leaseOffers']) && is_array($row['leaseOffers'])) {
$leaseOffer = collect($row['leaseOffers'])
->first(function ($nestedValue) {
return $nestedValue['regionKey'] == get_dealer_contact()['address_province'];
});
}
$row['leaseOffers'] = $leaseOffer;
// Set a 'financeTotal' property that returns the finance amount
if($row['financeOffers'] != null) {
$row['financeTotal'] = getFinanceTotal($row['startingPrice'], $row['financeOffers']['rate'], $row['financeOffers']['term']);
} else {
$row['financeTotal'] = 'XX';
}
// Set a 'leaseTotal' property that returns the lease amount
if($row['financeOffers'] != null) {
$row['leaseTotal'] = getLeaseTotal($row['startingPrice'], $row['leaseOffers']['term'], $row['leaseOffers']['rate'], $row['leaseOffers']['residual']);
} else {
$row['leaseTotal'] = 'XX';
}
// We filter the array $row['trims'] to exclude trims that may be selected in the setting
if(get_option('dealer-settings-showroom-options')){
$excludedModelsTrimsOption = Str::lower(get_option('dealer-settings-showroom-options')['excluded_trims']);
if( strlen($excludedModelsTrimsOption) > 0 ) {
$excludedModels = Str::of($excludedModelsTrimsOption)
->explode(',')
->transform(function ($model) {
return Str::of($model)->trim();
})
->all();
foreach($excludedModels as $model) {
$model_trim = explode("|", $model);
if(strtolower($model_trim[0]) == strtolower($row['model'])) {
if(is_array($row['trims'])){
foreach ($row['trims'] as $key => $value) {
if(strtolower($value['trimData']['name']) == strtolower($model_trim[1])) {
unset($row['trims'][$key]);
}
}
}
}
}
}
}
$row['trimData'] = [];
if (isset($row['trims']) && is_array($row['trims'])) {
$row['trimData'] = collect($row['trims'])->map(function ($trim) use ($row) {
$trim['trimData']['link'] = Str::lower($row['year'].'-'.Str::of($row['make'])->replace(' ', '-').'-'.Str::of($row['model'])->replace(' ', '-').'-');
$trim['trimData']['jellybean'] = $trim['trimData']['jellybean']['sourceUrl'];
return $trim['trimData'];
})->all();
}
}
return $row;
})
->all();
}
/**
* Gets the models that match the category received through parameter
*
* @param string $category
*
* @var string $query
*
* @return array
*/
public function getModelsByCategory($categories) {
$query = '
{
modelLists(first: 100, where: { search: "'.get_leadbox_manufacturer().'"}) {
nodes {
modelData {
year
make
model
colorizer {
colorName
colorNameFr
images {
url
imageType
image {
sourceUrl(size: MEDIUM)
}
}
}
category
startingPrice
}
}
}
}
';
return (new GraphqlData)->getGraphData($query)
->filter(function ($row) use ($categories) {
if (is_array($row)) {
foreach ($categories as $category) {
if (\in_array($category, $row['modelData']['category'])) {
return $row;
}
}
}
})
->map(function ($row) {
if (is_array($row)) {
$orientation = Str::lower(Genius::get('lineup.data.colorizer-orientation') ?: 'SR');
$colorizers = collect($row['modelData']['colorizer'])
// Here we remove the additional spaces that may bring the variables of the names from the content server.
->transform(function ($colorizer) use ($orientation) {
$colorizer['colorName'] = Str::headline( $colorizer['colorName'] );
$colorizer['colorNameFr'] = Str::headline( $colorizer['colorNameFr'] );
$resolveUrl = function ($image) {
return !empty($image['url']) ? $image['url'] : $image['image']['sourceUrl'];
};
// Image with the orientation configured in Genius (default 'SR').
$colorizer['imageSelected'] = collect($colorizer['images'])
->filter(function ($image) use ($orientation) {
return Str::lower($image['imageType']) === $orientation;
})
->map($resolveUrl)
->first();
// Fallback: any other available orientation, used only as a last resort.
$colorizer['imageFallback'] = collect($colorizer['images'])
->map($resolveUrl)
->filter()
->first();
return $colorizer;
});
// Cascade fallback for the selector configured in Genius:
// 1. configured color with the requested orientation
// 2. first available color with the requested orientation
// 3. configured color with any other orientation
// 4. coming-soon placeholder
$selectorMap = Genius::get('lineup.data.colorizer-selector');
$modelKey = Str::lower($row['modelData']['model']);
$hasSelector = is_array($selectorMap) && Arr::exists($selectorMap, $modelKey);
if ($hasSelector) {
$selectedColor = Arr::get($selectorMap, $modelKey);
$configured = $colorizers->first(function ($colorizer) use ($selectedColor) {
return Str::lower($colorizer['colorName']) === $selectedColor;
});
if ($configured && !empty($configured['imageSelected'])) {
$picked = $configured;
} else {
$anyWithOrientation = $colorizers->first(function ($colorizer) {
return !empty($colorizer['imageSelected']);
});
if ($anyWithOrientation) {
$picked = $anyWithOrientation;
} elseif ($configured && !empty($configured['imageFallback'])) {
$configured['imageSelected'] = $configured['imageFallback'];
$picked = $configured;
} else {
$picked = null;
}
}
$row['modelData']['colorizer'] = $picked ? [$picked] : [];
} else {
$row['modelData']['colorizer'] = $colorizers->values()->all();
}
return $row;
}
})
// If the model contains the Future Vehicles category, reject it.
->reject(function ($row) {
if (is_array($row)) {
return in_array('Future Vehicles', $row['modelData']['category']);
}
})
// Exclude models that may be selected in the dealer setting
->reject(function ($row) {
if (is_array($row)) {
if(get_option('dealer-settings-showroom-options')){
$excludedModelsOption = Str::lower(get_option('dealer-settings-showroom-options')['excluded_models']);
if( strlen($excludedModelsOption) > 0 ) {
$excludedModels = Str::of($excludedModelsOption)
->explode(',')
->transform(function ($model) {
return Str::of($model)->trim();
})
->all();
return in_array(Str::lower($row['modelData']['model']), $excludedModels);
} else {
return null;
}
}
}
})
->all();
}
/**
* Returns the collection at position ['modelList'] of the array where all the model information of the trim is located.
* @param $modelUrl
*
* @var string $query
*
* @return array
*/
protected function modelDataInTrim($modelUrl) : array
{
$query = '
{
modelList(id: "'.$modelUrl.'", idType: SLUG) {
featuredImage {
node {
sourceUrl
}
}
modelData {
year
make
model
description
descriptionFr
buildPrice
features
content {
heading
text
image {
sourceUrl
}
}
contentFr {
heading
text
image {
sourceUrl
}
}
trims {
... on ModelTrim {
trimData {
name
jellybean {
sourceUrl(size: LARGE)
}
colorizer {
colorName
images {
url
imageType
image {
sourceUrl(size: MEDIUM)
}
}
}
}
}
}
galleryExt {
sourceUrl(size: MEDIUM)
sourceUrlLarge: sourceUrl(size: LARGE)
}
galleryInt {
sourceUrl(size: MEDIUM)
sourceUrlLarge: sourceUrl(size: LARGE)
}
}
}
}
';
return (new GraphqlData)->getGraphData($query, "model")
->map(function ($row) {
if (is_array($row)) {
// Merge of medium sized exterior and interior images.
$mediumGalleryExt = collect($row['galleryExt'])->transform(function ($row) {
return $row;
})->all();
$mediumGalleryInt = collect($row['galleryInt'])->transform(function ($row) {
return $row;
})->all();
$row['galleryImages'] = array_merge($mediumGalleryExt, $mediumGalleryInt);
// Randomizing the gallery images
shuffle($row['galleryImages']);
// We filter the array $row['trims'] to exclude trims that may be selected in the setting
$excludedModelsOption = Str::lower(get_option('dealer-settings-showroom-options')['excluded_trims']);
if( strlen($excludedModelsOption) > 0 ) {
$excludedModels = Str::of($excludedModelsOption)
->explode(',')
->transform(function ($model) {
return Str::of($model)->trim();
})
->all();
foreach($excludedModels as $model) {
$model_trim = explode("|", $model);
if(strtolower($model_trim[0]) == strtolower($row['model'])) {
if(is_array($row['trims'])){
foreach ($row['trims'] as $key => $value) {
if(strtolower($value['trimData']['name']) == strtolower($model_trim[1])) {
unset($row['trims'][$key]);
}
}
}
}
}
}
$row['trimData'] = collect($row['trims'])->map(function ($trim) use ($row) {
$trim['trimData']['link'] = Str::lower($row['year'].'-'.Str::of($row['make'])->replace(' ', '-').'-'.Str::of($row['model'])->replace(' ', '-').'-');
$trim['trimData']['jellybean'] = $trim['trimData']['jellybean']['sourceUrl'];
return $trim['trimData'];
})->all();
}
return $row;
})
->all();
}
/**
* Returns the collection at position ['modelTrim'] of the array where all the trim information is located.
* @param $modelUrl
*
* @var string $query
*
* @return array
*/
protected function trimData() : array
{
if( !Model::getParamsFromUrl() ) {
return [];
}
$query = '
{
modelTrim(id: "'.Model::getParamsFromUrl().'", idType: SLUG) {
title
trimData {
name
startingPrice
financeOffers {
term
rate
regionKey
}
leaseOffers {
term
rate
mileage
residual
regionKey
}
features
colorizer {
isJellybean
colorName
hexCode
colorNameFr
images {
url
imageType
image {
sourceUrl(size: MEDIUM)
}
}
}
}
}
}
';
return (new GraphqlData)->getGraphData($query, "trim")
->pipe(function ($collection) {
return collect([
'trimData' => array_merge($collection->get('trimData') ?? [], ['title' => $collection->get('title') ?? []]),
]);
})
->map(function ($row) {
$row['arrayName'] = Str::of(Str::replace(' ', ',', (isset($row['name'])) ? Str::lower($row['name']) : ''))->split('/[\s,]+/')->all();
$title = is_array($row['title'] ?? '') ? '' : ($row['title'] ?? '');
$name = is_array($row['name'] ?? '') ? '' : ($row['name'] ?? '');
$row['modelUrl'] = Str::slug(Str::of(Str::replace(' ', ',', $title . ' ' . $name))->split('/[\s,]+/')->reject(function ($words) use ($row) {
return isset($row['arrayName']) && is_array($row['arrayName'])
? in_array(Str::lower($words), $row['arrayName'])
: false;
})->implode(' ')
);
if(isset($row['name']) && isset($row['title'])){
$name_length = strlen(trim(Str::lower($row['name'])));
$substring_length = strlen(Str::lower(str_replace('’', '',$row['title']) )) - $name_length - 1; // Restamos 1 para quitar la última letra de $row['name']
$substring = substr(Str::lower($row['title']), 0, $substring_length);
$url = str_replace(' ', '-', trim($substring));
$row['model'] = Model::modelDataInTrim($url);
}
// Get the finance offers for the dealer province
if(isset($row['financeOffers'])){
$row['financeOffers'] = collect($row['financeOffers'])
->filter(function ($nestedValue) {
return $nestedValue['regionKey'] == get_dealer_contact()['address_province'];
})->sortBy(['term', 'desc'])->all();
}else{
$row['financeOffers'] = '';
}
// Get the lease offers for the dealer province
if(isset($row['leaseOffers'])){
$row['leaseOffers'] = collect($row['leaseOffers'])
->map(function ($nestedValue) {
$nestedValue['mileage'] = (int) $nestedValue['mileage'];
return $nestedValue;
})
->filter(function ($nestedValue) use ($row) {
return $nestedValue['regionKey'] == get_dealer_contact()['address_province'] && $nestedValue['mileage'] == collect($row['leaseOffers'])->max('mileage');
})->sortBy(['term', 'desc'])->all();
}else{
$row['leaseOffers'] = '';
}
return $row;
})
->all();
}
}
Home - Capital GMC Buick Regina
Skip to content
{{ $t(category) }}
Error
{{vehicle.modelData.year}} {{vehicle.modelData.make}} {{vehicle.modelData.model}}
Starting from {{vehicle.modelData.startingPrice | moneyFormat(lang)}}
Welcome to Capital GMC BUICK – REGINA
Thank you for choosing Capital GMC Buick | Regina, your premier certified Buick and GMC dealership proudly serving drivers in Regina and the surrounding communities. Whether you’re searching for a brand-new Buick or GMC vehicle or a meticulously inspected pre-owned model, we have a diverse selection to match your needs and lifestyle.
Beyond our impressive inventory, we offer a seamless and stress-free financing experience through our well-connected finance centre, where our team of experts is dedicated to securing the best loan or lease options for you, quickly, transparently, and hassle-free.
But our commitment to you doesn’t stop at the sale. Our state-of-the-art service centre is staffed with skilled Buick and GMC technicians who use the latest equipment and genuine OEM parts to keep your vehicle running at its best. From routine maintenance to complex repairs, we’ve got you covered.
Experience top-tier customer service, quality vehicles, and expert care, all in one place. Visit Capital GMC Buick | Regina today or call us at 306-205-8072 with any questions. We’re here to help!
Ask a Question
Capital GMC Buick – Regina
Contact Us
Have a question or need assistance? Fill out the form and we will reach out to you as soon as possible.
Notice: JavaScript is required for this content.
CLOSE
Schedule a Visit
Let us know when you are coming and how we can assist you. We can ensure someone will be on hand to help you out at the desired date and time.
Notice: JavaScript is required for this content.
CLOSE
Find a Career
Have a look at our list of available positions and apply online today to join our team!
×
Opportunities to Grow
The auto industry is constantly changing and we want to continue to grow. We offer growth, leadership & mentorship programs to allow our staff to grow with us.
×
Competitive Salary
We have a significant earning potential with incentive-based pay in most roles. We also offer an employee referral bonus with paid bonuses.
×
Health & Dental
We offer a comprehensive benefits package including extended health, dental, and vision care. We also include paramedical, life insurance, paid sick leave, short & long-term disability coverages.
×
Vacation
We value our employees and want everyone to take their vacation time. We offer a minimum of 2 weeks vacation each year.
×
Training & Development
We have many opportunities for paid education and training in-house as well as training from the Manufacturer.
×
$10,000 Cash Giveaway – Terms & Conditions
All October long, stop by Capital GMC Buick Cadillac, to enter for your chance to win $10,000 cash. No purchase is required, but entries must be made in-store.
The contest is open to residents of Saskatchewan who are 18+. Dealership employees and their households are not eligible. Entries will be accepted from October 1 to October 31, 2025. A random draw will take place on November 1, 2025.
The prize is one $10,000 award, paid by cheque, and must be accepted as awarded. Winner will be contacted by phone or email and must respond within 7 days or another entry may be drawn. Odds of winning depend on the number of entries received.By entering, you agree that Capital Automotive Group may use your name and photo for winner announcements. The contest is governed by the laws of Saskatchewan.
Notice: JavaScript is required for this content.
CLOSE