diff --git a/packages/Webkul/Admin/src/Database/Factories/ThemeFactory.php b/packages/Webkul/Admin/src/Database/Factories/ThemeFactory.php index 2bfc37fbf02..b811de50d7d 100644 --- a/packages/Webkul/Admin/src/Database/Factories/ThemeFactory.php +++ b/packages/Webkul/Admin/src/Database/Factories/ThemeFactory.php @@ -19,14 +19,12 @@ class ThemeFactory extends Factory */ public function definition() { - $lastTheme = ThemeCustomizationModel::query()->orderBy('id', 'desc')->limit(1)->first(); - - $types = ['product_carousel', 'category_carousel', 'image_carousel', 'footer_links', 'services_content']; + $types = ['product_carousel', 'category_carousel', 'image_carousel', 'footer_links', 'services_content', 'static_content']; return [ 'type' => $this->faker->randomElement($types), 'name' => $this->faker->name, - 'sort_order' => ($lastTheme ? $lastTheme->id : 0) + 1, + 'sort_order' => 1, 'channel_id' => core()->getCurrentChannel()->id, ]; } diff --git a/packages/Webkul/Admin/src/Http/Controllers/Catalog/ProductController.php b/packages/Webkul/Admin/src/Http/Controllers/Catalog/ProductController.php index 81b4bdbb032..538667be256 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Catalog/ProductController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Catalog/ProductController.php @@ -331,9 +331,11 @@ public function search() 'name' => request('query'), 'sort' => 'created_at', 'order' => 'desc', + 'path' => request()->url(), + 'query_data' => request()->query(), ]); - $products = $this->productRepository->searchFromDatabase(); + $products = $this->productRepository->searchFromDatabase(request()->input()); foreach ($products as $product) { $results[] = [ diff --git a/packages/Webkul/Admin/src/Http/Controllers/Settings/ChannelController.php b/packages/Webkul/Admin/src/Http/Controllers/Settings/ChannelController.php index 7ec7f39f842..a012140a3b3 100755 --- a/packages/Webkul/Admin/src/Http/Controllers/Settings/ChannelController.php +++ b/packages/Webkul/Admin/src/Http/Controllers/Settings/ChannelController.php @@ -67,8 +67,10 @@ public function store() /* design */ 'theme' => 'nullable', - 'logo.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp', - 'favicon.*' => 'nullable|mimes:bmp,jpeg,jpg,png,webp,ico', + 'logo' => 'array', + 'logo.*' => 'image|mimes:bmp,jpeg,jpg,png,webp', + 'favicon' => 'array', + 'favicon.*' => 'image|mimes:bmp,jpeg,jpg,png,webp,ico', /* seo */ 'seo_title' => 'required|string', diff --git a/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php b/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php index 23bd1f94875..bccd20c1f0f 100755 --- a/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php +++ b/packages/Webkul/Admin/src/Resources/views/configuration/field-type.blade.php @@ -461,4 +461,4 @@ class="block leading-5 text-xs text-gray-600 dark:text-gray-300 font-medium" }); @endPushOnce -@endif +@endif \ No newline at end of file diff --git a/packages/Webkul/Admin/tests/Feature/Catalog/AttributeFamilyTest.php b/packages/Webkul/Admin/tests/Feature/Catalog/AttributeFamilyTest.php index 3e65ee64b90..8d4df201efb 100644 --- a/packages/Webkul/Admin/tests/Feature/Catalog/AttributeFamilyTest.php +++ b/packages/Webkul/Admin/tests/Feature/Catalog/AttributeFamilyTest.php @@ -49,7 +49,7 @@ $this->loginAsAdmin(); postJson(route('admin.catalog.families.store'), [ - 'code' => $code = strtolower(fake()->words(1, true)), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $name = fake()->name(), 'attribute_groups' => [ [ @@ -116,7 +116,7 @@ $this->loginAsAdmin(); putJson(route('admin.catalog.families.update', $attributeFamily->id), [ - 'code' => $updatedCode = strtolower(fake()->words(1, true)), + 'code' => $updatedCode = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $attributeFamily->name, ]) ->assertRedirectToRoute('admin.catalog.families.index') diff --git a/packages/Webkul/Admin/tests/Feature/Catalog/AttributeTest.php b/packages/Webkul/Admin/tests/Feature/Catalog/AttributeTest.php index 67205832e99..5d3528d9ab5 100644 --- a/packages/Webkul/Admin/tests/Feature/Catalog/AttributeTest.php +++ b/packages/Webkul/Admin/tests/Feature/Catalog/AttributeTest.php @@ -30,8 +30,7 @@ ]) ->assertOk() ->assertJsonPath('records.0.id', $attribute->id) - ->assertJsonPath('records.0.code', $attribute->code) - ->assertJsonPath('meta.total', 29); + ->assertJsonPath('records.0.code', $attribute->code); }); it('should returns attributes options', function () { @@ -73,7 +72,7 @@ postJson(route('admin.catalog.attributes.store'), [ 'admin_name' => $name = fake()->name(), - 'code' => $code = strtolower(fake()->word()), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'type' => 'text', 'default_value' => 1, ]) diff --git a/packages/Webkul/Admin/tests/Feature/Catalog/CategoryTest.php b/packages/Webkul/Admin/tests/Feature/Catalog/CategoryTest.php index 11ee90fb4f5..d54bb9b79e3 100644 --- a/packages/Webkul/Admin/tests/Feature/Catalog/CategoryTest.php +++ b/packages/Webkul/Admin/tests/Feature/Catalog/CategoryTest.php @@ -1,5 +1,6 @@ rand(1, 5), 'description' => $description = substr(fake()->paragraph(), 0, 50), 'attributes' => $attributes, + 'logo_path' => [ + UploadedFile::fake()->image('logo_path.jpg'), + ], + 'banner_path' => [ + UploadedFile::fake()->image('banner_path.jpg'), + ], ]) ->assertRedirect(route('admin.catalog.categories.index')) ->isRedirection(); @@ -186,9 +193,15 @@ 'description' => $description = substr(fake()->paragraph(), 0, 50), ], - 'locale' => config('app.locale'), - 'attributes' => $attributes, - 'position' => rand(1, 5), + 'locale' => config('app.locale'), + 'attributes' => $attributes, + 'position' => rand(1, 5), + 'logo_path' => [ + UploadedFile::fake()->image('logo_path.jpg'), + ], + 'banner_path' => [ + UploadedFile::fake()->image('banner_path.jpg'), + ], ]) ->assertRedirect(route('admin.catalog.categories.index')) ->isRedirection(); diff --git a/packages/Webkul/Admin/tests/Feature/Customers/CustomerGroupsTest.php b/packages/Webkul/Admin/tests/Feature/Customers/CustomerGroupsTest.php index f6ecb5e3db0..4ad417febaa 100644 --- a/packages/Webkul/Admin/tests/Feature/Customers/CustomerGroupsTest.php +++ b/packages/Webkul/Admin/tests/Feature/Customers/CustomerGroupsTest.php @@ -32,7 +32,7 @@ $this->loginAsAdmin(); postJson(route('admin.customers.groups.store'), [ - 'code' => $code = strtolower(fake()->words(1, true)), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $name = fake()->name(), ]) ->assertOk() diff --git a/packages/Webkul/Admin/tests/Feature/Settings/ChannelsTest.php b/packages/Webkul/Admin/tests/Feature/Settings/ChannelsTest.php index 669dc1a98dc..ade52f2448b 100644 --- a/packages/Webkul/Admin/tests/Feature/Settings/ChannelsTest.php +++ b/packages/Webkul/Admin/tests/Feature/Settings/ChannelsTest.php @@ -1,5 +1,6 @@ assertUnprocessable(); }); +it('should not store the new channel if the file has been tampered with', function () { + // Act and Assert + $this->loginAsAdmin(); + + postJson(route('admin.settings.channels.store'), [ + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), + 'theme' => $code, + 'hostname' => 'http://'.fake()->ipv4(), + 'root_category_id' => 1, + 'default_locale_id' => 1, + 'base_currency_id' => 1, + 'name' => fake()->name(), + 'description' => substr(fake()->paragraph, 0, 50), + 'inventory_sources' => [1], + 'locales' => [1], + 'currencies' => [1], + 'seo_title' => fake()->title(), + 'seo_description' => substr(fake()->paragraph(), 0, 50), + 'seo_keywords' => fake()->name(), + 'is_maintenance_on' => fake()->boolean(), + 'logo' => [ + UploadedFile::fake()->image('tampered1.php'), + ], + 'favicon' => [ + UploadedFile::fake()->image('tampered2.php'), + ], + ]) + ->assertJsonValidationErrorFor('logo.0') + ->assertJsonValidationErrorFor('favicon.0') + ->assertUnprocessable(); +}); + it('should store the newly created channels', function () { // Act and Assert $this->loginAsAdmin(); @@ -66,6 +99,12 @@ 'seo_description' => substr(fake()->paragraph(), 0, 50), 'seo_keywords' => fake()->name(), 'is_maintenance_on' => fake()->boolean(), + 'logo' => [ + UploadedFile::fake()->image('logo.png'), + ], + 'favicon' => [ + UploadedFile::fake()->image('favicon.png'), + ], ]) ->assertRedirect(route('admin.settings.channels.index')) ->isRedirection(); @@ -142,6 +181,12 @@ 'locales' => [1], 'currencies' => [1], 'is_maintenance_on' => fake()->boolean(), + 'logo' => [ + UploadedFile::fake()->image('logo.png'), + ], + 'favicon' => [ + UploadedFile::fake()->image('favicon.png'), + ], ]) ->assertRedirect(route('admin.settings.channels.index')) ->isRedirection(); diff --git a/packages/Webkul/Admin/tests/Feature/Settings/InventorySourcesTest.php b/packages/Webkul/Admin/tests/Feature/Settings/InventorySourcesTest.php index 855af39ca52..af811e335c2 100644 --- a/packages/Webkul/Admin/tests/Feature/Settings/InventorySourcesTest.php +++ b/packages/Webkul/Admin/tests/Feature/Settings/InventorySourcesTest.php @@ -50,7 +50,7 @@ $this->loginAsAdmin(); postJson(route('admin.settings.inventory_sources.store'), [ - 'code' => $code = strtolower(fake()->word), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $name = fake()->name(), 'priority' => $priority = rand(1, 10), 'contact_number' => $contactNumber = rand(1111111111, 9999999999), diff --git a/packages/Webkul/Admin/tests/Feature/Settings/TaxCategoriesTest.php b/packages/Webkul/Admin/tests/Feature/Settings/TaxCategoriesTest.php index 50b0043c835..7db5807b727 100644 --- a/packages/Webkul/Admin/tests/Feature/Settings/TaxCategoriesTest.php +++ b/packages/Webkul/Admin/tests/Feature/Settings/TaxCategoriesTest.php @@ -35,7 +35,7 @@ $this->loginAsAdmin(); postJson(route('admin.settings.taxes.categories.store'), [ - 'code' => $code = fake()->uuid(), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $name = fake()->words(2, true), 'description' => $description = fake()->sentence(10), 'taxrates' => TaxRate::factory()->count(2)->create()->pluck('id')->toArray(), @@ -94,7 +94,7 @@ putJson(route('admin.settings.taxes.categories.update'), [ 'id' => $taxCategory->id, - 'code' => $code = fake()->uuid(), + 'code' => $code = fake()->regexify('/^[a-zA-Z]+[a-zA-Z0-9_]+$/'), 'name' => $name = fake()->words(2, true), 'description' => $description = fake()->sentence(10), 'taxrates' => TaxRate::factory()->count(2)->create()->pluck('id')->toArray(), diff --git a/packages/Webkul/Admin/tests/Feature/Settings/ThemeTest.php b/packages/Webkul/Admin/tests/Feature/Settings/ThemeTest.php index b20a76532e8..92ced6e2c39 100644 --- a/packages/Webkul/Admin/tests/Feature/Settings/ThemeTest.php +++ b/packages/Webkul/Admin/tests/Feature/Settings/ThemeTest.php @@ -158,6 +158,16 @@ ], ]; + break; + + case ThemeCustomization::STATIC_CONTENT: + $data[app()->getLocale()] = [ + 'options' => [ + 'html' => fake()->randomHtml(), + 'css' => '', + ], + ]; + break; } diff --git a/packages/Webkul/Category/src/Repositories/CategoryRepository.php b/packages/Webkul/Category/src/Repositories/CategoryRepository.php index 8e9f4c12a48..89d3b2f19c0 100755 --- a/packages/Webkul/Category/src/Repositories/CategoryRepository.php +++ b/packages/Webkul/Category/src/Repositories/CategoryRepository.php @@ -2,6 +2,9 @@ namespace Webkul\Category\Repositories; +use Illuminate\Database\Eloquent\Collection; +use Illuminate\Http\UploadedFile; +use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; @@ -22,10 +25,8 @@ public function model(): string /** * Get categories. - * - * @return void */ - public function getAll(array $params = []) + public function getAll(array $params = []): LengthAwarePaginator { $queryBuilder = $this->query() ->leftJoin('category_translations', 'category_translations.category_id', '=', 'categories.id'); @@ -64,19 +65,15 @@ public function getAll(array $params = []) /** * Create category. - * - * @return \Webkul\Category\Contracts\Category */ - public function create(array $data) + public function create(array $data): Category { if ( isset($data['locale']) && $data['locale'] == 'all' ) { - $model = app()->make($this->model()); - foreach (core()->getAllLocales() as $locale) { - foreach ($model->translatedAttributes as $attribute) { + foreach ($this->getModel()->translatedAttributes as $attribute) { if (isset($data[$attribute])) { $data[$locale->code][$attribute] = $data[$attribute]; @@ -86,7 +83,7 @@ public function create(array $data) } } - $category = $this->model->create($data); + $category = $this->getModel()->create($data); $this->uploadImages($data, $category); @@ -127,71 +124,54 @@ public function update(array $data, $id, $attribute = 'id') /** * Specify category tree. - * - * @param int $id - * @return \Webkul\Category\Contracts\Category */ - public function getCategoryTree($id = null) + public function getCategoryTree(?int $id = null): Collection { return $id - ? $this->model::orderBy('position', 'ASC')->where('id', '!=', $id)->get()->toTree() - : $this->model::orderBy('position', 'ASC')->get()->toTree(); + ? $this->getModel()::orderBy('position', 'ASC')->where('id', '!=', $id)->get()->toTree() + : $this->getModel()::orderBy('position', 'ASC')->get()->toTree(); } /** * Specify category tree. - * - * @param int $id - * @return \Illuminate\Support\Collection */ - public function getCategoryTreeWithoutDescendant($id = null) + public function getCategoryTreeWithoutDescendant(?int $id = null): Collection { return $id - ? $this->model::orderBy('position', 'ASC')->where('id', '!=', $id)->whereNotDescendantOf($id)->get()->toTree() - : $this->model::orderBy('position', 'ASC')->get()->toTree(); + ? $this->getModel()::orderBy('position', 'ASC')->where('id', '!=', $id)->whereNotDescendantOf($id)->get()->toTree() + : $this->getModel()::orderBy('position', 'ASC')->get()->toTree(); } /** * Get root categories. - * - * @return \Illuminate\Support\Collection */ - public function getRootCategories() + public function getRootCategories(): Collection { return $this->getModel()->where('parent_id', null)->get(); } /** * Get child categories. - * - * @return \Illuminate\Support\Collection */ - public function getChildCategories($parentId) + public function getChildCategories($parentId): Collection { return $this->getModel()->where('parent_id', $parentId)->get(); } /** * get visible category tree. - * - * @param int $id - * @return \Illuminate\Support\Collection */ - public function getVisibleCategoryTree($id = null) + public function getVisibleCategoryTree(?int $id = null): Collection { return $id - ? $this->model::orderBy('position', 'ASC')->where('status', 1)->descendantsAndSelf($id)->toTree($id) - : $this->model::orderBy('position', 'ASC')->where('status', 1)->get()->toTree(); + ? $this->getModel()::orderBy('position', 'ASC')->where('status', 1)->descendantsAndSelf($id)->toTree($id) + : $this->getModel()::orderBy('position', 'ASC')->where('status', 1)->get()->toTree(); } /** * Checks slug is unique or not based on locale. - * - * @param int $id - * @param string $slug - * @return bool */ - public function isSlugUnique($id, $slug) + public function isSlugUnique(int $id, string $slug): bool { $exists = CategoryTranslationProxy::modelClass()::where('category_id', '<>', $id) ->where('slug', $slug) @@ -205,65 +185,54 @@ public function isSlugUnique($id, $slug) /** * Retrieve category from slug. * - * @param string $slug - * @return \Webkul\Category\Contracts\Category + * @return \Webkul\Category\Contracts\Category|void */ - public function findBySlug($slug) + public function findBySlug(string $slug) { - if ($category = $this->model->whereTranslation('slug', $slug)->first()) { + if ($category = $this->getModel()->whereTranslation('slug', $slug)->first()) { return $category; } } /** * Retrieve category from slug. - * - * @param string $slug - * @return \Webkul\Category\Contracts\Category */ - public function findBySlugOrFail($slug) + public function findBySlugOrFail(string $slug): Category { - return $this->model->whereTranslation('slug', $slug)->firstOrFail(); + return $this->getModel()->whereTranslation('slug', $slug)->firstOrFail(); } /** * Upload category's images. - * - * @param array $data - * @param \Webkul\Category\Contracts\Category $category - * @param string $type - * @return void */ - public function uploadImages($data, $category, $type = 'logo_path') + public function uploadImages(array $data, Category $category, string $type = 'logo_path'): void { - if (isset($data[$type])) { - foreach ($data[$type] as $imageId => $image) { - $file = $type.'.'.$imageId; - - $dir = 'category/'.$category->id; - - if (request()->hasFile($file)) { - if ($category->{$type}) { - Storage::delete($category->{$type}); - } - - $manager = new ImageManager(); + if (empty($data[$type])) { + if ($category->{$type}) { + Storage::delete($category->{$type}); + } - $image = $manager->make(request()->file($file))->encode('webp'); + $category->{$type} = null; - $category->{$type} = 'category/'.$category->id.'/'.Str::random(40).'.webp'; + $category->save(); - Storage::put($category->{$type}, $image); + return; + } - $category->save(); - } + foreach ($data[$type] as $image) { + if (! $image instanceof UploadedFile) { + continue; } - } else { + if ($category->{$type}) { Storage::delete($category->{$type}); } - $category->{$type} = null; + $image = (new ImageManager())->make($image)->encode('webp'); + + $category->{$type} = 'category/'.$category->id.'/'.Str::uuid()->toString().'.webp'; + + Storage::put($category->{$type}, $image); $category->save(); } @@ -277,7 +246,7 @@ public function uploadImages($data, $category, $type = 'logo_path') */ public function getPartial($columns = null) { - $categories = $this->model->all(); + $categories = $this->getModel()->all(); $trimmed = []; @@ -307,12 +276,10 @@ private function setSameAttributeValueToAllLocale(array $data, ...$attributeName { $requestedLocale = core()->getRequestedLocaleCode(); - $model = app()->make($this->model()); - foreach ($attributeNames as $attributeName) { foreach (core()->getAllLocales() as $locale) { if ($requestedLocale == $locale->code) { - foreach ($model->translatedAttributes as $attribute) { + foreach ($this->getModel()->translatedAttributes as $attribute) { if ($attribute === $attributeName) { $data[$locale->code][$attribute] = $data[$requestedLocale][$attribute] ?? $data[$data['locale']][$attribute]; } diff --git a/packages/Webkul/Core/src/Repositories/ChannelRepository.php b/packages/Webkul/Core/src/Repositories/ChannelRepository.php index c4b2e3e2fbb..94464098eec 100755 --- a/packages/Webkul/Core/src/Repositories/ChannelRepository.php +++ b/packages/Webkul/Core/src/Repositories/ChannelRepository.php @@ -2,7 +2,11 @@ namespace Webkul\Core\Repositories; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; +use Intervention\Image\ImageManager; +use Webkul\Core\Contracts\Channel; use Webkul\Core\Eloquent\Repository; class ChannelRepository extends Repository @@ -12,21 +16,16 @@ class ChannelRepository extends Repository */ public function model(): string { - return 'Webkul\Core\Contracts\Channel'; + return Channel::class; } /** - * Create. - * - * @return \Webkul\Core\Contracts\Channel + * Create channel. */ - public function create(array $data) + public function create(array $data): Channel { - - $model = $this->getModel(); - foreach (core()->getAllLocales() as $locale) { - foreach ($model->translatedAttributes as $attribute) { + foreach ($this->getModel()->translatedAttributes as $attribute) { if (isset($data[$attribute])) { $data[$locale->code][$attribute] = $data[$attribute]; } @@ -49,13 +48,12 @@ public function create(array $data) } /** - * Update. + * Update the channel. * * @param int $id * @param string $attribute - * @return \Webkul\Core\Contracts\Channel */ - public function update(array $data, $id, $attribute = 'id') + public function update(array $data, $id, $attribute = 'id'): Channel { $channel = parent::update($data, $id, $attribute); @@ -74,28 +72,37 @@ public function update(array $data, $id, $attribute = 'id') /** * Upload images. - * - * @param array $data - * @param \Webkul\Core\Contracts\Channel $channel - * @param string $type - * @return void */ - public function uploadImages($data, $channel, $type = 'logo') + public function uploadImages(array $data, Channel $channel, string $type = 'logo'): void { - if (request()->hasFile($type)) { - $channel->{$type} = current(request()->file($type))->store('channel/'.$channel->id); + if (empty($data[$type])) { + if ($channel->{$type}) { + Storage::delete($channel->{$type}); + } + + $channel->{$type} = null; $channel->save(); - } else { - if (! isset($data[$type])) { - if (! empty($data[$type])) { - Storage::delete($channel->{$type}); - } - $channel->{$type} = null; + return; + } - $channel->save(); + foreach ($data[$type] as $image) { + if (! $image instanceof UploadedFile) { + continue; } + + if ($channel->{$type}) { + Storage::delete($channel->{$type}); + } + + $image = (new ImageManager())->make($image)->encode('webp'); + + $channel->{$type} = 'channel/'.$channel->id.'/'.Str::uuid()->toString().'.webp'; + + Storage::put($channel->{$type}, $image); + + $channel->save(); } } } diff --git a/packages/Webkul/Core/src/Repositories/CoreConfigRepository.php b/packages/Webkul/Core/src/Repositories/CoreConfigRepository.php index bf3af11adaf..e18ada80b2a 100755 --- a/packages/Webkul/Core/src/Repositories/CoreConfigRepository.php +++ b/packages/Webkul/Core/src/Repositories/CoreConfigRepository.php @@ -2,10 +2,12 @@ namespace Webkul\Core\Repositories; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; +use Webkul\Core\Contracts\CoreConfig; use Webkul\Core\Eloquent\Repository; use Webkul\Core\Traits\CoreConfigField; @@ -18,15 +20,13 @@ class CoreConfigRepository extends Repository */ public function model(): string { - return 'Webkul\Core\Contracts\CoreConfig'; + return CoreConfig::class; } /** - * Create. - * - * @return \Webkul\Core\Contracts\CoreConfig + * Create the core configuration. */ - public function create(array $data) + public function create(array $data): void { Event::dispatch('core.configuration.save.before'); @@ -84,8 +84,8 @@ public function create(array $data) } } - if (request()->hasFile($fieldName)) { - $value = request()->file($fieldName)->store('configuration'); + if ($hasFile = $value instanceof UploadedFile) { + $value = $value->store('configuration'); } if (! count($coreConfigValue)) { @@ -97,12 +97,12 @@ public function create(array $data) ]); } else { foreach ($coreConfigValue as $coreConfig) { - if (request()->hasFile($fieldName)) { - Storage::delete($coreConfig['value']); + if ($hasFile) { + Storage::delete($coreConfig->value); } if (isset($value['delete'])) { - parent::delete($coreConfig['id']); + parent::delete($coreConfig->id); } else { parent::update([ 'code' => $fieldName, diff --git a/packages/Webkul/Customer/src/Repositories/CustomerRepository.php b/packages/Webkul/Customer/src/Repositories/CustomerRepository.php index d4ee29261b2..6beb6dea33f 100755 --- a/packages/Webkul/Customer/src/Repositories/CustomerRepository.php +++ b/packages/Webkul/Customer/src/Repositories/CustomerRepository.php @@ -3,7 +3,10 @@ namespace Webkul\Customer\Repositories; use Carbon\Carbon; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Str; +use Intervention\Image\ImageManager; use Webkul\Core\Eloquent\Repository; use Webkul\Sales\Models\Order; @@ -71,28 +74,30 @@ public function checkBulkCustomerIfTheyHaveOrderPendingOrProcessing($customerIds */ public function uploadImages($data, $customer, $type = 'image') { - if (isset($data[$type])) { - $request = request(); - - foreach ($data[$type] as $imageId => $image) { - $file = $type.'.'.$imageId; - $dir = 'customer/'.$customer->id; + if (empty($data[$type])) { + if ($customer->{$type}) { + Storage::delete($customer->{$type}); + } - if ($request->hasFile($file)) { - if ($customer->{$type}) { - Storage::delete($customer->{$type}); - } + $customer->{$type} = null; + $customer->save(); + } - $customer->{$type} = $request->file($file)->store($dir); - $customer->save(); - } + foreach ($data[$type] as $image) { + if (! $image instanceof UploadedFile) { + continue; } - } else { + if ($customer->{$type}) { Storage::delete($customer->{$type}); } - $customer->{$type} = null; + $image = (new ImageManager())->make($image)->encode('webp'); + + $customer->{$type} = 'customer/'.$customer->id.'/'.Str::uuid()->toString().'.webp'; + + Storage::put($customer->{$type}, $image); + $customer->save(); } } diff --git a/packages/Webkul/Product/src/Repositories/ElasticSearchRepository.php b/packages/Webkul/Product/src/Repositories/ElasticSearchRepository.php index 9e86f861256..068538326a7 100755 --- a/packages/Webkul/Product/src/Repositories/ElasticSearchRepository.php +++ b/packages/Webkul/Product/src/Repositories/ElasticSearchRepository.php @@ -38,9 +38,9 @@ public function getIndexName() * @param array $options * @return array */ - public function search($categoryId, $options) + public function search($categoryId, $options, $params) { - $filters = $this->getFilters(); + $filters = $this->getFilters($params); if ($categoryId) { $filters['filter'][]['term']['category_ids'] = $categoryId; @@ -74,10 +74,8 @@ public function search($categoryId, $options) * * @return void */ - public function getFilters() + public function getFilters(array $params) { - $params = request()->input(); - if (! empty($params['query'])) { $params['name'] = $params['query']; } @@ -183,6 +181,12 @@ public function getSortOptions($options) $sort = 'price_'.$customerGroup->id; } + if ($options['sort'] == 'price') { + $customerGroup = $this->customerRepository->getCurrentGroup(); + + $sort = 'price_'.$customerGroup->id; + } + if ($options['sort'] == 'name') { $sort .= '.keyword'; } diff --git a/packages/Webkul/Product/src/Repositories/ProductDownloadableLinkRepository.php b/packages/Webkul/Product/src/Repositories/ProductDownloadableLinkRepository.php index d32c36e2aa2..ee7eab7cfff 100755 --- a/packages/Webkul/Product/src/Repositories/ProductDownloadableLinkRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductDownloadableLinkRepository.php @@ -2,9 +2,11 @@ namespace Webkul\Product\Repositories; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\Product; class ProductDownloadableLinkRepository extends Repository { @@ -17,23 +19,19 @@ public function model(): string } /** - * Upload. - * - * @param array $data - * @param int $productId - * @return array + * Upload files related to downloadable products */ - public function upload($data, $productId) + public function upload(array $data, int $productId): array { foreach ($data as $type => $file) { - if (! request()->hasFile($type)) { + if (! $file instanceof UploadedFile) { continue; } return [ - $type => $path = request()->file($type)->store('product_downloadable_links/'.$productId, 'private'), - $type.'_name' => $file->getClientOriginalName(), - $type.'_url' => Storage::url($path), + $type => $path = $file->store('product_downloadable_links/'.$productId, 'private'), + $type.'_name' => $file->getClientOriginalName(), + $type.'_url' => Storage::url($path), ]; } @@ -42,11 +40,8 @@ public function upload($data, $productId) /** * Save links. - * - * @param \Webkul\Product\Models\Product $product - * @return void */ - public function saveLinks(array $data, $product) + public function saveLinks(array $data, Product $product): void { $previousLinkIds = $product->downloadable_links()->pluck('id'); diff --git a/packages/Webkul/Product/src/Repositories/ProductDownloadableSampleRepository.php b/packages/Webkul/Product/src/Repositories/ProductDownloadableSampleRepository.php index 5ce6d06c83c..40c629aa4d9 100755 --- a/packages/Webkul/Product/src/Repositories/ProductDownloadableSampleRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductDownloadableSampleRepository.php @@ -2,43 +2,46 @@ namespace Webkul\Product\Repositories; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Str; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\Product; +use Webkul\Product\Contracts\ProductDownloadableSample; class ProductDownloadableSampleRepository extends Repository { /** - * Specify Model class name + * Specify Model class name. */ public function model(): string { - return 'Webkul\Product\Contracts\ProductDownloadableSample'; + return ProductDownloadableSample::class; } /** - * @param array $data - * @param int $productId - * @return mixed + * Upload files related to downloadable products */ - public function upload($data, $productId) + public function upload(array $data, int $productId): array { - if (! request()->hasFile('file')) { + if ( + ! empty($data['file']) + && ! $data['file'] instanceof UploadedFile + ) { return []; } return [ - 'file' => $path = request()->file('file')->store('product_downloadable_links/'.$productId), - 'file_name' => request()->file('file')->getClientOriginalName(), + 'file' => $path = $data['file']->store('product_downloadable_links/'.$productId), + 'file_name' => $data['file']->getClientOriginalName(), 'file_url' => Storage::url($path), ]; } /** - * @param Webkul\Product\Contracts\Product $product - * @return void + * Save samples. */ - public function saveSamples(array $data, $product) + public function saveSamples(array $data, Product $product): void { $previousSampleIds = $product->downloadable_samples()->pluck('id'); diff --git a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php index 978037afbce..8b46005077e 100644 --- a/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductFlatRepository.php @@ -5,6 +5,7 @@ use Illuminate\Support\Facades\DB; use Webkul\Attribute\Models\Attribute; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\ProductFlat; class ProductFlatRepository extends Repository { @@ -13,17 +14,15 @@ class ProductFlatRepository extends Repository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductFlat'; + return ProductFlat::class; } /** * Update `product_flat` custom column. - * - * @return mixed */ - public function updateAttributeColumn(Attribute $attribute) + public function updateAttributeColumn(Attribute $attribute): mixed { - return $this->model + return $this->getModel() ->leftJoin('product_attribute_values as v', function ($join) use ($attribute) { $join->on('product_flat.id', '=', 'v.product_id') ->on('v.attribute_id', '=', DB::raw($attribute->id)); diff --git a/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php index af4bf8c0dbc..4ca309a74ff 100644 --- a/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductGroupedProductRepository.php @@ -4,6 +4,8 @@ use Illuminate\Support\Str; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\Product; +use Webkul\Product\Contracts\ProductGroupedProduct; class ProductGroupedProductRepository extends Repository { @@ -12,15 +14,13 @@ class ProductGroupedProductRepository extends Repository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductGroupedProduct'; + return ProductGroupedProduct::class; } /** - * @param array $data - * @param \Webkul\Product\Contracts\Product $product - * @return void + * Save grouped products. */ - public function saveGroupedProducts($data, $product) + public function saveGroupedProducts(array $data, Product $product): void { $previousGroupedProductIds = $product->grouped_products()->pluck('id'); diff --git a/packages/Webkul/Product/src/Repositories/ProductImageRepository.php b/packages/Webkul/Product/src/Repositories/ProductImageRepository.php index 2d57a016a8c..3f5f4c2943f 100755 --- a/packages/Webkul/Product/src/Repositories/ProductImageRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductImageRepository.php @@ -3,6 +3,8 @@ namespace Webkul\Product\Repositories; use Illuminate\Container\Container; +use Webkul\Product\Contracts\Product; +use Webkul\Product\Contracts\ProductImage; class ProductImageRepository extends ProductMediaRepository { @@ -23,16 +25,13 @@ public function __construct( */ public function model(): string { - return 'Webkul\Product\Contracts\ProductImage'; + return ProductImage::class; } /** * Upload images. - * - * @param array $data - * @param \Webkul\Product\Models\Product $product */ - public function uploadImages($data, $product): void + public function uploadImages($data, Product $product): void { $this->upload($data, $product, 'images'); @@ -43,10 +42,8 @@ public function uploadImages($data, $product): void /** * Upload variant images. - * - * @param array $variants */ - public function uploadVariantImages($variants): void + public function uploadVariantImages(array $variants): void { foreach ($variants as $variantsId => $variantData) { $product = $this->productRepository->find($variantsId); diff --git a/packages/Webkul/Product/src/Repositories/ProductInventoryIndexRepository.php b/packages/Webkul/Product/src/Repositories/ProductInventoryIndexRepository.php index 083b685b05e..54dd475f651 100644 --- a/packages/Webkul/Product/src/Repositories/ProductInventoryIndexRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductInventoryIndexRepository.php @@ -3,6 +3,7 @@ namespace Webkul\Product\Repositories; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\ProductInventoryIndex; class ProductInventoryIndexRepository extends Repository { @@ -11,6 +12,6 @@ class ProductInventoryIndexRepository extends Repository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductInventoryIndex'; + return ProductInventoryIndex::class; } } diff --git a/packages/Webkul/Product/src/Repositories/ProductInventoryRepository.php b/packages/Webkul/Product/src/Repositories/ProductInventoryRepository.php index 84a74bbdb46..43818fb8c73 100755 --- a/packages/Webkul/Product/src/Repositories/ProductInventoryRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductInventoryRepository.php @@ -3,6 +3,8 @@ namespace Webkul\Product\Repositories; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\Product; +use Webkul\Product\Contracts\ProductInventory; class ProductInventoryRepository extends Repository { @@ -11,14 +13,13 @@ class ProductInventoryRepository extends Repository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductInventory'; + return ProductInventory::class; } /** - * @param Webkul\Product\Contracts\Product $product - * @return void + * Save inventories. */ - public function saveInventories(array $data, $product) + public function saveInventories(array $data, Product $product): void { if (! isset($data['inventories'])) { return; diff --git a/packages/Webkul/Product/src/Repositories/ProductMediaRepository.php b/packages/Webkul/Product/src/Repositories/ProductMediaRepository.php index 1cbf3f97545..5fd84356196 100644 --- a/packages/Webkul/Product/src/Repositories/ProductMediaRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductMediaRepository.php @@ -8,6 +8,7 @@ use Illuminate\Support\Str; use Intervention\Image\ImageManager; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\Product; class ProductMediaRepository extends Repository { @@ -28,21 +29,16 @@ public function model() /** * Get product directory. - * - * @param \Webkul\Product\Contracts\Product $product */ - public function getProductDirectory($product): string + public function getProductDirectory(Product $product): string { return 'product/'.$product->id; } /** * Upload. - * - * @param array $data - * @param \Webkul\Product\Contracts\Product $product */ - public function upload($data, $product, string $uploadFileType): void + public function upload(array $data, Product $product, string $uploadFileType): void { /** * Previous model ids for filtering. @@ -98,12 +94,9 @@ public function upload($data, $product, string $uploadFileType): void /** * Resolve file type query builder. * - * @param \Webkul\Product\Contracts\Product $product - * @return mixed - * * @throws \Exception */ - private function resolveFileTypeQueryBuilder($product, string $uploadFileType) + private function resolveFileTypeQueryBuilder(Product $product, string $uploadFileType): mixed { if ($uploadFileType === 'images') { return $product->images(); diff --git a/packages/Webkul/Product/src/Repositories/ProductPriceIndexRepository.php b/packages/Webkul/Product/src/Repositories/ProductPriceIndexRepository.php index be362e3ad83..3b0ed006749 100644 --- a/packages/Webkul/Product/src/Repositories/ProductPriceIndexRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductPriceIndexRepository.php @@ -3,6 +3,7 @@ namespace Webkul\Product\Repositories; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\ProductPriceIndex; class ProductPriceIndexRepository extends Repository { @@ -11,6 +12,6 @@ class ProductPriceIndexRepository extends Repository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductPriceIndex'; + return ProductPriceIndex::class; } } diff --git a/packages/Webkul/Product/src/Repositories/ProductRepository.php b/packages/Webkul/Product/src/Repositories/ProductRepository.php index d2f3f6e76fa..671e7d8c1be 100755 --- a/packages/Webkul/Product/src/Repositories/ProductRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductRepository.php @@ -169,37 +169,29 @@ public function findBySlugOrFail($slug) /** * Get all products. * - * To Do (@devansh-webkul): Need to reduce all the request query from this repo and provide - * good request parameter with an array type as an argument. Make a clean pull request for - * this to have track record. - * * @return \Illuminate\Support\Collection */ - public function getAll() + public function getAll(array $data) { if (core()->getConfigData('catalog.products.storefront.search_mode') == 'elastic') { - return $this->searchFromElastic(); + return $this->searchFromElastic($data); } - return $this->searchFromDatabase(); + return $this->searchFromDatabase($data); } /** * Search product from database. * - * To Do (@devansh-webkul): Need to reduce all the request query from this repo and provide - * good request parameter with an array type as an argument. Make a clean pull request for - * this to have track record. - * * @return \Illuminate\Support\Collection */ - public function searchFromDatabase() + public function searchFromDatabase($data) { $params = array_merge([ 'status' => 1, 'visible_individually' => 1, 'url_key' => null, - ], request()->input()); + ], $data); if (! empty($params['query'])) { $params['name'] = $params['query']; @@ -272,7 +264,7 @@ public function searchFromDatabase() ->where($alias.'.attribute_id', $attribute->id); if ($attribute->code == 'name') { - $synonyms = $this->searchSynonymRepository->getSynonymsByQuery(urldecode($params['name'])); + $synonyms = $this->searchSynonymRepository->getSynonymsByQuery(urldecode($params['query'])); $qb->where(function ($subQuery) use ($alias, $synonyms) { foreach ($synonyms as $synonym) { @@ -374,16 +366,10 @@ public function searchFromDatabase() /** * Search product from elastic search. * - * To Do (@devansh-webkul): Need to reduce all the request query from this repo and provide - * good request parameter with an array type as an argument. Make a clean pull request for - * this to have track record. - * * @return \Illuminate\Support\Collection */ - public function searchFromElastic() + public function searchFromElastic(array $params) { - $params = request()->input(); - $currentPage = Paginator::resolveCurrentPage('page'); $limit = $this->getPerPageLimit($params); @@ -396,7 +382,7 @@ public function searchFromElastic() 'limit' => $limit, 'sort' => $sortOptions['sort'], 'order' => $sortOptions['order'], - ]); + ], $params); $query = $this->with([ 'attribute_family', diff --git a/packages/Webkul/Product/src/Repositories/ProductReviewRepository.php b/packages/Webkul/Product/src/Repositories/ProductReviewRepository.php index 73377e0f089..94811558066 100755 --- a/packages/Webkul/Product/src/Repositories/ProductReviewRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductReviewRepository.php @@ -2,30 +2,28 @@ namespace Webkul\Product\Repositories; +use Illuminate\Pagination\LengthAwarePaginator; use Webkul\Core\Eloquent\Repository; +use Webkul\Product\Contracts\ProductReview; class ProductReviewRepository extends Repository { /** - * Specify Model class name + * Specify Model class name. */ public function model(): string { - return 'Webkul\Product\Contracts\ProductReview'; + return ProductReview::class; } /** - * Retrieve review for customerId - * - * @return \Illuminate\Support\Collection + * Retrieve review for customer. */ - public function getCustomerReview() + public function getCustomerReview(): LengthAwarePaginator { - $reviews = $this->model + return $this->getModel() ->where(['customer_id' => auth()->guard('customer')->user()->id]) ->with('product') ->paginate(5); - - return $reviews; } } diff --git a/packages/Webkul/Product/src/Repositories/ProductVideoRepository.php b/packages/Webkul/Product/src/Repositories/ProductVideoRepository.php index 30b54c9891a..c5ca3e146bc 100644 --- a/packages/Webkul/Product/src/Repositories/ProductVideoRepository.php +++ b/packages/Webkul/Product/src/Repositories/ProductVideoRepository.php @@ -2,6 +2,9 @@ namespace Webkul\Product\Repositories; +use Webkul\Product\Contracts\Product; +use Webkul\Product\Contracts\ProductVideo; + class ProductVideoRepository extends ProductMediaRepository { /** @@ -9,17 +12,13 @@ class ProductVideoRepository extends ProductMediaRepository */ public function model(): string { - return 'Webkul\Product\Contracts\ProductVideo'; + return ProductVideo::class; } /** * Upload videos. - * - * @param array $data - * @param \Webkul\Product\Contracts\Product $product - * @return void */ - public function uploadVideos($data, $product) + public function uploadVideos(array $data, Product $product): void { $this->upload($data, $product, 'videos'); } diff --git a/packages/Webkul/Product/src/Repositories/SearchRepository.php b/packages/Webkul/Product/src/Repositories/SearchRepository.php index 8b8c7799c3b..5539258d394 100755 --- a/packages/Webkul/Product/src/Repositories/SearchRepository.php +++ b/packages/Webkul/Product/src/Repositories/SearchRepository.php @@ -2,6 +2,7 @@ namespace Webkul\Product\Repositories; +use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; use Webkul\Core\Traits\Sanitizer; @@ -10,14 +11,18 @@ class SearchRepository extends ProductRepository use Sanitizer; /** - * Upload provided image - * - * @param array $data - * @return string + * Upload provided image. */ - public function uploadSearchImage($data) + public function uploadSearchImage(array $data): mixed { - $path = request()->file('image')->store('product-search'); + if ( + ! empty($data['image']) + && ! $data['image'] instanceof UploadedFile + ) { + return null; + } + + $path = $data['image']->store('product-search'); $this->sanitizeSVG($path, $data['image']->getMimeType()); diff --git a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php index 838a82897fb..cb03f0c91f4 100755 --- a/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php +++ b/packages/Webkul/Sales/src/Repositories/InvoiceRepository.php @@ -167,10 +167,7 @@ public function create(array $data, $invoiceState = null, $orderState = null) $this->orderRepository->updateOrderStatus($order); } - /** - * Temporary property has been used to avoid request helper usage in listener. - */ - $invoice->can_create_transaction = request()->has('can_create_transaction') && request()->input('can_create_transaction') == '1'; + $invoice->can_create_transaction = $data['can_create_transaction'] ?? false; Event::dispatch('sales.invoice.save.after', $invoice); } catch (\Exception $e) { diff --git a/packages/Webkul/Shop/src/Http/Controllers/API/ProductController.php b/packages/Webkul/Shop/src/Http/Controllers/API/ProductController.php index 2ca058f82cc..51defcd21fb 100644 --- a/packages/Webkul/Shop/src/Http/Controllers/API/ProductController.php +++ b/packages/Webkul/Shop/src/Http/Controllers/API/ProductController.php @@ -26,7 +26,12 @@ public function __construct( */ public function index(): JsonResource { - $products = $this->productRepository->getAll(); + $data = array_merge(request()->input(), [ + 'path' => request()->url(), + 'query_data' => request()->query(), + ]); + + $products = $this->productRepository->getAll($data); if (! empty(request()->query('query'))) { /** diff --git a/packages/Webkul/Shop/src/Http/Requests/Customer/ProfileRequest.php b/packages/Webkul/Shop/src/Http/Requests/Customer/ProfileRequest.php index e444242aa2b..e47766c8d3f 100644 --- a/packages/Webkul/Shop/src/Http/Requests/Customer/ProfileRequest.php +++ b/packages/Webkul/Shop/src/Http/Requests/Customer/ProfileRequest.php @@ -36,7 +36,8 @@ public function rules() 'new_password' => 'confirmed|min:6|required_with:current_password', 'new_password_confirmation' => 'required_with:new_password', 'current_password' => 'required_with:new_password', - 'image.*' => 'mimes:bmp,jpeg,jpg,png,webp', + 'image' => 'array', + 'image.*' => 'image|mimes:bmp,jpeg,jpg,png,webp', 'phone' => ['required', new PhoneNumber(), 'unique:customers,phone,'.$id], 'subscribed_to_news_letter' => 'nullable', ]; diff --git a/packages/Webkul/Shop/src/Resources/views/search/images/results.blade.php b/packages/Webkul/Shop/src/Resources/views/search/images/results.blade.php index 339a2b84e13..eeeaa2e01f9 100644 --- a/packages/Webkul/Shop/src/Resources/views/search/images/results.blade.php +++ b/packages/Webkul/Shop/src/Resources/views/search/images/results.blade.php @@ -68,7 +68,10 @@ class="p-2.5 text-xs font-normal leading-none max-w-full flex-initial" }, created() { - if (localStorage.searchedTerms && localStorage.searchedTerms != '') { + if ( + localStorage.searchedTerms + && localStorage.searchedTerms != '' + ) { this.searchedTerms = localStorage.searchedTerms.split('_'); this.searchedTerms = this.searchedTerms.map(term => { diff --git a/packages/Webkul/Shop/tests/Feature/Customers/AccountTest.php b/packages/Webkul/Shop/tests/Feature/Customers/AccountTest.php index cde41ff6ee9..eb5b61af519 100644 --- a/packages/Webkul/Shop/tests/Feature/Customers/AccountTest.php +++ b/packages/Webkul/Shop/tests/Feature/Customers/AccountTest.php @@ -1,5 +1,6 @@ 1, 'customer_group_id' => 2, 'phone' => $phone = fake()->e164PhoneNumber(), + 'image' => [ + UploadedFile::fake()->image('profile.jpg'), + ], ]) ->assertRedirect(route('shop.customers.account.profile.index')); diff --git a/packages/Webkul/SocialLogin/src/Repositories/CustomerSocialAccountRepository.php b/packages/Webkul/SocialLogin/src/Repositories/CustomerSocialAccountRepository.php index 15db7ee8044..78a5d1c66f7 100644 --- a/packages/Webkul/SocialLogin/src/Repositories/CustomerSocialAccountRepository.php +++ b/packages/Webkul/SocialLogin/src/Repositories/CustomerSocialAccountRepository.php @@ -6,6 +6,7 @@ use Webkul\Core\Eloquent\Repository; use Webkul\Customer\Repositories\CustomerGroupRepository; use Webkul\Customer\Repositories\CustomerRepository; +use Webkul\SocialLogin\Contracts\CustomerSocialAccount; class CustomerSocialAccountRepository extends Repository { @@ -19,8 +20,6 @@ public function __construct( protected CustomerGroupRepository $customerGroupRepository, Container $container ) { - $this->_config = request('_config'); - parent::__construct($container); } @@ -29,7 +28,7 @@ public function __construct( */ public function model(): string { - return 'Webkul\SocialLogin\Contracts\CustomerSocialAccount'; + return CustomerSocialAccount::class; } /** @@ -74,11 +73,8 @@ public function findOrCreateCustomer($providerUser, $provider) /** * Returns first and last name from name - * - * @param string $name - * @return string */ - public function getFirstLastName($name) + public function getFirstLastName(string $name): array { $name = trim($name); diff --git a/packages/Webkul/Theme/src/Models/ThemeCustomization.php b/packages/Webkul/Theme/src/Models/ThemeCustomization.php index 1479d375772..fb987a705ff 100644 --- a/packages/Webkul/Theme/src/Models/ThemeCustomization.php +++ b/packages/Webkul/Theme/src/Models/ThemeCustomization.php @@ -28,6 +28,13 @@ class ThemeCustomization extends TranslatableModel implements ThemeCustomization */ protected $with = ['translations']; + /** + * Translation model foreign key column + * + * @var string + */ + protected $translationForeignKey = 'theme_customization_id'; + /** * Image carousel precision. * diff --git a/packages/Webkul/Theme/src/Repositories/ThemeCustomizationRepository.php b/packages/Webkul/Theme/src/Repositories/ThemeCustomizationRepository.php index b9540b05a02..ed338fc5339 100644 --- a/packages/Webkul/Theme/src/Repositories/ThemeCustomizationRepository.php +++ b/packages/Webkul/Theme/src/Repositories/ThemeCustomizationRepository.php @@ -27,24 +27,42 @@ public function model(): string */ public function update($data, $id): ThemeCustomization { + $tempData = $data; + $locale = core()->getRequestedLocaleCode(); - if ($data['type'] == 'static_content') { - $data[$locale]['options']['html'] = preg_replace('/]*>(.*?)<\/script>/is', '', $data[$locale]['options']['html']); - $data[$locale]['options']['css'] = preg_replace('/]*>(.*?)<\/script>/is', '', $data[$locale]['options']['css']); - } + $this->sanitizeHtmlAndCss($data, $locale); + + $theme = parent::find($id); if (in_array($data['type'], ['image_carousel', 'services_content'])) { unset($data[$locale]['options']); + + $this->uploadImage($tempData, $theme); } - $theme = parent::update($data, $id); + $theme->update($data); - if (in_array($data['type'], ['image_carousel', 'services_content'])) { - $this->uploadImage(request()->all(), $theme); + return $theme; + } + + /** + * Sanitize the html and css. + */ + public function sanitizeHtmlAndCss(array &$data, string $locale): void + { + if ($data['type'] == 'static_content') { + $data[$locale]['options']['html'] = $this->removeScripts($data[$locale]['options']['html']); + $data[$locale]['options']['css'] = $this->removeScripts($data[$locale]['options']['css']); } + } - return $theme; + /** + * Remove scripts. + */ + public function removeScripts(string $content): string + { + return preg_replace('/]*>(.*?)<\/script>/is', '', $content); } /** @@ -101,9 +119,8 @@ public function uploadImage(array $data, ThemeCustomization $theme) } } - $translatedModel = $theme->translate($locale); - $translatedModel->options = $options ?? []; - $translatedModel->theme_customization_id = $theme->id; - $translatedModel->save(); + $theme->options = $options ?? []; + + $theme->save(); } }