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
c8862b3c
Commit
c8862b3c
authored
May 06, 2020
by
Artem
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
building shopping cart
parent
3db4fc38
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
115 additions
and
12 deletions
+115
-12
Cart.php
app/Cart.php
+42
-0
CartController.php
app/Http/Controllers/CartController.php
+13
-0
ProductController.php
app/Http/Controllers/ProductController.php
+5
-0
Product.php
app/Product.php
+2
-0
welcome.css
public/css/welcome.css
+2
-0
welcome.js
public/js/welcome.js
+18
-0
app.js
resources/js/app.js
+1
-0
welcome.scss
resources/sass/welcome.scss
+2
-0
cart.blade.php
resources/views/cart.blade.php
+7
-0
app.blade.php
resources/views/layouts/app.blade.php
+2
-0
header.blade.php
resources/views/layouts/header.blade.php
+6
-2
welcome.blade.php
resources/views/welcome.blade.php
+10
-10
web.php
routes/web.php
+5
-0
No files found.
app/Cart.php
0 → 100644
View file @
c8862b3c
<?php
namespace
App
;
//use Illuminate\Database\Eloquent\Model;
class
Cart
/*extends Model*/
{
public
$items
=
null
;
public
$total_qty
=
0
;
public
$total_price
=
0
;
public
function
__construct
(
$old_cart
)
{
if
(
$old_cart
)
{
$this
->
items
=
$old_cart
->
items
;
$this
->
total_qty
=
$old_cart
->
total_qty
;
$this
->
total_price
=
$old_cart
->
total_price
;
}
}
public
function
addItemToCart
(
$item
,
$id
)
{
$stored_item
=
[
'qty'
=>
0
,
'price'
=>
$item
->
price
,
'item'
=>
$item
];
if
(
$this
->
items
)
{
if
(
array_key_exists
(
$id
,
$this
->
items
))
{
$stored_item
=
$this
->
items
[
$id
];
}
}
// $stored_item = ($this->items && array_key_exists($id, $this->items)) ?
// $stored_item = $this->items[$id] :
// ['qty' => 0, 'price' => $item->price, 'item' => $item];
$stored_item
[
'qty'
]
++
;
$stored_item
[
'price'
]
=
$item
->
price
*
$stored_item
[
'qty'
];
$this
->
items
[
$id
]
=
$stored_item
;
$this
->
total_qty
++
;
$this
->
total_price
+=
$item
->
price
;
}
}
app/Http/Controllers/CartController.php
0 → 100644
View file @
c8862b3c
<?php
namespace
App\Http\Controllers
;
use
Illuminate\Http\Request
;
class
CartController
extends
Controller
{
public
function
index
()
{
return
view
(
'cart'
);
}
}
app/Http/Controllers/ProductController.php
View file @
c8862b3c
...
@@ -161,4 +161,9 @@ class ProductController extends Controller
...
@@ -161,4 +161,9 @@ class ProductController extends Controller
'type'
=>
'required'
'type'
=>
'required'
]);
]);
}
}
public
function
addToCart
(
Request
$request
,
Product
$product
)
{
// return $product;
}
}
}
app/Product.php
View file @
c8862b3c
...
@@ -18,4 +18,6 @@ class Product extends Model
...
@@ -18,4 +18,6 @@ class Product extends Model
{
{
return
route
(
'product.edit'
,
$this
);
return
route
(
'product.edit'
,
$this
);
}
}
}
}
public/css/welcome.css
View file @
c8862b3c
...
@@ -40,6 +40,8 @@
...
@@ -40,6 +40,8 @@
.product__short-text
{
.product__short-text
{
text-align
:
center
;
text-align
:
center
;
height
:
50px
;
overflow
:
hidden
;
}
}
.product__price
{
.product__price
{
...
...
public/js/welcome.js
0 → 100644
View file @
c8862b3c
document
.
querySelector
(
'.products'
).
addEventListener
(
'click'
,
function
(
e
)
{
if
(
!
e
.
target
.
classList
.
contains
(
'btn-add-to-basket'
))
return
;
e
.
preventDefault
();
const
actionUrl
=
e
.
target
.
dataset
.
action
;
axios
.
post
(
actionUrl
,
{
productId
:
e
.
target
.
dataset
.
product_id
})
.
then
(
function
(
response
)
{
console
.
log
(
response
);
const
amountInCart
=
document
.
querySelector
(
'.amount-in-cart'
);
amountInCart
.
textContent
++
;
})
.
catch
(
function
(
error
)
{
console
.
log
(
error
);
});
});
resources/js/app.js
View file @
c8862b3c
require
(
'./bootstrap'
);
require
(
'./bootstrap'
);
resources/sass/welcome.scss
View file @
c8862b3c
...
@@ -41,6 +41,8 @@
...
@@ -41,6 +41,8 @@
&
__short-text
{
&
__short-text
{
text-align
:
center
;
text-align
:
center
;
height
:
50px
;
overflow
:
hidden
;
}
}
&
__price
{
&
__price
{
...
...
resources/views/cart.blade.php
0 → 100644
View file @
c8862b3c
@
extends
(
'layouts.app'
)
@
section
(
'content'
)
<
div
class
="
container
">
<div>OLOLO</div>
</div>
@endsection
resources/views/layouts/app.blade.php
View file @
c8862b3c
...
@@ -24,5 +24,7 @@
...
@@ -24,5 +24,7 @@
@yield('content')
@yield('content')
</main>
</main>
</div>
</div>
@yield('script')
</body>
</body>
</html>
</html>
resources/views/layouts/header.blade.php
View file @
c8862b3c
...
@@ -12,11 +12,15 @@
...
@@ -12,11 +12,15 @@
<div class="
collapse
navbar
-
collapse
" id="
navbarSupportedContent
">
<div class="
collapse
navbar
-
collapse
" id="
navbarSupportedContent
">
<!-- Left Side Of Navbar -->
<!-- Left Side Of Navbar -->
<ul class="
navbar
-
nav
mr
-
auto
">
<ul class="
navbar
-
nav
ml
-
auto
">
<li class="
nav
-
item
">
<span class="
amount
-
in
-
cart
"></span>
<a href="
{{
route
(
'cart.index'
)
}}
">Shopping cart</a>
</li>
</ul>
</ul>
<!-- Right Side Of Navbar -->
<!-- Right Side Of Navbar -->
<ul class="
navbar
-
nav
ml
-
auto
">
<ul class="
navbar
-
nav
ml
-
5
">
<!-- Authentication Links -->
<!-- Authentication Links -->
@guest
@guest
<li class="
nav
-
item
">
<li class="
nav
-
item
">
...
...
resources/views/welcome.blade.php
View file @
c8862b3c
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
<
section
class
="
products
">
<
section
class
="
products
">
<div class="
container
">
<div class="
container
">
<a href="
/
product
/
create
">Create product</a>
<a href="
/
product
/
create
">Create product</a>
{{-- @if(isset(
$products
))--}}
<ul class="
product
-
list
">
<ul class="
product
-
list
">
@foreach(
$products
as
$product
)
@foreach(
$products
as
$product
)
<li class="
product
-
list__item
">
<li class="
product
-
list__item
">
...
@@ -16,23 +16,23 @@
...
@@ -16,23 +16,23 @@
{{-- <a href="
/
product
/
{{
$product
->
id
}}
" class="
product__image
">--}}
{{-- <a href="
/
product
/
{{
$product
->
id
}}
" class="
product__image
">--}}
<a href="
{{
$product
->
path
()
}}
" class="
product__image
">
<a href="
{{
$product
->
path
()
}}
" class="
product__image
">
<img src="
/
img
/
{{
$product
->
type
}}
.
jpg
" alt="
{{
$product
->
reference
}}
">
<img src="
/
img
/
{{
$product
->
type
}}
.
jpg
" alt="
{{
$product
->
reference
}}
">
{{-- <img--}}
{{-- @if (
$product->type
=== 'Phone' ||
$product->type
=== 'Balalaika')--}}
{{-- src="
/
img
/
{{
$product
->
type
}}
.
jpg
"--}}
{{-- @else--}}
{{-- src="
https
://
placehold
.
it
/
150
x150
"--}}
{{-- @endif--}}
{{-- alt="
{{
$product
->
reference
}}
">--}}
</a>
</a>
<a href="
{{
$product
->
path
()
}}
" class="
product__name
">
{
{$product->reference}
}
</a>
<a href="
{{
$product
->
path
()
}}
" class="
product__name
">
{
{$product->reference}
}
</a>
<p class="
product__short
-
text
">
{
{$product->description_short}
}
</p>
<p class="
product__short
-
text
">
{
{$product->description_short}
}
</p>
<p class="
product__price
">
{
{$product->price}
}
EUR</p>
<p class="
product__price
">
{
{$product->price}
}
EUR</p>
<button class="
btn
-
add
-
to
-
basket
">Add to basket</button>
<button class="
btn
-
add
-
to
-
basket
btn
btn
-
info
"
data-product_id="
{{
$product
->
id
}}
"
data-action="
{{
route
(
'product.addToCart'
,
$product
)
}}
"
>Add to basket</button>
</div>
</div>
</li>
</li>
@endforeach
@endforeach
</ul>
</ul>
{{-- @endif--}}
</div>
</div>
</section>
</section>
@endsection
@endsection
@section('script')
<script src="
js
/
welcome
.
js
"></script>
@endsection
routes/web.php
View file @
c8862b3c
...
@@ -24,3 +24,8 @@ Route::delete('/product/{product}', 'ProductController@destroy');
...
@@ -24,3 +24,8 @@ Route::delete('/product/{product}', 'ProductController@destroy');
Auth
::
routes
();
Auth
::
routes
();
Route
::
get
(
'/home'
,
'HomeController@index'
)
->
name
(
'home'
);
Route
::
get
(
'/home'
,
'HomeController@index'
)
->
name
(
'home'
);
Route
::
post
(
'/add-to-cart/{product}'
,
'ProductController@addToCart'
)
->
name
(
'product.addToCart'
);
Route
::
get
(
'/cart'
,
'CartController@index'
)
->
name
(
'cart.index'
);
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