Merge pull request #5998 from ILDaviz/delete-all-item-cart

Remove all cart items at once
This commit is contained in:
Jitendra Singh 2022-04-20 13:51:36 +05:30 committed by GitHub
commit af7ea4d8c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 173 additions and 32 deletions

View File

@ -294,6 +294,40 @@ class Cart
return false;
}
/**
* Remove all items from cart.
*
* @return \Webkul\Checkout\Models\Cart|null
*/
public function removeAllItems(): ?CartModel
{
$cart = $this->getCart();
Event::dispatch('checkout.cart.delete.all.before', $cart);
if (! $cart) {
return $cart;
}
foreach ($cart->items as $item) {
$this->cartItemRepository->delete($item->id);
if ($cart->items->count() == 0) {
$this->cartRepository->delete($cart->id);
if (session()->has('cart')) {
session()->forget('cart');
}
}
}
$cart->save();
Event::dispatch('checkout.cart.delete.all.after', $cart);
return $cart;
}
/**
* Remove cart items, whose product is inactive.
*

View File

@ -105,6 +105,22 @@ class CartController extends Controller
return redirect()->back();
}
/**
* Removes the item from the cart if it exists.
*
* @return \Illuminate\Http\Response
*/
public function removeAllItems()
{
$result = Cart::removeAllItems();
if ($result) {
session()->flash('success', trans('shop::app.checkout.cart.item.success-all-remove'));
}
return redirect()->back();
}
/**
* Updates the quantity of the items present in the cart.
*

View File

@ -503,6 +503,8 @@ return [
'continue-registration' => 'متابعة التسجيل',
'proceed-to-checkout' => 'انتقل إلى الخروج',
'remove' => 'احذف',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'remove-link' => 'احذف',
'move-to-wishlist' => 'انقل إلى قائمة الأمنيات',
'move-to-wishlist-success' => 'نقل العنصر إلى قائمة الأمنيات',
@ -521,6 +523,7 @@ return [
'success' => 'تم بنجاح إضافة العنصر إلى العربة',
'success-remove' => 'تم إزالة العنصر بنجاح من العربة',
'error-add' => 'لا يمكن إضافة العنصر إلى العربة ، رجاء حاول مرة أخرى ',
'success-all-remove' => 'All items is successfully removed from the cart.',
'inactive' => 'An item is inactive and was removed from cart',
'inactive-add' => 'Inactive item cannot be added to cart',
],

View File

@ -501,6 +501,8 @@ return [
'proceed-to-checkout' => 'Zur Kasse',
'remove' => 'Entfernen',
'remove-link' => 'Entfernen',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Zur Wunschliste verschieben',
'move-to-wishlist-success' => 'Artikel wurde erfolgreich auf die Wunschliste verschoben.',
'move-to-wishlist-error' => 'Das Objekt kann nicht auf die Wunschliste verschoben werden. Bitte versuchen Sie es später erneut.',
@ -517,6 +519,7 @@ return [
'error_remove' => 'Keine Artikel aus dem Warenkorb zu entfernen',
'success' => 'Artikel wurde erfolgreich zum Warenkorb hinzugefügt',
'success-remove' => 'Artikel wurde erfolgreich aus dem Warenkorb entfernt',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Artikel kann nicht zum Warenkorb hinzugefügt werden. Bitte versuchen Sie es später erneut',
'inactive' => 'Ein Artikel ist inaktiv und wurde aus dem Warenkorb entfernt.',
'inactive-add' => 'Ein inaktiver Artikel kann nicht zum Warenkorb hinzugefügt werde.',

View File

@ -160,7 +160,7 @@ return [
'not-activated' => 'Your activation seeks admin approval',
'resend-verification' => 'Resend verification mail again',
'show-password' => 'Show Password',
],
'forgot-password' => [
@ -500,6 +500,8 @@ return [
'empty' => 'Your shopping cart is empty',
'update-cart' => 'Update Cart',
'continue-shopping' => 'Continue Shopping',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'continue-registration' => 'Continue Registration',
'proceed-to-checkout' => 'Proceed To Checkout',
'remove' => 'Remove',
@ -519,6 +521,7 @@ return [
'error_remove' => 'No items to remove from the cart.',
'success' => 'Item is successfully added to cart.',
'success-remove' => 'Item is successfully removed from the cart.',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Item cannot be added to cart, please try again later.',
'inactive' => 'An item is inactive and was removed from cart.',
'inactive-add' => 'Inactive item cannot be added to cart.',

View File

@ -505,6 +505,8 @@ return [
'proceed-to-checkout' => 'Continuar con el pago',
'remove' => 'Eliminar',
'remove-link' => 'Eliminar',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Mover a la lista de deseos',
'move-to-wishlist-success' => 'Artículo movido a la lista de deseos',
'move-to-wishlist-error' => 'El artículo no se puede añadir a la lista de deseos, por favor inténtalo más tarde',
@ -520,6 +522,7 @@ return [
'error_remove' => 'No hay artículos que eliminar en el carrito',
'success' => 'El artículo se añadió al carrito',
'success-remove' => 'El artículo se eliminó del carrito',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'El artículo no se puede añadir al carrito, inténtelo más tarde',
'inactive' => 'Un artículo está inactivo y se eliminó del carrito.',
'inactive-add' => 'El artículo inactivo no se puede agregar al carrito',

View File

@ -501,6 +501,8 @@ return [
'proceed-to-checkout' => 'ادامه به پرداخت',
'remove' => 'برداشتن',
'remove-link' => 'برداشتن',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'انتقال به لیست دلخواه',
'move-to-wishlist-success' => 'مورد به لیست دلخواه منتقل شد',
'move-to-wishlist-error' => 'نمی توان مورد را به لیست علاقه مندی ها انتقال داد ، لطفا بعداً دوباره امتحان کنید',
@ -517,6 +519,7 @@ return [
'error_remove' => 'هیچ موردی برای حذف از سبد خرید وجود ندارد',
'success' => 'مورد با موفقیت به سبد خرید اضافه شد',
'success-remove' => 'مورد با موفقیت از سبد خرید حذف شد',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'لطفاً موردی را به سبد خرید اضافه نکرد ، لطفا بعداً دوباره امتحان کنید',
'inactive' => 'An item is inactive and was removed from cart',
'inactive-add' => 'Inactive item cannot be added to cart',

View File

@ -500,6 +500,8 @@ return [
'proceed-to-checkout' => 'Passer à la caisse',
'remove' => 'Supprimer',
'remove-link' => 'Supprimer',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Placer dans la liste de souhaits',
'move-to-wishlist-success' => 'L\'article a été déplacé vers la liste de souhaits avec succès.',
'move-to-wishlist-error' => 'Impossible de déplacer l\'élément vers la liste de souhaits, veuillez réessayer plus tard.',
@ -517,6 +519,7 @@ return [
'error_remove' => 'Aucun article à retirer du panier.',
'success' => 'L\'article a été ajouté au panier avec succès.',
'success-remove' => 'L\'article a été supprimé avec succès du panier.',
'remove-all-items' => 'Remove all items',
'error-add' => 'L\'article ne peut pas être ajouté au panier, veuillez réessayer plus tard.',
'inactive' => 'Un article est inactif et a été supprimé du panier.',
'inactive-add' => 'L\'article inactif ne peut pas être ajouté au panier.',

View File

@ -503,6 +503,8 @@ return [
'proceed-to-checkout' => 'चेक आउट करने के लिए आगे बढ़ें',
'remove' => 'निकालना',
'remove-link' => 'निकालना',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'इच्छा सूची की ओर बदें',
'move-to-wishlist-success' => 'आइटम सफलतापूर्वक इच्छा सूची में ले जाया गया।',
'move-to-wishlist-error' => 'आइटम को इच्छा सूची में नहीं ले जाया जा सकता, कृपया बाद में पुन: प्रयास करें।',
@ -518,6 +520,7 @@ return [
'error_remove' => 'कार्ट से निकालने के लिए कोई आइटम नहीं है।',
'success' => 'आइटम सफलतापूर्वक कार्ट में जोड़ा गया।',
'success-remove' => 'आइटम कार्ट से सफलतापूर्वक हटा दिया गया है।',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'आइटम कार्ट में नहीं जोड़ा जा सकता, कृपया बाद में पुन: प्रयास करें।',
'inactive' => 'एक आइटम निष्क्रिय है और उसे कार्ट से निकाल दिया गया था।',
'inactive-add' => 'निष्क्रिय आइटम कार्ट में नहीं जोड़ा जा सकता है।',

View File

@ -498,6 +498,8 @@ return [
'empty' => 'Il tuo carrello è ancora vuoto',
'update-cart' => 'Aggiorna Carrello',
'continue-shopping' => 'Continua con i tuoi acquisti',
'remove-all-items' => 'Rimuovi tutti i prodotti',
'confirm-action' => 'Confermi questa azione?',
'continue-registration' => 'Continua la registrazione',
'proceed-to-checkout' => 'Procedi alla Cassa',
'remove' => 'Rimuovi',
@ -518,6 +520,7 @@ return [
'error_remove' => 'Nessun prodotto da rimuovere nel carrello.',
'success' => 'Prodotto aggiunto al carrello.',
'success-remove' => 'Prodotto rimosso dal carrello.',
'success-all-remove' => 'Tutti i prodotti sono rimossi dal carrello',
'error-add' => 'Il prodotto non può essere aggiunto al carrello, prova ancora.',
'inactive' => 'An item is inactive and was removed from cart.',
'inactive-add' => 'Inactive item cannot be added to cart.',

View File

@ -467,6 +467,8 @@ return [
'proceed-to-checkout' => '購入手続きに進む',
'remove' => '削除',
'remove-link' => '削除',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'お気に入りに移動する',
'move-to-wishlist-success' => 'アイテムがお気に入りに追加されました。',
'move-to-wishlist-error' => 'アイテムをお気に入りに追加することができませんでした。しばらくしてから再度お試し下さい。',
@ -482,6 +484,7 @@ return [
'error_remove' => 'カートに削除するアイテムがございません。',
'success' => 'アイテムがカートに追加されました。',
'success-remove' => 'アイテムがカートから削除されました。',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'アイテムをカートに追加できません。しばらくしてから再度お試し下さい。',
'inactive' => 'An item is inactive and was removed from cart',
'inactive-add' => 'Inactive item cannot be added to cart',

View File

@ -509,6 +509,8 @@ return [
'proceed-to-checkout' => 'Ga naar de kassa',
'remove' => 'Verwijderen',
'remove-link' => 'Verwijderen',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Verplaats naar wens lijst',
'move-to-wishlist-success' => 'Item is succesvol naar de verlanglijst verplaatst.',
'move-to-wishlist-error' => 'Kan item niet naar verlanglijstje verplaatsen, probeer het later opnieuw.',
@ -525,6 +527,7 @@ return [
'error_remove' => 'Geen items om uit de winkelwagen te verwijderen.',
'success' => 'Artikel is succesvol toegevoegd aan winkelwagen.',
'success-remove' => 'Item is met succes uit de winkelwagen verwijderd.',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Item kan niet aan winkelwagen worden toegevoegd. Probeer het later opnieuw.',
'inactive' => 'An item is inactive and was removed from cart.',
'inactive-add' => 'Inactive item cannot be added to cart.',

View File

@ -502,6 +502,8 @@ return [
'proceed-to-checkout' => 'Przejdź do kasy”',
'remove' => 'Usuń',
'remove-link' => 'Usuń',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Przenieś na listę wyboru',
'move-to-wishlist-success' => 'Produkt został pomyślnie przeniesiony na listę wyboru.',
'move-to-wishlist-error' => 'Nie można przenieść ptoduktu na listę życzeń, spróbuj ponownie później.',
@ -518,6 +520,7 @@ return [
'error_remove' => 'Brak produktów do usunięcia z koszyka.',
'success' => 'Produkt został pomyślnie dodany do koszyka.',
'success-remove' => 'Produkt został pomyślnie usunięty z koszyka.',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Nie można dodać produktu do koszyka, spróbuj ponownie później.',
'inactive' => 'An item is inactive and was removed from cart.',
'inactive-add' => 'Inactive item cannot be added to cart.',

View File

@ -493,6 +493,8 @@ return [
'proceed-to-checkout' => 'Finalizar Compra',
'remove' => 'Remover',
'remove-link' => 'Remover',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Mover para Lista de Desejos',
'move-to-wishlist-success' => 'Item Movido para Lista de Desejos',
'move-to-wishlist-error' => 'Não foi possivel Mover Item para Lista de Desejos, Por favor, tente novamente mais tarde',
@ -509,6 +511,7 @@ return [
'error_remove' => 'Nenhum item para remover do carrinho',
'success' => 'Item foi adicionado com sucesso ao carrinho',
'success-remove' => 'Item foi removido com sucesso do carrinho',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Item não pode ser adicionado ao carrinho, por favor, tente novamente mais tarde',
'inactive' => 'An item is inactive and was removed from cart',
'inactive-add' => 'Inactive item cannot be added to cart',

View File

@ -502,6 +502,8 @@ return [
'proceed-to-checkout' => 'Satın Al',
'remove' => 'Kaldır',
'remove-link' => 'Kaldır',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => 'Dilek Listesine Ekle',
'move-to-wishlist-success' => 'Dilek listesine başarıyla eklendi.',
'move-to-wishlist-error' => 'Dilek listesine eklenirken hata oluştu, lütfen tekrar deneyin.',
@ -518,6 +520,7 @@ return [
'error_remove' => 'Sepetten kaldırılacak ürün bulunamadı.',
'success' => 'Ürün başarıyla sepete eklendi.',
'success-remove' => 'Ürün sepetten başarıyla kaldırıldı.',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => 'Ürün sepete eklenirken hata oluştu, lütfen tekrar deneyin.',
'inactive' => 'An item is inactive and was removed from cart.',
'inactive-add' => 'Inactive item cannot be added to cart.',

View File

@ -502,6 +502,8 @@ return [
'proceed-to-checkout' => '进行结算',
'remove' => '移除',
'remove-link' => '移除',
'remove-all-items' => 'Remove all items',
'confirm-action' => 'Confirm this action?',
'move-to-wishlist' => '移动到愿望清单',
'move-to-wishlist-success' => '项目已成功移至愿望清单.',
'move-to-wishlist-error' => '无法将商品移至愿望清单, 请稍后再试.',
@ -518,6 +520,7 @@ return [
'error_remove' => '没有要从购物车中删除的物品.',
'success' => '商品已成功添加到购物车.',
'success-remove' => '物品已成功从购物车中移除.',
'success-all-remove' => 'All items is successfully removed from the cart.',
'error-add' => '商品无法加入购物车, 请稍后再试.',
'inactive' => '商品处于非活动状态并已从购物车中移除.',
'inactive-add' => '不活跃商品无法添加到购物车.',

View File

@ -13,6 +13,20 @@
<div class="cart-content">
<div class="left-side">
<div style="display: flex;justify-content: flex-end;margin-bottom: 20px;">
<form
method="POST"
action="{{ route('cart.remove.all.items') }}">
@csrf
<button
type="submit"
onclick="return confirm('{{ __('shop::app.checkout.cart.confirm-action') }}')"
class="btn btn-lg btn-primary">
{{ __('shop::app.checkout.cart.remove-all-items') }}
</button>
</form>
</div>
<form action="{{ route('shop.checkout.cart.update') }}" method="POST" @submit.prevent="onSubmit">
<div class="cart-item-list" style="margin-top: 0">
@ -86,27 +100,27 @@
<a href="{{ route('shop.checkout.cart.remove', $item->id) }}" onclick="removeLink('{{ __('shop::app.checkout.cart.cart-remove-action') }}')">{{ __('shop::app.checkout.cart.remove-link') }}</a></span>
@auth('customer')
@php
$showWishlist = core()->getConfigData('general.content.shop.wishlist_option') == "1" ? true : false;
@endphp
@php
$showWishlist = core()->getConfigData('general.content.shop.wishlist_option') == "1" ? true : false;
@endphp
@if ($showWishlist)
<span class="towishlist">
@if ($showWishlist)
<span class="towishlist">
@if ($item->parent_id != 'null' ||$item->parent_id != null)
<a
href="javascript:void(0);"
onclick="moveToWishlist('{{ __('shop::app.checkout.cart.cart-remove-action') }}', '{{ route('shop.movetowishlist', $item->id) }}')">
<a
href="javascript:void(0);"
onclick="moveToWishlist('{{ __('shop::app.checkout.cart.cart-remove-action') }}', '{{ route('shop.movetowishlist', $item->id) }}')">
{{ __('shop::app.checkout.cart.move-to-wishlist') }}
</a>
@else
<a
href="javascript:void(0);"
onclick="moveToWishlist('{{ __('shop::app.checkout.cart.cart-remove-action') }}', '{{ route('shop.movetowishlist', $item->child->id) }}')">
@else
<a
href="javascript:void(0);"
onclick="moveToWishlist('{{ __('shop::app.checkout.cart.cart-remove-action') }}', '{{ route('shop.movetowishlist', $item->child->id) }}')">
{{ __('shop::app.checkout.cart.move-to-wishlist') }}
</a>
@endif
@endif
</span>
@endif
@endif
@endauth
</div>
@ -130,9 +144,9 @@
<div style="display:flex;">
@if ($cart->hasProductsWithQuantityBox())
<button type="submit" class="btn btn-lg btn-primary" id="update_cart_button">
{{ __('shop::app.checkout.cart.update-cart') }}
</button>
<button type="submit" class="btn btn-lg btn-primary" id="update_cart_button">
{{ __('shop::app.checkout.cart.update-cart') }}
</button>
@endif
@if (! cart()->hasError())

View File

@ -33,6 +33,8 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
Route::get('checkout/cart/remove/{id}', [CartController::class, 'remove'])->name('cart.remove');
Route::post('checkout/cart/remove}', [CartController::class, 'removeAllItems'])->name('cart.remove.all.items');
Route::post('/checkout/cart', [CartController::class, 'updateBeforeCheckout'])->defaults('_config', [
'redirect' => 'shop.checkout.cart.index'
])->name('shop.checkout.cart.update');

View File

@ -142,4 +142,20 @@ class CartController extends Controller
'message' => trans('velocity::app.error.something_went_wrong'),
]);
}
/**
* Removes the item from the cart if it exists.
*
* @return \Illuminate\Http\Response
*/
public function removeAllItems()
{
$result = Cart::removeAllItems();
if ($result) {
session()->flash('success', trans('shop::app.checkout.cart.item.success-all-remove'));
}
return redirect()->back();
}
}

