diff --git a/client/components/wishlist.js b/client/components/wishlist.js index 2fb4e5f2d..62fa504fc 100644 --- a/client/components/wishlist.js +++ b/client/components/wishlist.js @@ -59,12 +59,12 @@ class Wishlist extends Component { } } -Wishlist.propTypes = { - variant: PropTypes.object, - isWished: PropTypes.bool, - user: PropTypes.object, - onWishlistClick: PropTypes.func -} +// Wishlist.propTypes = { +// variant: PropTypes.object, +// isWished: PropTypes.bool, +// user: PropTypes.object, +// onWishlistClick: PropTypes.func +// } registerComponent({ name: "Wishlist", diff --git a/server/lib/collections/schemas/index.js b/lib/collections/index.js similarity index 96% rename from server/lib/collections/schemas/index.js rename to lib/collections/index.js index 252dab9dd..541412416 100644 --- a/server/lib/collections/schemas/index.js +++ b/lib/collections/index.js @@ -1 +1,2 @@ export * from "./wishlist"; + diff --git a/lib/collections/wishlist.js b/lib/collections/wishlist.js new file mode 100644 index 000000000..587030f6d --- /dev/null +++ b/lib/collections/wishlist.js @@ -0,0 +1,46 @@ +import SimpleSchema from "simpl-schema"; +import { registerSchema } from "@reactioncommerce/schemas"; + +/** + * OrderItems Schema + * merges with Cart and Order to create Orders collection + */ +export const WishListItem = new SimpleSchema({ + productId: { + type: String, + optional: false + }, + variantId: { + type: String, + optional: true + }, + title: { + // Why do we want this? + type: String, + defaultValue: "", + label: "Product Title" + } +}); + +/** + * Order Schema + */ +export const Wishlist = new SimpleSchema({ + Id: { + type: String, + optional: true + }, + userId: { + type: String, + unique: true + }, + items: { + type: Array + }, + "items.$": { + type: WishListItem, + } +}); + +registerSchema("Wishlist", Wishlist); +registerSchema("WishListItem", WishListItem); diff --git a/register.js b/register.js index e41818b8b..be3ac1129 100644 --- a/register.js +++ b/register.js @@ -1,24 +1,23 @@ -import { Reaction } from '/server/api'; +import Reaction from "/imports/plugins/core/core/server/Reaction"; Reaction.registerPackage({ - label: 'Classic WishList functionality for reaction', - name: 'reaction-wish-list', - icon: 'fa fa-thumb-tack', - autoEnable: true, - settings: { - }, - registry: [ - { - provides: 'dashboard', - label: 'Wishlist', - description: 'Classic wish list functionality', - route: '/dashboard/wishlist', - icon: 'fa fa-thumb-tack', - container: 'core', - template: 'wishlist', - name: 'dashboardProductImporter', - workflow: 'coreWorkflow', - priority: 2 - } - ] -}) \ No newline at end of file + label: "Classic WishList functionality for reaction", + name: "reaction-wish-list", + icon: "fa fa-thumb-tack", + autoEnable: true, + settings: {}, + registry: [ + { + container: "core", + description: "Classic wish list functionality", + icon: "fa fa-thumb-tack", + label: "Wishlist", + name: "dashboardProductImporter", + priority: 2, + provides: "dashboard", + route: "/dashboard/wishlist", + template: "wishlist", + workflow: "coreWorkflow" + } + ] +}); diff --git a/server/index.js b/server/index.js index f1d2772b1..9fe4c3343 100644 --- a/server/index.js +++ b/server/index.js @@ -1,2 +1,4 @@ -import './lib/collections'; -import "./init"; +import "../lib/collections"; +import "./methods/wishlist"; +import "./methods/init"; + diff --git a/server/init.js b/server/init.js deleted file mode 100644 index 2390cab45..000000000 --- a/server/init.js +++ /dev/null @@ -1,10 +0,0 @@ -import { Meteor } from "meteor/meteor"; -import { Wishlist } from "./lib/collections"; -import { Hooks, Reaction, Logger } from "/server/api"; - -Meteor.users.after.insert(function (userId, doc) { - if ( doc.emails.length != 0 ) { - Logger.info("::: Creating wishlist for user: #" + doc._id); - Wishlist.insert({ userId: doc._id }) - } -}); diff --git a/server/lib/collections/collections.js b/server/lib/collections/collections.js deleted file mode 100644 index 266ef3b12..000000000 --- a/server/lib/collections/collections.js +++ /dev/null @@ -1,9 +0,0 @@ -import { Mongo } from "meteor/mongo"; -import * as Schemas from "./schemas"; - -export const Wishlist = new Mongo.Collection("Wishlist"); - -Wishlist.attachSchema([ - Schemas.Wishlist, - Schemas.WishlistItem -]); diff --git a/server/lib/collections/index.js b/server/lib/collections/index.js deleted file mode 100644 index e35f2b7fd..000000000 --- a/server/lib/collections/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./collections"; - diff --git a/server/lib/collections/schemas/wishlist.js b/server/lib/collections/schemas/wishlist.js deleted file mode 100644 index 0ac59d533..000000000 --- a/server/lib/collections/schemas/wishlist.js +++ /dev/null @@ -1,44 +0,0 @@ -import { SimpleSchema } from "meteor/aldeed:simple-schema"; - -/** -* OrderItems Schema -* merges with Cart and Order to create Orders collection -*/ -export const WishListItem = new SimpleSchema({ - productId: { - type: String, - optional: false - }, - variantId: { - type: String, - optional: true - }, - title: { // Why do we want this? - type: String, - defaultValue: "", - label: "Product Title" - } - -}); - - - -/** - * Order Schema - */ -export const Wishlist = new SimpleSchema({ - - Id: { - type: String, - optional: true - }, - userId: { - type: String, - unique:true - }, - items: { - type: [WishListItem], - optional: true - } - -}); diff --git a/server/methods/init.js b/server/methods/init.js new file mode 100644 index 000000000..65b347e91 --- /dev/null +++ b/server/methods/init.js @@ -0,0 +1,11 @@ +import Logger from "@reactioncommerce/logger"; +import { Wishlist } from "/lib/collections"; +import Hooks from "@reactioncommerce/hooks"; + + +Hooks.Events.run("afterAccountsInsert", (function (userId, doc) { + if ( doc.emails.length != 0 ) { + Logger.info("::: Creating wishlist for user: #" + doc._id); + Wishlist.insert({ userId: doc._id }) + } +})); diff --git a/server/wishlist-collection.app-test.js b/server/methods/wishlist-collection.app-test.js similarity index 100% rename from server/wishlist-collection.app-test.js rename to server/methods/wishlist-collection.app-test.js diff --git a/server/methods/wishlist.js b/server/methods/wishlist.js new file mode 100644 index 000000000..81ad5a3b9 --- /dev/null +++ b/server/methods/wishlist.js @@ -0,0 +1,9 @@ +import { Meteor } from "meteor/meteor"; +import * as WishlistMethods from "./wishlistMethods"; + +Meteor.methods({ + createWishlist: WishlistMethods.createWishlist, + addToWishlist: WishlistMethods.addToWishlist, + removeFromWishlist: WishlistMethods.removeFromWishlist, + getWishList: WishlistMethods.getWishlist +}); diff --git a/server/methods/wishlistMethods.js b/server/methods/wishlistMethods.js new file mode 100644 index 000000000..30273116d --- /dev/null +++ b/server/methods/wishlistMethods.js @@ -0,0 +1,56 @@ +import { Meteor } from "meteor/meteor"; +import { Wishlist } from "/lib/collections"; +import { check } from "meteor/check"; + +export function getWishlist(userId) { + return Wishlist.findOne({ userId }); +} + +export function createWishlist(userId) { + check(userId, String); + const wishlistId = Wishlist.insert({ userId }); + return Wishlist.findOne({ _id: wishlistId }); +} + +export function addToWishlist(userId, product) { + check(userId, String); + check(product, Object); + let aWishlist = Wishlist.findOne({ userId }); + if (aWishlist == undefined) aWishlist = createWishlist(userId); + + return Wishlist.update( + { + _id: aWishlist._id + }, + { + $push: { + items: { + _id: Random.id(), + productId: product._id, + title: product.title + } + } + } + ); +} + +export function removeFromWishlist(userId, product, variantId) { + check(userId, String); + check(product, Object); + + const aWishlist = Wishlist.findOne({ userId }); + return Wishlist.update( + { + _id: aWishlist._id + }, + { + $pull: { + items: { + productId: product._id + } + } + } + ); +} + + diff --git a/server/no-meteor/schema.graphql b/server/no-meteor/schema.graphql new file mode 100644 index 000000000..e69de29bb diff --git a/server/wishlist-functions.js b/server/wishlist-functions.js deleted file mode 100644 index c1b94fac2..000000000 --- a/server/wishlist-functions.js +++ /dev/null @@ -1,74 +0,0 @@ -import {Meteor} from "meteor/meteor"; -import * as Collections from "/lib/collections"; -import {Reaction} from "/server/api"; -import {Products, Accounts} from "/lib/collections"; -import {Wishlist} from "./lib/collections" -import { check } from 'meteor/check' -//import * as Schemas from "/lib/collections/schemas - - -export function getWishlist(userId){ - const wishlistId=Wishlist.insert({userId: userId}); - return Wishlist.findOne({userId: userId}) - -} - -export function createWishlist(userId){ - check(userId, String) - const wishlistId=Wishlist.insert({userId:userId}); - return Wishlist.findOne({_id: wishlistId}) -} - - -export function addToWishlist(userId, product){ - - var aWishlist = Wishlist.findOne({userId: userId}); - if(aWishlist == undefined) - aWishlist=createWishlist(userId); - - return Wishlist.update({ - _id: aWishlist._id - }, { - $push: { - items: { - "_id": Random.id(), - "productId": product._id, - "title": product.title, - } - } - }); -} - - -export function removeFromWishlist(userId, product, variantId){ - var aWishlist = Wishlist.findOne({userId: userId}); - return Wishlist.update({ - _id: aWishlist._id - }, { - $pull: { - items: { - productId: product._id - } - } - }); - - -} - -Meteor.methods({ - "createWishlist": function(userId){ - check(userId,String); - createWishlist(userId); - }, - "addToWishlist": function(userId,product){ - check(userId,String); - check(product,Object); - addToWishlist(userId,product); - }, - "removeFromWishlist": function(userId,product){ - check(userId,String); - check(product,Object); - removeFromWishlist(userId,product); - } - -});