Global Flags Provided

This commit is contained in:
Devansh 2021-12-30 16:54:12 +05:30
parent 70c74e1233
commit 6a49f55300
8 changed files with 70 additions and 95 deletions

View File

@ -13,6 +13,20 @@ class Locale extends Model implements LocaleContract
{ {
use HasFactory; use HasFactory;
/**
* List of all default locale images for velocity.
*
* @var array
*/
protected $defaultImage = [
'de' => 'flags/de.png',
'en' => 'flags/en.png',
'es' => 'flags/es.png',
'fr' => 'flags/fr.png',
'nl' => 'flags/nl.png',
'tr' => 'flags/tr.png',
];
/** /**
* The attributes that are mass assignable. * The attributes that are mass assignable.
* *
@ -46,19 +60,9 @@ class Locale extends Model implements LocaleContract
* *
* @return string * @return string
*/ */
public function image_url() public function getImageUrlAttribute(): string
{ {
if (! $this->locale_image) { return $this->image_url();
$defaultLocaleImagePath = 'themes/velocity/assets/images/flags/' . $this->code . '.png';
if (file_exists(public_path($defaultLocaleImagePath))) {
return asset($defaultLocaleImagePath);
}
return '';
}
return Storage::url($this->locale_image);
} }
/** /**
@ -66,8 +70,24 @@ class Locale extends Model implements LocaleContract
* *
* @return string * @return string
*/ */
public function getImageUrlAttribute() public function image_url(): string
{ {
return $this->image_url(); if (! $this->locale_image) {
return $this->getDefaultImageSource();
}
return Storage::url($this->locale_image);
}
/**
* Get default image source.
*
* @return string
*/
public function getDefaultImageSource(): string
{
return isset($this->defaultImage[$this->code]) && file_exists($this->defaultImage[$this->code])
? asset($this->defaultImage[$this->code])
: '';
} }
} }

View File

@ -2,7 +2,6 @@
namespace Webkul\Velocity\Helpers; namespace Webkul\Velocity\Helpers;
use Illuminate\Support\Facades\Storage;
use Webkul\Attribute\Repositories\AttributeOptionRepository; use Webkul\Attribute\Repositories\AttributeOptionRepository;
use Webkul\Product\Facades\ProductImage; use Webkul\Product\Facades\ProductImage;
use Webkul\Product\Helpers\Review; use Webkul\Product\Helpers\Review;
@ -64,20 +63,6 @@ class Helper extends Review
*/ */
protected $velocityMetadataRepository; protected $velocityMetadataRepository;
/**
* List of all default locale images for velocity.
*
* @var array
*/
protected $defaultLocaleImageSources = [
'de' => '/themes/velocity/assets/images/flags/de.png',
'en' => '/themes/velocity/assets/images/flags/en.png',
'es' => '/themes/velocity/assets/images/flags/es.png',
'fr' => '/themes/velocity/assets/images/flags/fr.png',
'nl' => '/themes/velocity/assets/images/flags/nl.png',
'tr' => '/themes/velocity/assets/images/flags/tr.png'
];
/** /**
* Create a helper instance. * Create a helper instance.
* *
@ -97,9 +82,9 @@ class Helper extends Review
ProductReviewRepository $productReviewRepository, ProductReviewRepository $productReviewRepository,
VelocityMetadataRepository $velocityMetadataRepository VelocityMetadataRepository $velocityMetadataRepository
) { ) {
$this->productModel = $productModel; $this->productModel = $productModel;
$this->attributeOptionRepository = $attributeOptionRepository; $this->attributeOptionRepository = $attributeOptionRepository;
$this->productRepository = $productRepository; $this->productRepository = $productRepository;
@ -107,9 +92,9 @@ class Helper extends Review
$this->orderBrandsRepository = $orderBrandsRepository; $this->orderBrandsRepository = $orderBrandsRepository;
$this->productReviewRepository = $productReviewRepository; $this->productReviewRepository = $productReviewRepository;
$this->velocityMetadataRepository = $velocityMetadataRepository; $this->velocityMetadataRepository = $velocityMetadataRepository;
} }
/** /**
@ -181,7 +166,7 @@ class Helper extends Review
} }
foreach ($brandName as $brandKey => $brandvalue) { foreach ($brandName as $brandKey => $brandvalue) {
$brandImplode[$brandKey][] = implode(' | ', array_map("ucfirst", $brandvalue)); $brandImplode[$brandKey][] = implode(' | ', array_map('ucfirst', $brandvalue));
} }
return $brandImplode; return $brandImplode;
@ -214,14 +199,14 @@ class Helper extends Review
try { try {
$metaData = $this->velocityMetadataRepository->findOneWhere([ $metaData = $this->velocityMetadataRepository->findOneWhere([
'locale' => $locale, 'locale' => $locale,
'channel' => $channel 'channel' => $channel,
]); ]);
if (! $metaData && $default) { if (! $metaData && $default) {
$metaData = $this->velocityMetadataRepository->findOneWhere([ $metaData = $this->velocityMetadataRepository->findOneWhere([
'locale' => 'en', 'locale' => 'en',
'channel' => 'default' 'channel' => 'default',
]); ]);
} }
@ -255,8 +240,8 @@ class Helper extends Review
public function getMessage() public function getMessage()
{ {
$message = [ $message = [
'message' => '', 'message' => '',
'messageType' => '', 'messageType' => '',
'messageLabel' => '', 'messageLabel' => '',
]; ];
@ -291,7 +276,7 @@ class Helper extends Review
if (is_string($path) && is_readable($path)) { if (is_string($path) && is_readable($path)) {
return include $path; return include $path;
} else { } else {
$currentLocale = "en"; $currentLocale = 'en';
$path = __DIR__ . "/../Resources/lang/$currentLocale/app.php"; $path = __DIR__ . "/../Resources/lang/$currentLocale/app.php";
@ -336,8 +321,8 @@ class Helper extends Review
$galleryImages = ProductImage::getGalleryImages($product); $galleryImages = ProductImage::getGalleryImages($product);
$productImage = ProductImage::getProductBaseImage($product, $galleryImages)['medium_image_url']; $productImage = ProductImage::getProductBaseImage($product, $galleryImages)['medium_image_url'];
$largeProductImageName = "large-product-placeholder.png"; $largeProductImageName = 'large-product-placeholder.png';
$mediumProductImageName = "meduim-product-placeholder.png"; $mediumProductImageName = 'meduim-product-placeholder.png';
if (strpos($productImage, $mediumProductImageName) > -1) { if (strpos($productImage, $mediumProductImageName) > -1) {
$productImageNameCollection = explode('/', $productImage); $productImageNameCollection = explode('/', $productImage);
@ -353,28 +338,28 @@ class Helper extends Review
$isProductNew = ($product->new && ! strpos($priceHTML, 'sticker sale') > 0) ? __('shop::app.products.new') : false; $isProductNew = ($product->new && ! strpos($priceHTML, 'sticker sale') > 0) ? __('shop::app.products.new') : false;
return [ return [
'priceHTML' => $priceHTML, 'priceHTML' => $priceHTML,
'avgRating' => ceil($reviewHelper->getAverageRating($product)), 'avgRating' => ceil($reviewHelper->getAverageRating($product)),
'totalReviews' => $reviewHelper->getTotalReviews($product), 'totalReviews' => $reviewHelper->getTotalReviews($product),
'image' => $productImage, 'image' => $productImage,
'new' => $isProductNew, 'new' => $isProductNew,
'galleryImages' => $galleryImages, 'galleryImages' => $galleryImages,
'name' => $product->name, 'name' => $product->name,
'slug' => $product->url_key, 'slug' => $product->url_key,
'description' => $product->description, 'description' => $product->description,
'shortDescription' => $product->short_description, 'shortDescription' => $product->short_description,
'firstReviewText' => trans('velocity::app.products.be-first-review'), 'firstReviewText' => trans('velocity::app.products.be-first-review'),
'addToCartHtml' => view('shop::products.add-to-cart', [ 'addToCartHtml' => view('shop::products.add-to-cart', [
'product' => $product, 'product' => $product,
'addWishlistClass' => ! (isset($list) && $list) ? '' : '', 'addWishlistClass' => ! (isset($list) && $list) ? '' : '',
'showCompare' => core()->getConfigData('general.content.shop.compare_option') == "1" 'showCompare' => core()->getConfigData('general.content.shop.compare_option') == '1'
? true : false, ? true : false,
'btnText' => (isset($metaInformation['btnText']) && $metaInformation['btnText']) 'btnText' => (isset($metaInformation['btnText']) && $metaInformation['btnText'])
? $metaInformation['btnText'] : null, ? $metaInformation['btnText'] : null,
'moveToCart' => (isset($metaInformation['moveToCart']) && $metaInformation['moveToCart']) 'moveToCart' => (isset($metaInformation['moveToCart']) && $metaInformation['moveToCart'])
? $metaInformation['moveToCart'] : null, ? $metaInformation['moveToCart'] : null,
'addToCartBtnClass' => ! (isset($list) && $list) ? 'small-padding' : '', 'addToCartBtnClass' => ! (isset($list) && $list) ? 'small-padding' : '',
@ -399,48 +384,18 @@ class Helper extends Review
if ($productFlat) { if ($productFlat) {
$formattedProduct = $this->formatProduct($productFlat, false, [ $formattedProduct = $this->formatProduct($productFlat, false, [
'moveToCart' => $moveToCart, 'moveToCart' => $moveToCart,
'btnText' => $moveToCart ? trans('shop::app.customer.account.wishlist.move-to-cart') : null, 'btnText' => $moveToCart ? trans('shop::app.customer.account.wishlist.move-to-cart') : null,
]); ]);
return array_merge($productFlat->toArray(), [ return array_merge($productFlat->toArray(), [
'slug' => $productFlat->url_key, 'slug' => $productFlat->url_key,
'product_image' => $formattedProduct['image'], 'product_image' => $formattedProduct['image'],
'priceHTML' => $formattedProduct['priceHTML'], 'priceHTML' => $formattedProduct['priceHTML'],
'new' => $formattedProduct['new'], 'new' => $formattedProduct['new'],
'addToCartHtml' => $formattedProduct['addToCartHtml'], 'addToCartHtml' => $formattedProduct['addToCartHtml'],
'galleryImages' => $formattedProduct['galleryImages'] 'galleryImages' => $formattedProduct['galleryImages'],
]); ]);
} }
})->toArray(); })->toArray();
} }
/**
* Get current locale image source.
*
* @return string
*/
public function getCurrentLocaleImageSource(): string
{
$localeImages = core()->getCurrentChannel()->locales()->pluck('locale_image', 'code');
$currentLocaleImage = $localeImages[app()->getLocale()] ?? null;
return $currentLocaleImage
? Storage::url($currentLocaleImage)
: $this->getDefaultImageSourceOfCurrentLocale();
}
/**
* Get default image source of current locale.
*
* @return string
*/
public function getDefaultImageSourceOfCurrentLocale(): string
{
$currentLocale = app()->getLocale();
return isset($this->defaultLocaleImageSources[$currentLocale])
? asset($this->defaultLocaleImageSources[$currentLocale])
: '';
}
} }

BIN
public/flags/de.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
public/flags/en.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

BIN
public/flags/es.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

BIN
public/flags/fr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

BIN
public/flags/nl.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
public/flags/tr.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB