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

Add app.js, Rename vue files to their names for auto importing #11

Merged
merged 4 commits into from
Apr 6, 2023
Merged
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
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@

## Installation

```
```bash
composer require rapidez/wishlist
```

And require the Javascript in `resources/js/app.js`:
```
require('Vendor/rapidez/wishlist/resources/js/wishlist.js')
```

If you haven't published the Rapidez views yet, publish them with:
```
```bash
php artisan vendor:publish --provider="Rapidez\Wishlist\WishlistServiceProvider" --tag=views
```

### Product page

Include the wishlist button on the product page, for example in `resources/views/vendor/rapidez/product/partials/addtocart.blade.php`:
```
```blade
@include('rapidez::wishlist.product.wishlist')
```

### Product listing

Include the wishlist button on the listing items, for example in `resources/views/vendor/rapidez/listing/partials/item/addtocart.blade.php`:
```
```blade
@include('rapidez::wishlist.listing.wishlist')
```

Expand All @@ -37,7 +32,7 @@ The wishlist account page can be found on `/account/wishlist` and [will be added
### Wishlist items count

You can get the count of the customer's wishlist items by using the wishlist component. For example:
```
```blade
<wishlist v-cloak>
<span slot-scope="{ itemsCount }">
@{{ itemsCount }}
Expand Down
3 changes: 3 additions & 0 deletions resources/js/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'Vendor/rapidez/core/resources/js/vue'

Vue.component('wishlist', () => import('./components/Wishlist.vue'))
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script>
import removeProductsFromWishlist from './graphql/removeProductsFromWishlist'
import addProductsToWishlist from './graphql/addProductsToWishlist'
import removeProductsFromWishlist from '../graphql/removeProductsFromWishlist'
import addProductsToWishlist from '../graphql/addProductsToWishlist'

export default {
props: {
Expand Down
14 changes: 14 additions & 0 deletions resources/js/eventlisteners.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
document.addEventListener('turbo:load', () => {
window.app.$on('logged-in', async () => {
let response = await axios.post(config.magento_url + '/graphql', {
query: '{ customer { wishlists { id items_v2 { items { id product { sku id } } } } } }'
}, { headers: { Authorization: `Bearer ${localStorage.token}`, Store: config.store_code }})

localStorage.wishlist = JSON.stringify(response.data.data.customer.wishlists[0])
window.app.$emit('wishlist-changed')
});

window.app.$on('logout', () => {
localStorage.removeItem('wishlist')
});
})
2 changes: 2 additions & 0 deletions resources/js/package.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import './components'
import './eventlisteners'
18 changes: 1 addition & 17 deletions resources/js/wishlist.js
Original file line number Diff line number Diff line change
@@ -1,17 +1 @@
import wishlist from 'Vendor/rapidez/wishlist/resources/js/Wishlist.vue'
Vue.component('wishlist', wishlist)

document.addEventListener('turbo:load', () => {
window.app.$on('logged-in', async () => {
let response = await axios.post(config.magento_url + '/graphql', {
query: '{ customer { wishlists { id items_v2 { items { id product { sku id } } } } } }'
}, { headers: { Authorization: `Bearer ${localStorage.token}`, Store: config.store_code }})

localStorage.wishlist = JSON.stringify(response.data.data.customer.wishlists[0])
window.app.$emit('wishlist-changed')
});

window.app.$on('logout', () => {
localStorage.removeItem('wishlist')
});
})
import './package'