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 ...@@ -74,7 +74,8 @@ class CartController extends Controller
// make array of products in order to get correct order of items in js // make array of products in order to get correct order of items in js
$cart_products = []; $cart_products = [];
foreach ($cart->items as $item) { foreach ($cart->items as $id => $item) {
$item['productLink'] = route('product.show', $id);
$cart_products[] = $item; $cart_products[] = $item;
} }
......
...@@ -11,7 +11,6 @@ class Cart { ...@@ -11,7 +11,6 @@ class Cart {
this.totalPrice; this.totalPrice;
this.updateItemUrl = cartElem.dataset.updateItemUrl; this.updateItemUrl = cartElem.dataset.updateItemUrl;
this.removeItemUrl = cartElem.dataset.removeItemUrl; this.removeItemUrl = cartElem.dataset.removeItemUrl;
this.itemUrl = cartElem.dataset.itemUrl;
this.hasEvents; this.hasEvents;
this.updateItemQty = this.updateItemQty.bind(this); this.updateItemQty = this.updateItemQty.bind(this);
this.removeItemFromCart = this.removeItemFromCart.bind(this); this.removeItemFromCart = this.removeItemFromCart.bind(this);
...@@ -23,7 +22,7 @@ class Cart { ...@@ -23,7 +22,7 @@ class Cart {
<div class="row"> <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-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"> <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> <p>${product.item.description_short}</p>
</div> </div>
</div> </div>
...@@ -75,8 +74,7 @@ class Cart { ...@@ -75,8 +74,7 @@ class Cart {
this.sendUpdateItemQtyRequest({ productId, changedQty }) this.sendUpdateItemQtyRequest({ productId, changedQty })
.then( (response) => { .then( (response) => {
this.show(); this.show('Quantity updated');
toastr.success('Quantity updated');
}) })
.catch( (error) => { .catch( (error) => {
console.log(error); console.log(error);
...@@ -100,8 +98,7 @@ class Cart { ...@@ -100,8 +98,7 @@ class Cart {
this.sendRemoveItemRequest({ productId }) this.sendRemoveItemRequest({ productId })
.then( (response) => { .then( (response) => {
this.show(); this.show('Product deleted');
toastr.success('Product deleted');
}) })
.catch( (error) => { .catch( (error) => {
console.log(error); console.log(error);
...@@ -121,7 +118,7 @@ class Cart { ...@@ -121,7 +118,7 @@ class Cart {
} }
show() { show(successMessage) {
if (!this.loaderElem.classList.contains('loader-show')) { if (!this.loaderElem.classList.contains('loader-show')) {
this.loaderElem.classList.toggle('loader-show'); this.loaderElem.classList.toggle('loader-show');
} }
...@@ -141,6 +138,10 @@ class Cart { ...@@ -141,6 +138,10 @@ class Cart {
this.showProducts(); this.showProducts();
this.toggleLoager(); this.toggleLoager();
if (successMessage) {
toastr.success(successMessage);
}
if (!this.hasEvents) { if (!this.hasEvents) {
this.events(); this.events();
} }
......
...@@ -65,7 +65,6 @@ ...@@ -65,7 +65,6 @@
data-get-items-url="{{ route('cart.getItems') }}" data-get-items-url="{{ route('cart.getItems') }}"
data-update-item-url="{{ route('cart.updateQtyInCart') }}" data-update-item-url="{{ route('cart.updateQtyInCart') }}"
data-remove-item-url="{{ route('cart.removeFromCart') }}" data-remove-item-url="{{ route('cart.removeFromCart') }}"
data-item-url="{{ route('productPath') }}"
> >
{{-- @foreach($products as $product) {{-- @foreach($products as $product)
<tr> <tr>
......
...@@ -18,7 +18,7 @@ Auth::routes(); ...@@ -18,7 +18,7 @@ Auth::routes();
Route::get('/', 'ProductController@index')->name('homepage'); Route::get('/', 'ProductController@index')->name('homepage');
Route::prefix('product')->group(function() { Route::prefix('product')->group(function() {
Route::post('/', 'ProductController@store')->name('productPath'); Route::post('/', 'ProductController@store');
Route::get('/create', 'ProductController@create'); Route::get('/create', 'ProductController@create');
Route::get('/{product}', 'ProductController@show')->name('product.show'); Route::get('/{product}', 'ProductController@show')->name('product.show');
Route::get('/{product}/edit', 'ProductController@edit')->name('product.edit'); 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