Skip to content

Commit

Permalink
Add package.js (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
indykoning authored Apr 6, 2023
1 parent fc97324 commit 0bf34ce
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 29 deletions.
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'

0 comments on commit 0bf34ce

Please sign in to comment.