Commit 76388bfd authored by Artem's avatar Artem

very last commit, fix products links in cart and success notifications

parent 15453a4d
......@@ -74,7 +74,8 @@ class CartController extends Controller
// make array of products in order to get correct order of items in js
$cart_products = [];
foreach ($cart->items as $item) {
foreach ($cart->items as $id => $item) {
$item['productLink'] = route('product.show', $id);
$cart_products[] = $item;
}
......
......@@ -11,7 +11,6 @@ class Cart {
this.totalPrice;
this.updateItemUrl = cartElem.dataset.updateItemUrl;
this.removeItemUrl = cartElem.dataset.removeItemUrl;
this.itemUrl = cartElem.dataset.itemUrl;
this.hasEvents;
this.updateItemQty = this.updateItemQty.bind(this);
this.removeItemFromCart = this.removeItemFromCart.bind(this);
......@@ -23,7 +22,7 @@ class Cart {
<div class="row">
<div class="col-sm-3 hidden-xs"><img src="/img/${product.item.type}.jpg" width="100" height="100" alt="${product.item.reference}" class="img-responsive"/></div>
<div class="col-sm-9">
<h4 class="nomargin"><a href="${this.itemUrl + product.item.id}">${product.item.reference}</a></h4>
<h4 class="nomargin"><a href="${product.productLink}">${product.item.reference}</a></h4>
<p>${product.item.description_short}</p>
</div>
</div>
......@@ -75,8 +74,7 @@ class Cart {
this.sendUpdateItemQtyRequest({ productId, changedQty })
.then( (response) => {
this.show();
toastr.success('Quantity updated');
this.show('Quantity updated');
})
.catch( (error) => {
console.log(error);
......@@ -100,8 +98,7 @@ class Cart {
this.sendRemoveItemRequest({ productId })
.then( (response) => {
this.show();
toastr.success('Product deleted');
this.show('Product deleted');
})
.catch( (error) => {
console.log(error);
......@@ -121,7 +118,7 @@ class Cart {
}
show() {
show(successMessage) {
if (!this.loaderElem.classList.contains('loader-show')) {
this.loaderElem.classList.toggle('loader-show');
}
......@@ -141,6 +138,10 @@ class Cart {
this.showProducts();
this.toggleLoager();
if (successMessage) {
toastr.success(successMessage);
}
if (!this.hasEvents) {
this.events();
}
......
......@@ -65,7 +65,6 @@
data-get-items-url="{{ route('cart.getItems') }}"
data-update-item-url="{{ route('cart.updateQtyInCart') }}"
data-remove-item-url="{{ route('cart.removeFromCart') }}"
data-item-url="{{ route('productPath') }}"
>
{{-- @foreach($products as $product)
<tr>
......
......@@ -18,7 +18,7 @@ Auth::routes();
Route::get('/', 'ProductController@index')->name('homepage');
Route::prefix('product')->group(function() {
Route::post('/', 'ProductController@store')->name('productPath');
Route::post('/', 'ProductController@store');
Route::get('/create', 'ProductController@create');
Route::get('/{product}', 'ProductController@show')->name('product.show');
Route::get('/{product}/edit', 'ProductController@edit')->name('product.edit');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment