product image facade added
This commit is contained in:
parent
31a5256ae1
commit
7157318d18
|
|
@ -340,5 +340,6 @@ return [
|
|||
'Concord' => Konekt\Concord\Facades\Concord::class,
|
||||
'Helper' => Konekt\Concord\Facades\Helper::class,
|
||||
'Debugbar' => Barryvdh\Debugbar\Facade::class,
|
||||
'ProductImage' => Webkul\Product\Facades\ProductImage::class
|
||||
],
|
||||
];
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Product\Facades;
|
||||
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
|
||||
class ProductImage extends Facade
|
||||
{
|
||||
/**
|
||||
* Get the registered name of the component.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected static function getFacadeAccessor()
|
||||
{
|
||||
return 'productimage';
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,124 @@
|
|||
<?php
|
||||
|
||||
namespace Webkul\Product;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Webkul\Product\Repositories\ProductRepository;
|
||||
use Webkul\Product\Helpers\AbstractProduct;
|
||||
|
||||
class ProductImage extends AbstractProduct
|
||||
{
|
||||
/**
|
||||
* ProductRepository instance
|
||||
*
|
||||
* @var \Webkul\Product\Repositories\ProductRepository
|
||||
*/
|
||||
protected $productRepository;
|
||||
|
||||
/**
|
||||
* Create a new helper instance.
|
||||
*
|
||||
* @param \Webkul\Product\Repositories\ProductRepository $productRepository
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(
|
||||
ProductRepository $productRepository
|
||||
)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
}
|
||||
|
||||
public function sampleText()
|
||||
{
|
||||
echo "Sample Text";
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve collection of gallery images
|
||||
*
|
||||
* @param \Webkul\Product\Contracts\Product|\Webkul\Product\Contracts\ProductFlat $product
|
||||
* @return array
|
||||
*/
|
||||
public function getGalleryImages($product)
|
||||
{
|
||||
if (! $product) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$images = [];
|
||||
|
||||
foreach ($product->images as $image) {
|
||||
if (! Storage::has($image->path)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$images[] = [
|
||||
'small_image_url' => url('cache/small/' . $image->path),
|
||||
'medium_image_url' => url('cache/medium/' . $image->path),
|
||||
'large_image_url' => url('cache/large/' . $image->path),
|
||||
'original_image_url' => url('cache/original/' . $image->path),
|
||||
];
|
||||
}
|
||||
|
||||
if (! $product->parent_id && ! count($images) && ! count($product->videos)) {
|
||||
$images[] = [
|
||||
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.webp'),
|
||||
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.webp'),
|
||||
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.webp'),
|
||||
'original_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.webp'),
|
||||
];
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product's base image
|
||||
*
|
||||
* @param \Webkul\Product\Contracts\Product|\Webkul\Product\Contracts\ProductFlat $product
|
||||
* @return array
|
||||
*/
|
||||
public function getProductBaseImage($product)
|
||||
{
|
||||
$images = $product ? $product->images : null;
|
||||
|
||||
if ($images && $images->count()) {
|
||||
$image = [
|
||||
'small_image_url' => url('cache/small/' . $images[0]->path),
|
||||
'medium_image_url' => url('cache/medium/' . $images[0]->path),
|
||||
'large_image_url' => url('cache/large/' . $images[0]->path),
|
||||
'original_image_url' => url('cache/original/' . $images[0]->path),
|
||||
];
|
||||
} else {
|
||||
$image = [
|
||||
'small_image_url' => asset('vendor/webkul/ui/assets/images/product/small-product-placeholder.webp'),
|
||||
'medium_image_url' => asset('vendor/webkul/ui/assets/images/product/meduim-product-placeholder.webp'),
|
||||
'large_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.webp'),
|
||||
'original_image_url' => asset('vendor/webkul/ui/assets/images/product/large-product-placeholder.webp'),
|
||||
];
|
||||
}
|
||||
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get product varient image if available otherwise product base image
|
||||
*
|
||||
* @param \Webkul\Customer\Contracts\Wishlist $item
|
||||
* @return array
|
||||
*/
|
||||
public function getProductImage($item)
|
||||
{
|
||||
if ($item instanceof \Webkul\Customer\Contracts\Wishlist) {
|
||||
if (isset($item->additional['selected_configurable_option'])) {
|
||||
$product = $this->productRepository->find($item->additional['selected_configurable_option']);
|
||||
} else {
|
||||
$product = $item->product;
|
||||
}
|
||||
} else {
|
||||
$product = $item->product;
|
||||
}
|
||||
|
||||
return $this->getProductBaseImage($product);
|
||||
}
|
||||
}
|
||||
|
|
@ -8,6 +8,9 @@ use Webkul\Product\Models\ProductProxy;
|
|||
use Webkul\Product\Observers\ProductObserver;
|
||||
use Webkul\Product\Console\Commands\PriceUpdate;
|
||||
use Webkul\Product\Console\Commands\GenerateProducts;
|
||||
use Illuminate\Foundation\AliasLoader;
|
||||
use Webkul\Product\Facades\ProductImage as ProductImageFacade;
|
||||
use Webkul\Product\ProductImage;
|
||||
|
||||
class ProductServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
|
@ -42,6 +45,8 @@ class ProductServiceProvider extends ServiceProvider
|
|||
|
||||
$this->registerCommands();
|
||||
|
||||
$this->registerFacades();
|
||||
|
||||
$this->registerEloquentFactoriesFrom(__DIR__ . '/../Database/Factories');
|
||||
}
|
||||
|
||||
|
|
@ -79,4 +84,56 @@ class ProductServiceProvider extends ServiceProvider
|
|||
{
|
||||
$this->app->make(EloquentFactory::class)->load($path);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Register Bouncer as a singleton.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function registerFacades()
|
||||
{
|
||||
$loader = AliasLoader::getInstance();
|
||||
$loader->alias('productimage', ProductImageFacade::class);
|
||||
|
||||
$this->app->singleton('productimage', function () {
|
||||
return app()->make(ProductImage::class);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Register facade
|
||||
*
|
||||
*/
|
||||
public function registerFacadesd()
|
||||
{
|
||||
//to make the cart facade and bind the
|
||||
//alias to the class needed to be called.
|
||||
// $loader = AliasLoader::getInstance();
|
||||
|
||||
// $loader->alias('productimage', ProductImageFacade::class);
|
||||
|
||||
// $this->app->singleton('productimage', function () {
|
||||
// return new cart();
|
||||
// });
|
||||
|
||||
// $this->app->bind('productimage', 'Webkul\Checkout\Cart');
|
||||
|
||||
|
||||
// \App::bind('mysiteclass', function()
|
||||
// {
|
||||
// return new \Webkul\Product\Helpers\ProductImage;
|
||||
// });
|
||||
|
||||
$this->app->bind('ProductImage', function() {
|
||||
return new ProductImage;
|
||||
});
|
||||
|
||||
// $loader = AliasLoader::getInstance();
|
||||
// $loader->alias('productimage', ProductImageFacade::class);
|
||||
|
||||
// $this->app->singleton('productimage', function () {
|
||||
// return app()->make(ProductImage::class);
|
||||
// });
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue