Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
T
test-webshop
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Artem
test-webshop
Commits
0bfb296e
Commit
0bfb296e
authored
May 08, 2020
by
Artem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix in cart index method, disable delete product option
parent
02165d9e
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
37 additions
and
13 deletions
+37
-13
Cart.php
app/Cart.php
+10
-0
CartController.php
app/Http/Controllers/CartController.php
+2
-0
ProductController.php
app/Http/Controllers/ProductController.php
+5
-5
User.php
app/User.php
+6
-0
DatabaseSeeder.php
database/seeds/DatabaseSeeder.php
+1
-1
cart.blade.php
resources/views/cart.blade.php
+6
-1
product.blade.php
resources/views/product/product.blade.php
+5
-5
web.php
routes/web.php
+2
-1
No files found.
app/Cart.php
View file @
0bfb296e
...
...
@@ -3,6 +3,8 @@
namespace
App
;
//use Illuminate\Database\Eloquent\Model;
use
App\Product
;
use
DB
;
class
Cart
/*extends Model*/
{
...
...
@@ -67,4 +69,12 @@ class Cart /*extends Model*/
$this
->
updateTotalQty
();
$this
->
updateTotalPrice
();
}
public
function
updateCurrentItems
()
{
foreach
(
$this
->
items
as
$id
=>
$item
)
{
$this
->
items
[
$id
][
'item'
]
=
Product
::
where
(
'id'
,
$id
)
->
first
();
}
$this
->
updateTotalPrice
();
}
}
app/Http/Controllers/CartController.php
View file @
0bfb296e
...
...
@@ -17,6 +17,8 @@ class CartController extends Controller
}
$cart
=
Session
::
get
(
'cart'
);
// need to take products from database because product data may change
$cart
->
updateCurrentItems
();
$products
=
$cart
->
items
;
return
view
(
'cart'
,
compact
(
'cart'
,
'products'
));
...
...
app/Http/Controllers/ProductController.php
View file @
0bfb296e
...
...
@@ -127,11 +127,11 @@ class ProductController extends Controller
* @param \App\Product $product
* @return \Illuminate\Http\Response
*/
public
function
destroy
(
Product
$product
)
{
$product
->
delete
();
return
redirect
(
'/'
);
}
//
public function destroy(Product $product)
//
{
//
$product->delete();
//
return redirect('/');
//
}
public
function
validateProduct
()
{
...
...
app/User.php
View file @
0bfb296e
...
...
@@ -5,6 +5,7 @@ namespace App;
use
Illuminate\Contracts\Auth\MustVerifyEmail
;
use
Illuminate\Foundation\Auth\User
as
Authenticatable
;
use
Illuminate\Notifications\Notifiable
;
use
Illuminate\Support\Facades\Artisan
;
class
User
extends
Authenticatable
{
...
...
@@ -36,4 +37,9 @@ class User extends Authenticatable
protected
$casts
=
[
'email_verified_at'
=>
'datetime'
,
];
public
function
orders
()
{
return
$this
->
hasMany
(
Order
::
class
);
}
}
database/seeds/DatabaseSeeder.php
View file @
0bfb296e
...
...
@@ -11,7 +11,7 @@ class DatabaseSeeder extends Seeder
*/
public
function
run
()
{
//
$this->call(UserSeeder::class);
$this
->
call
(
UserSeeder
::
class
);
factory
(
App\Product
::
class
,
20
)
->
create
();
}
}
resources/views/cart.blade.php
View file @
0bfb296e
...
...
@@ -61,7 +61,12 @@
>Update quantity</button>
</td>
<td class="
hidden
-
xs
text
-
center
"><strong>Total € {{
$cart->total_price
}}</strong></td>
<td><button class="
btn
btn
-
success
btn
-
block
">Checkout</button></td>
<td>
<form action="
{{
route
(
'order.sendOrder'
)
}}
" method="
POST
">
@csrf
<button class="
btn
btn
-
success
btn
-
block
">Send order</button>
</form>
</td>
</tr>
</tfoot>
</table>
...
...
resources/views/product/product.blade.php
View file @
0bfb296e
...
...
@@ -15,12 +15,12 @@
href
=
"{{
$product->editPath
() }}"
>
Edit
product
</
a
>
</
div
>
<
form
method
=
"POST"
action
=
"{{
$product->path
() }}"
>
@
csrf
@
method
(
'DELETE'
)
{{
--
<
form
method
=
"POST"
action
=
"{{
$product->path
() }}"
>--
}}
{{
--
@
csrf
--
}}
{{
--
@
method
(
'DELETE'
)
--
}}
<
button
class
="
btn
btn
-
outline
-
danger
mt
-
5
">Delete product</button>
</form>
{{
--
<
button
class
="
btn
btn
-
outline
-
danger
mt
-
5
">Delete product</button>--}}
{{-- </form>--}}
</div>
</section>
@endsection
routes/web.php
View file @
0bfb296e
...
...
@@ -21,7 +21,7 @@ Route::prefix('product')->group(function() {
Route
::
get
(
'/{product}'
,
'ProductController@show'
)
->
name
(
'product.show'
);
Route
::
get
(
'/{product}/edit'
,
'ProductController@edit'
)
->
name
(
'product.edit'
);
Route
::
put
(
'/{product}'
,
'ProductController@update'
);
Route
::
delete
(
'/{product}'
,
'ProductController@destroy'
);
//
Route::delete('/{product}', 'ProductController@destroy');
});
...
...
@@ -37,3 +37,4 @@ Route::prefix('cart')->group(function() {
Route
::
post
(
'/clear'
,
'CartController@clearCart'
)
->
name
(
'cart.clearCart'
);
});
Route
::
post
(
'order'
,
'OrderController@store'
)
->
name
(
'order.sendOrder'
)
->
middleware
(
'auth'
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment