products.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const state = {
  2. products: [],
  3. selectedProducts: []
  4. }
  5. const getters = {
  6. getProducts (state) {
  7. return state.products
  8. },
  9. hasSelectedProducts (state) {
  10. return state.selectedProducts.length !== 0
  11. }
  12. }
  13. const mutations = {
  14. pushProducts(state, payload) {
  15. state.products = payload.products
  16. },
  17. selectProducts (state, payload) {
  18. state.selectedProducts = []
  19. payload.products.forEach(item => {
  20. state.products.push(item)
  21. });
  22. }
  23. }
  24. const actions = {
  25. fetchProducts ({ commit }) {
  26. let product = new openerp.web.Model('product.product')
  27. product.query(['name', 'display_name', 'list_price', 'qty_available', 'image_medium']).all().then(response => {
  28. commit('pushProducts', {
  29. products: response
  30. })
  31. }).fail(error => {
  32. console.log(error)
  33. })
  34. },
  35. selectProduct({ commit }) {
  36. }
  37. }
  38. export default {
  39. state,
  40. getters,
  41. mutations,
  42. actions
  43. }