View File

@ -182,22 +182,36 @@
</div>
{!! view_render_event('bagisto.shop.checkout.cart.controls.after', ['cart' => $cart]) !!}
<div class="misc">
<a
class="theme-btn light fs16 text-center"
href="{{ route('shop.home.index') }}">
{{ __('shop::app.checkout.cart.continue-shopping') }}
</a>
<div class="misc">
<a
class="theme-btn light fs16 text-center"
href="{{ route('shop.home.index') }}">
{{ __('shop::app.checkout.cart.continue-shopping') }}
</a>
@if ($item->product->getTypeInstance()->showQuantityBox() === true)
<button
type="submit"
class="theme-btn light unset">
<form
method="POST"
@submit.prevent="onSubmit"
action="{{ route('velocity.cart.remove.all.items') }}">
@csrf
<button
type="submit"
onclick="return confirm('{{ __('shop::app.checkout.cart.confirm-action') }}')"
class="theme-btn light unset">
{{ __('shop::app.checkout.cart.update-cart') }}
</button>
@endif
</div>
{{ __('shop::app.checkout.cart.remove-all-items') }}
</button>
</form>
@if ($item->product->getTypeInstance()->showQuantityBox() === true)
<button
type="submit"
class="theme-btn light unset">
{{ __('shop::app.checkout.cart.update-cart') }}
</button>
@endif
</div>
{!! view_render_event('bagisto.shop.checkout.cart.controls.after', ['cart' => $cart]) !!}
</form>

View File

@ -80,6 +80,9 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function
Route::delete('/cart/remove/{id}', [CartController::class, 'removeProductFromCart'])
->name('velocity.cart.remove.product');
Route::post('/cart/remove-all', [CartController::class, 'removeAllItems'])
->name('velocity.cart.remove.all.items');
Route::get('/categories', [ShopController::class, 'fetchCategories'])
->name('velocity.categoriest');