Merge pull request #5314 from devansh-webkul/wishlist-issue-fixed

Wishlist Issue Fixed #5226
This commit is contained in:
Devansh 2021-11-09 17:04:19 +05:30 committed by GitHub
commit cda58a576f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 21 deletions

View File

@ -22,6 +22,34 @@
/* add translations */
window._translations = @json($velocityHelper->jsonTranslations());
})();
/**
* Wishist form will dynamically create and execute.
*
* @param {!string} action
* @param {!string} method
* @param {!string} csrfToken
*/
function submitWishlistForm(action, method, csrfToken) {
let form = document.createElement('form');
form.method = 'POST';
form.action = action;
let _methodElement = document.createElement('input');
_methodElement.type = 'hidden';
_methodElement.name = '_method';
_methodElement.value = method;
form.appendChild(_methodElement);
let _tokenElement = document.createElement('input');
_tokenElement.type = 'hidden';
_tokenElement.name ='_token';
_tokenElement.value = csrfToken;
form.appendChild(_tokenElement);
document.body.appendChild(form);
form.submit();
}
</script>
@stack('scripts')

View File

@ -14,37 +14,23 @@
$title = $wishlist ? __('velocity::app.shop.wishlist.remove-wishlist-text') : __('velocity::app.shop.wishlist.add-wishlist-text');
@endphp
@if($wishlist)
<form
class="d-none"
id="wishlist-{{ $wishlist->id }}"
action="{{ $href }}"
method="POST">
@method('DELETE')
@csrf
</form>
@else
<form
class="d-none"
id="wishlist-{{ $product->product_id }}"
action="{{ $href }}"
method="POST">
@csrf
</form>
@endif
<a
class="unset wishlist-icon {{ $addWishlistClass ?? '' }} text-right"
href="javascript:void(0);"
title="{{ $title }}"
onclick="document.getElementById('wishlist-{{ $wishlist ? $wishlist->id : $product->product_id }}').submit();">
onclick="submitWishlistForm(
'{{ $href }}',
'{{ $wishlist ? 'DELETE' : 'POST' }}',
'{{ csrf_token() }}'
)"
>
<wishlist-component active="{{ $wishlist ? false : true }}"></wishlist-component>
@if (isset($text))
{!! $text !!}
@endif
</a>
@endauth