diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/categories/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/categories/edit.blade.php index c882eb722..9ea6a3062 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/categories/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/categories/edit.blade.php @@ -6,6 +6,7 @@ @section('content')
+ get('locale') ?: app()->getLocale(); ?>
diff --git a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php index 9186cb522..6adba4afc 100755 --- a/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/catalog/products/edit.blade.php @@ -6,6 +6,9 @@ @section('content')
+ get('locale') ?: app()->getLocale(); ?> + get('channel') ?: core()->getDefaultChannelCode(); ?> + {!! view_render_event('bagisto.admin.catalog.product.edit.before', ['product' => $product]) !!} @@ -25,7 +28,7 @@ @foreach (core()->getAllChannels() as $channelModel) @@ -38,7 +41,7 @@ @foreach (core()->getAllLocales() as $localeModel) @@ -111,11 +114,11 @@ $channel_locale = []; if ($attribute->value_per_channel) { - array_push($channel_locale, $channelCode); + array_push($channel_locale, $channel); } if ($attribute->value_per_locale) { - array_push($channel_locale, $localeCode); + array_push($channel_locale, $locale); } ?> diff --git a/packages/Webkul/Category/src/Http/Controllers/CategoryController.php b/packages/Webkul/Category/src/Http/Controllers/CategoryController.php index 5ea2c054e..f5fcbc87d 100755 --- a/packages/Webkul/Category/src/Http/Controllers/CategoryController.php +++ b/packages/Webkul/Category/src/Http/Controllers/CategoryController.php @@ -39,9 +39,8 @@ class CategoryController extends Controller /** * Create a new controller instance. * - * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository - * @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository - * + * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository + * @param \Webkul\Attribute\Repositories\AttributeRepository $attributeRepository * @return void */ public function __construct( @@ -75,7 +74,7 @@ class CategoryController extends Controller { $categories = $this->categoryRepository->getCategoryTree(null, ['id']); - $attributes = $this->attributeRepository->findWhere(['is_filterable' => 1]); + $attributes = $this->attributeRepository->findWhere(['is_filterable' => 1]); return view($this->_config['view'], compact('categories', 'attributes')); } @@ -88,10 +87,10 @@ class CategoryController extends Controller public function store() { $this->validate(request(), [ - 'slug' => ['required', 'unique:category_translations,slug', new \Webkul\Core\Contracts\Validations\Slug], - 'name' => 'required', - 'image.*' => 'mimes:jpeg,jpg,bmp,png', - 'description' => 'required_if:display_mode,==,description_only,products_and_description', + 'slug' => ['required', 'unique:category_translations,slug', new \Webkul\Core\Contracts\Validations\Slug], + 'name' => 'required', + 'image.*' => 'mimes:jpeg,jpg,bmp,png', + 'description' => 'required_if:display_mode,==,description_only,products_and_description' ]); if (strtolower(request()->input('name')) == 'root') { @@ -99,14 +98,14 @@ class CategoryController extends Controller $result = $categoryTransalation->where('name', request()->input('name'))->get(); - if (count($result) > 0) { + if(count($result) > 0) { session()->flash('error', trans('admin::app.response.create-root-failure')); return redirect()->back(); } } - $this->categoryRepository->create(request()->all()); + $category = $this->categoryRepository->create(request()->all()); session()->flash('success', trans('admin::app.response.create-success', ['name' => 'Category'])); @@ -117,7 +116,6 @@ class CategoryController extends Controller * Show the form for editing the specified resource. * * @param int $id - * * @return \Illuminate\View\View */ public function edit($id) @@ -126,25 +124,15 @@ class CategoryController extends Controller $categories = $this->categoryRepository->getCategoryTreeWithoutDescendant($id); - $attributes = $this->attributeRepository->findWhere(['is_filterable' => 1]); + $attributes = $this->attributeRepository->findWhere(['is_filterable' => 1]); - $locale = request()->get('locale') - ?: core()->getDefaultChannel()->default_locale->code - ?: app()->getLocale(); - - return view($this->_config['view'], compact( - 'category', - 'categories', - 'attributes', - 'locale' - )); + return view($this->_config['view'], compact('category', 'categories', 'attributes')); } /** * Update the specified resource in storage. * - * @param int $id - * + * @param int $id * @return \Illuminate\Http\Response */ public function update($id) @@ -158,7 +146,7 @@ class CategoryController extends Controller } }], $locale . '.name' => 'required', - 'image.*' => 'mimes:jpeg,jpg,bmp,png', + 'image.*' => 'mimes:jpeg,jpg,bmp,png' ]); $this->categoryRepository->update(request()->all(), $id); @@ -171,15 +159,14 @@ class CategoryController extends Controller /** * Remove the specified resource from storage. * - * @param int $id - * + * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $category = $this->categoryRepository->findOrFail($id); - if (strtolower($category->name) == "root") { + if(strtolower($category->name) == "root") { session()->flash('warning', trans('admin::app.response.delete-category-root', ['name' => 'Category'])); } else { try { @@ -192,7 +179,7 @@ class CategoryController extends Controller session()->flash('success', trans('admin::app.response.delete-success', ['name' => 'Category'])); return response()->json(['message' => true], 200); - } catch (\Exception $e) { + } catch(\Exception $e) { session()->flash('error', trans('admin::app.response.delete-failed', ['name' => 'Category'])); } } @@ -205,8 +192,7 @@ class CategoryController extends Controller * * @return response \Illuminate\Http\Response */ - public function massDestroy() - { + public function massDestroy() { $suppressFlash = false; if (request()->isMethod('delete') || request()->isMethod('post')) { @@ -219,7 +205,7 @@ class CategoryController extends Controller $this->categoryRepository->delete($value); Event::dispatch('catalog.category.delete.after', $value); - } catch (\Exception $e) { + } catch(\Exception $e) { $suppressFlash = true; continue; diff --git a/packages/Webkul/Core/src/Core.php b/packages/Webkul/Core/src/Core.php index 2e4b1d167..d39459dff 100755 --- a/packages/Webkul/Core/src/Core.php +++ b/packages/Webkul/Core/src/Core.php @@ -135,9 +135,6 @@ class Core 'https://' . request()->getHttpHost(), ])->first(); - if (! $channel) - $channel = $this->channelRepository->findOneByField('code', config('app.channel')); - if (! $channel) $channel = $this->channelRepository->first(); diff --git a/packages/Webkul/Core/src/Models/Channel.php b/packages/Webkul/Core/src/Models/Channel.php index 1908a4872..963418413 100755 --- a/packages/Webkul/Core/src/Models/Channel.php +++ b/packages/Webkul/Core/src/Models/Channel.php @@ -10,19 +10,7 @@ use Webkul\Core\Contracts\Channel as ChannelContract; class Channel extends Model implements ChannelContract { - protected $fillable = [ - 'code', - 'name', - 'description', - 'theme', - 'home_page_content', - 'footer_content', - 'hostname', - 'default_locale_id', - 'base_currency_id', - 'root_category_id', - 'home_seo', - ]; + protected $fillable = ['code', 'name', 'description', 'theme', 'home_page_content', 'footer_content', 'hostname', 'default_locale_id', 'base_currency_id', 'root_category_id', 'home_seo']; /** * Get the channel locales. diff --git a/packages/Webkul/Product/src/Http/Controllers/ProductController.php b/packages/Webkul/Product/src/Http/Controllers/ProductController.php index 7dd76524a..e910a2ae0 100755 --- a/packages/Webkul/Product/src/Http/Controllers/ProductController.php +++ b/packages/Webkul/Product/src/Http/Controllers/ProductController.php @@ -73,13 +73,12 @@ class ProductController extends Controller /** * Create a new controller instance. * - * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository - * @param \Webkul\Product\Repositories\ProductRepository $productRepository - * @param \Webkul\Product\Repositories\ProductDownloadableLinkRepository $productDownloadableLinkRepository - * @param \Webkul\Product\Repositories\ProductDownloadableSampleRepository $productDownloadableSampleRepository - * @param \Webkul\Attribute\Repositories\AttributeFamilyRepository $attributeFamilyRepository - * @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySource - * + * @param \Webkul\Category\Repositories\CategoryRepository $categoryRepository + * @param \Webkul\Product\Repositories\ProductRepository $productRepository + * @param \Webkul\Product\Repositories\ProductDownloadableLinkRepository $productDownloadableLinkRepository + * @param \Webkul\Product\Repositories\ProductDownloadableSampleRepository $productDownloadableSampleRepository + * @param \Webkul\Attribute\Repositories\AttributeFamilyRepository $attributeFamilyRepository + * @param \Webkul\Inventory\Repositories\InventorySourceRepository $inventorySource * @return void */ public function __construct( @@ -150,7 +149,7 @@ class ProductController extends Controller if (ProductType::hasVariants(request()->input('type')) && (! request()->has('super_attributes') - || ! count(request()->get('super_attributes')))) { + || ! count(request()->get('super_attributes')))) { session()->flash('error', trans('admin::app.catalog.products.configurable-error')); @@ -158,9 +157,9 @@ class ProductController extends Controller } $this->validate(request(), [ - 'type' => 'required', + 'type' => 'required', 'attribute_family_id' => 'required', - 'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug], + 'sku' => ['required', 'unique:products,sku', new \Webkul\Core\Contracts\Validations\Slug] ]); $product = $this->productRepository->create(request()->all()); @@ -173,8 +172,7 @@ class ProductController extends Controller /** * Show the form for editing the specified resource. * - * @param int $id - * + * @param int $id * @return \Illuminate\View\View */ public function edit($id) @@ -185,25 +183,14 @@ class ProductController extends Controller $inventorySources = $this->inventorySourceRepository->all(); - $channel = request()->get('channel') ?: core()->getDefaultChannel(); - $channelCode = $channel->code; - $localeCode = request()->get('localeCode') ?: $channel->default_locale->code ?: app()->getLocale(); - - return view($this->_config['view'], compact('product', - 'categories', - 'inventorySources', - 'channel', - 'channelCode', - 'localeCode' - )); + return view($this->_config['view'], compact('product', 'categories', 'inventorySources')); } /** * Update the specified resource in storage. * - * @param \Webkul\Product\Http\Requests\ProductForm $request - * @param int $id - * + * @param \Webkul\Product\Http\Requests\ProductForm $request + * @param int $id * @return \Illuminate\Http\Response */ public function update(ProductForm $request, $id) @@ -218,8 +205,7 @@ class ProductController extends Controller /** * Uploads downloadable file * - * @param int $id - * + * @param int $id * @return \Illuminate\Http\Response */ public function uploadLink($id) @@ -232,8 +218,7 @@ class ProductController extends Controller /** * Uploads downloadable sample file * - * @param int $id - * + * @param int $id * @return \Illuminate\Http\Response */ public function uploadSample($id) @@ -246,8 +231,7 @@ class ProductController extends Controller /** * Remove the specified resource from storage. * - * @param int $id - * + * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) @@ -303,7 +287,7 @@ class ProductController extends Controller return redirect()->back(); } - if (! $data['massaction-type'] == 'update') { + if (!$data['massaction-type'] == 'update') { return redirect()->back(); } @@ -312,8 +296,8 @@ class ProductController extends Controller foreach ($productIds as $productId) { $this->productRepository->update([ 'channel' => null, - 'locale' => null, - 'status' => $data['update-options'], + 'locale' => null, + 'status' => $data['update-options'] ], $productId); } @@ -344,10 +328,10 @@ class ProductController extends Controller foreach ($this->productRepository->searchProductByAttribute(request()->input('query')) as $row) { $results[] = [ - 'id' => $row->product_id, - 'sku' => $row->sku, - 'name' => $row->name, - ]; + 'id' => $row->product_id, + 'sku' => $row->sku, + 'name' => $row->name, + ]; } return response()->json($results); @@ -356,18 +340,17 @@ class ProductController extends Controller } } - /** + /** * Download image or file * - * @param int $productId , $attributeId - * + * @param int $productId, $attributeId * @return \Illuminate\Http\Response */ public function download($productId, $attributeId) { $productAttribute = $this->productAttributeValue->findOneWhere([ 'product_id' => $productId, - 'attribute_id' => $attributeId, + 'attribute_id' => $attributeId ]); return Storage::download($productAttribute['text_value']); diff --git a/packages/Webkul/Product/src/Models/Product.php b/packages/Webkul/Product/src/Models/Product.php index d73e46527..ce9ab9d08 100755 --- a/packages/Webkul/Product/src/Models/Product.php +++ b/packages/Webkul/Product/src/Models/Product.php @@ -2,7 +2,6 @@ namespace Webkul\Product\Models; -use Webkul\Core\Models\Channel; use Illuminate\Database\Eloquent\Model; use Webkul\Attribute\Models\AttributeFamilyProxy; use Webkul\Category\Models\CategoryProxy; @@ -182,8 +181,8 @@ class Product extends Model implements ProductContract public function inventory_source_qty($inventorySourceId) { return $this->inventories() - ->where('inventory_source_id', $inventorySourceId) - ->sum('qty'); + ->where('inventory_source_id', $inventorySourceId) + ->sum('qty'); } /** @@ -244,7 +243,6 @@ class Product extends Model implements ProductContract * * @param Group $group * @param bool $skipSuperAttribute - * * @return Collection */ public function getEditableAttributes($group = null, $skipSuperAttribute = true) @@ -255,8 +253,7 @@ class Product extends Model implements ProductContract /** * Get an attribute from the model. * - * @param string $key - * + * @param string $key * @return mixed */ public function getAttribute($key) @@ -265,9 +262,8 @@ class Product extends Model implements ProductContract if (isset($this->id)) { $this->attributes[$key] = ''; - $attribute = core() - ->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) - ->getAttributeByCode($key); + $attribute = core()->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) + ->getAttributeByCode($key); $this->attributes[$key] = $this->getCustomAttributeValue($attribute); @@ -288,9 +284,8 @@ class Product extends Model implements ProductContract $hiddenAttributes = $this->getHidden(); if (isset($this->id)) { - $familyAttributes = core() - ->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) - ->getFamilyAttributes($this->attribute_family); + $familyAttributes = core()->getSingletonInstance(\Webkul\Attribute\Repositories\AttributeRepository::class) + ->getFamilyAttributes($this->attribute_family); foreach ($familyAttributes as $attribute) { if (in_array($attribute->code, $hiddenAttributes)) { @@ -311,41 +306,24 @@ class Product extends Model implements ProductContract */ public function getCustomAttributeValue($attribute) { - if (! $attribute) { + if (! $attribute) return; - } $channel = request()->get('channel') ?: (core()->getCurrentChannelCode() ?: core()->getDefaultChannelCode()); - $locale = $this->determineLocale($channel); + $locale = request()->get('locale') ?: app()->getLocale(); if ($attribute->value_per_channel) { if ($attribute->value_per_locale) { - $attributeValue = $this - ->attribute_values() - ->where('channel', $channel) - ->where('locale', $locale) - ->where('attribute_id', $attribute->id) - ->first(); + $attributeValue = $this->attribute_values()->where('channel', $channel)->where('locale', $locale)->where('attribute_id', $attribute->id)->first(); } else { - $attributeValue = $this - ->attribute_values() - ->where('channel', $channel) - ->where('attribute_id', $attribute->id) - ->first(); + $attributeValue = $this->attribute_values()->where('channel', $channel)->where('attribute_id', $attribute->id)->first(); } } else { if ($attribute->value_per_locale) { - $attributeValue = $this - ->attribute_values() - ->where('locale', $locale) - ->where('attribute_id', $attribute->id) - ->first(); + $attributeValue = $this->attribute_values()->where('locale', $locale)->where('attribute_id', $attribute->id)->first(); } else { - $attributeValue = $this - ->attribute_values() - ->where('attribute_id', $attribute->id) - ->first(); + $attributeValue = $this->attribute_values()->where('attribute_id', $attribute->id)->first(); } } @@ -355,8 +333,7 @@ class Product extends Model implements ProductContract /** * Overrides the default Eloquent query builder * - * @param \Illuminate\Database\Eloquent\Builder $query - * + * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function newEloquentBuilder($query) @@ -379,24 +356,4 @@ class Product extends Model implements ProductContract { return $this; } - - /** - * Determine if the given channel has a default locale configured. - * If not, return the channel given in the request. - * If none given, return the fallback channel given in the application configuration - * - * @param string $channel - * - * @return string - */ - private function determineLocale(string $channel): string - { - $channelModel = Channel::where(['code' => $channel])->first(); - - if ($channelModel) { - return $channelModel->default_locale->code; - } - - return request()->get('locale') ?: app()->getLocale(); - } } \ No newline at end of file