liberu-ecommerce / ecommerce-laravel

Ecommerce system written in Laravel 11 / PHP 8.3 using Filament 3.2 and Livewire 3.5
https://www.facebook.com/liberusoftware
85 stars 27 forks source link

Implement Downloadable Products Functionality #14

Closed curtisdelicata closed 7 months ago

curtisdelicata commented 1 year ago

Add to database schema and add to the products controllers/models when ready.

Objective: Implement functionality to support downloadable products within our ecommerce application built using Laravel. Downloadable products are digital goods that customers can purchase and download after their purchase is completed.

Acceptance Criteria:

Add a downloadable products table to store relevant information about each downloadable product (e.g., file URL, product ID, download limit, etc.). Modify the product creation and editing flow to include the option to upload/downloadable files and specify download limits. Integrate secure download links that expire after a defined period or a certain number of downloads. Ensure that the download links are accessible only to authorized users who have purchased the product. Create a mechanism to track and record download history for each downloadable product. Update the user interface to display downloadable products and allow customers to initiate downloads. Test the functionality thoroughly, including edge cases and potential security vulnerabilities. Additional Information:

Priority: High Difficulty: Medium Labels: enhancement, downloadable products Milestone: 1.2.0 (or appropriate milestone) Tasks: Create a database migration for the downloadable products table. Implement a file upload mechanism for downloadable products. Update product creation/editing forms to handle downloadable products. Implement secure download links and manage their expiration and access limits. Update the user interface to display downloadable products and allow for downloads. Add unit and integration tests to ensure the functionality is working correctly.

Checklist - [X] Create `database/migrations/2023_04_01_000000_create_downloadable_products_table.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/ddee428ac26d35519ea35a3feb4577400d4b1c43 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/database/migrations/2023_04_01_000000_create_downloadable_products_table.php) - [X] Running GitHub Actions for `database/migrations/2023_04_01_000000_create_downloadable_products_table.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/database/migrations/2023_04_01_000000_create_downloadable_products_table.php) - [X] Modify `app/Models/Product.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/ffce15929e8835d3bdcfce172c4f3464235fdd75 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Models/Product.php#L1-L1) - [X] Running GitHub Actions for `app/Models/Product.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Models/Product.php#L1-L1) - [X] Create `app/Models/DownloadableProduct.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/637f1d7acd09760a3214f92f8f94d5349ed01fb5 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Models/DownloadableProduct.php) - [X] Running GitHub Actions for `app/Models/DownloadableProduct.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Models/DownloadableProduct.php) - [X] Modify `app/Http/Controllers/ProductController.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/496d49919a1f63f31b6d662a601042397b682e7a [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Http/Controllers/ProductController.php#L1-L1) - [X] Running GitHub Actions for `app/Http/Controllers/ProductController.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Http/Controllers/ProductController.php#L1-L1) - [X] Create `app/Http/Controllers/DownloadController.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/edeabc3417730597c98146c83f8be4f190c25b79 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Http/Controllers/DownloadController.php) - [X] Running GitHub Actions for `app/Http/Controllers/DownloadController.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/app/Http/Controllers/DownloadController.php) - [X] Modify `routes/web.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/e603d666d1de5dbb6dfe2cc1b2a2659fe729379b [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/routes/web.php) - [X] Running GitHub Actions for `routes/web.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/routes/web.php) - [X] Modify `resources/views/products/show.blade.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/b9a0ea1489af4e2837362db4fc686c0e93e8a103 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/resources/views/products/show.blade.php#L1-L1) - [X] Running GitHub Actions for `resources/views/products/show.blade.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/resources/views/products/show.blade.php#L1-L1) - [X] Create `tests/Feature/DownloadableProductTest.php` ✓ https://github.com/liberu-ecommerce/ecommerce-laravel/commit/eaf68579881a9ed314e2b3395478da57feb07796 [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/tests/Feature/DownloadableProductTest.php) - [X] Running GitHub Actions for `tests/Feature/DownloadableProductTest.php` ✓ [Edit](https://github.com/liberu-ecommerce/ecommerce-laravel/edit/sweep/implement_downloadable_products_function/tests/Feature/DownloadableProductTest.php)
sweep-ai[bot] commented 7 months ago

🚀 Here's the PR! #67

See Sweep's progress at the progress dashboard!
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: a235f56f55)

[!TIP] I'll email you at genealogysoftwareuk@gmail.com when I complete this pull request!


Actions (click)

GitHub Actions✓

Here are the GitHub Actions logs prior to making any changes:

Sandbox logs for 857c21e
Checking app/Models/Product.php for syntax errors... ✅ app/Models/Product.php has no syntax errors! 1/1 ✓
Checking app/Models/Product.php for syntax errors...
✅ app/Models/Product.php has no syntax errors!

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/liberu-ecommerce/ecommerce-laravel/blob/857c21e64335904ca427312afb15fbbc07a5738d/README.md#L16-L55 https://github.com/liberu-ecommerce/ecommerce-laravel/blob/857c21e64335904ca427312afb15fbbc07a5738d/routes/web.php#L1-L58 https://github.com/liberu-ecommerce/ecommerce-laravel/blob/857c21e64335904ca427312afb15fbbc07a5738d/config/app.php#L128-L187 https://github.com/liberu-ecommerce/ecommerce-laravel/blob/857c21e64335904ca427312afb15fbbc07a5738d/config/auth.php#L73-L114

Step 2: ⌨️ Coding

Ran GitHub Actions for ddee428ac26d35519ea35a3feb4577400d4b1c43:

--- 
+++ 
@@ -46,3 +46,7 @@

 }
+    public function downloadable()
+    {
+        return $this->hasMany(DownloadableProduct::class);
+    }

Ran GitHub Actions for ffce15929e8835d3bdcfce172c4f3464235fdd75:

Ran GitHub Actions for 637f1d7acd09760a3214f92f8f94d5349ed01fb5:

--- 
+++ 
@@ -10,12 +10,23 @@
 {
     public function create(Request $request)
     {
+        // Handle Product File Upload
+        if ($request->hasFile('product_file')) {
+            $file = $request->file('product_file');
+            $filePath = $file->store('public/downloadable_products');
+            $fileUrl = Storage::url($filePath);
+        } else {
+            $fileUrl = null;
+        }
+
         $validatedData = $request->validate([
             'name' => 'required|string|max:255',
             'description' => 'required|string',
             'price' => 'required|numeric',
             'category' => 'required|string|max:255',
             'inventory_count' => 'required|integer',
+            // Include download limit in validation
+            'download_limit' => 'integer|nullable',
         ]);

         $product = Product::create($validatedData);
@@ -57,6 +68,15 @@
             'inventory_count' => 'integer',
         ]);

+        // Handle Product File Upload for Update
+        if ($request->hasFile('product_file')) {
+            $file = $request->file('product_file');
+            $filePath = $file->store('public/downloadable_products');
+            $fileUrl = Storage::url($filePath);
+            // Update Downloadable Product entry
+            $product->downloadable()->updateOrCreate(['product_id' => $product->id], ['file_url' => $fileUrl, 'download_limit' => $request->download_limit]);
+        }
+
         $product->update($validatedData);

         return response()->json($product);

Ran GitHub Actions for 496d49919a1f63f31b6d662a601042397b682e7a:

Ran GitHub Actions for edeabc3417730597c98146c83f8be4f190c25b79:

--- 
+++ 
@@ -60,4 +60,11 @@

+Route::middleware('auth')->group(function () {
+    Route::get('/download/{productId}', 'App\Http\Controllers\DownloadController@generateSecureLink')->name('download.generate-link');
+    Route::get('/download/file/{productId}', 'App\Http\Controllers\DownloadController@serveFile')->name('download.serve-file');
+});

+
+
+

Ran GitHub Actions for e603d666d1de5dbb6dfe2cc1b2a2659fe729379b:

--- 
+++ 
@@ -19,3 +19,6 @@
     
@endsection + @if($product->downloadable->count() > 0 && auth()->user() && auth()->user()->hasPurchased($product)) + Download + @endif

Ran GitHub Actions for b9a0ea1489af4e2837362db4fc686c0e93e8a103:

Ran GitHub Actions for eaf68579881a9ed314e2b3395478da57feb07796:


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/implement_downloadable_products_function.


🎉 Latest improvements to Sweep:

💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request.Something wrong? Let us know.

This is an automated message generated by Sweep AI.