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

Update to reaction v2 #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions client/components/wishlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./wishlist";

46 changes: 46 additions & 0 deletions lib/collections/wishlist.js
Original file line number Diff line number Diff line change
@@ -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);
43 changes: 21 additions & 22 deletions register.js
Original file line number Diff line number Diff line change
@@ -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
}
]
})
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"
}
]
});
6 changes: 4 additions & 2 deletions server/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import './lib/collections';
import "./init";
import "../lib/collections";
import "./methods/wishlist";
import "./methods/init";

10 changes: 0 additions & 10 deletions server/init.js

This file was deleted.

9 changes: 0 additions & 9 deletions server/lib/collections/collections.js

This file was deleted.

2 changes: 0 additions & 2 deletions server/lib/collections/index.js

This file was deleted.

44 changes: 0 additions & 44 deletions server/lib/collections/schemas/wishlist.js

This file was deleted.

11 changes: 11 additions & 0 deletions server/methods/init.js
Original file line number Diff line number Diff line change
@@ -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 })
}
}));
9 changes: 9 additions & 0 deletions server/methods/wishlist.js
Original file line number Diff line number Diff line change
@@ -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
});
56 changes: 56 additions & 0 deletions server/methods/wishlistMethods.js
Original file line number Diff line number Diff line change
@@ -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
}
}
}
);
}


Empty file added server/no-meteor/schema.graphql
Empty file.
74 changes: 0 additions & 74 deletions server/wishlist-functions.js

This file was deleted.