Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Add button to remove out of stock products #131

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions resources/js/components/RemoveMultipleFromCart.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<script>
import { cart } from 'Vendor/rapidez/core/resources/js/stores/useCart.js'
import { mask } from 'Vendor/rapidez/core/resources/js/stores/useMask.js'
export default {
render() {
return this.$scopedSlots.default(this)
},
methods: {
async remove() {
await Promise.all(this.outOfStockItems.map(async (item) => {
let response = await window.magentoGraphQL(
`mutation ($cart_id: String!, $cart_item_id: Int) { removeItemFromCart(input: { cart_id: $cart_id, cart_item_id: $cart_item_id }) { cart { ...cart } } } ` + config.fragments.cart,
{
cart_id: mask.value,
cart_item_id: item.id,
},
)
this.updateCart({}, response)
}))
}
},
computed: {
outOfStockItems() {
return cart.value.items.filter((item) => !this.$root.canOrderCartItem(item))
}
}
}
</script>
3 changes: 2 additions & 1 deletion resources/js/package.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
Vue.component('checkout-address', () => import('./components/CheckoutAddress.vue'))
Vue.component('checkout-success-addresses', () => import('./components/CheckoutSuccessAddresses.vue'))
Vue.component('address-card', () => import('./components/AddressCard.vue'))
Vue.component('address-card', () => import('./components/AddressCard.vue'))
Vue.component('remove-multiple-from-cart', () => import('./components/RemoveMultipleFromCart.vue'))
9 changes: 5 additions & 4 deletions resources/views/cart/overview.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
@section('robots', 'NOINDEX,NOFOLLOW')

@section('content')
<graphql v-if="mask"
:query="'query getCart($cart_id: String!) { cart (cart_id: $cart_id) { ' + config.queries.cart + ' } }'"
:variables="{ cart_id: mask }"
:callback="updateCart"
<graphql
v-if="mask"
:query="'query getCart($cart_id: String!) { cart (cart_id: $cart_id) { ...cart } } ' + config.fragments.cart"
:variables="{ cart_id: mask }"
:callback="updateCart"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to v3

:error-callback="checkResponseForExpiredCart"
>
</graphql>
Expand Down
14 changes: 12 additions & 2 deletions resources/views/cart/partials/sidebar/summary.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,27 @@
<dd>@{{ cart.prices.grand_total.value | price }}</dd>
</div>
</x-rapidez-ct::separated-listing>
<div class="w-full" :class="{ 'cursor-not-allowed': !canOrder }">
<div class="w-full">
<x-rapidez-ct::button.enhanced
:href="route('checkout')"
class="flex w-full items-center justify-center gap-1 mt-6"
v-bind:class="{ 'pointer-events-none': !canOrder }"
dusk="checkout"
v-if="canOrder"
>
@lang('To checkout')
<x-heroicon-o-arrow-right class="h-4" />
</x-rapidez-ct::button.enhanced>
</div>
<remove-multiple-from-cart v-slot="{ remove }" v-else>
<x-rapidez-ct::button.accent
@click="remove"
class="flex w-full items-center justify-center gap-1 mt-6"
dusk="remove-out-of-stock-items"
>
@lang('Remove items from cart')
</x-rapidez-ct::button.accent>
</remove-multiple-from-cart>
</div>
<div class="mt-4 flex items-center justify-center gap-1 text-center text-sm">
<x-heroicon-o-check class="h-5 text-ct-accent" />
@lang('Ordered within 2 minutes')
Expand Down
Loading