items: function () { const product = addProduct(); const variant = Products.findOne({ ancestors: [product._id] }); const childVariants = Products.find({ ancestors: [ product._id, variant._id ] }).fetch(); const selectedOption = Random.choice(childVariants); const product2 = addProduct(); const variant2 = Products.findOne({ ancestors: [product2._id] }); const childVariants2 = Products.find({ ancestors: [ product2._id, variant2._id ] }).fetch(); const selectedOption2 = Random.choice(childVariants2); return [{ _id: itemIdOne, title: "firstItem", shopId: product.shopId, productId: product._id, quantity: 1, product: product, variants: selectedOption, workflow: { status: "new" } }, { _id: itemIdTwo, title: "secondItem", shopId: product2.shopId, productId: product2._id, quantity: 1, product: product2, variants: selectedOption2, workflow: { status: "new" } }]; },
export function getCartItem(options = {}) { const product = addProduct(); const variant = Products.findOne({ ancestors: [product._id] }); const childVariants = Products.find({ ancestors: [ product._id, variant._id ] }).fetch(); const selectedOption = Random.choice(childVariants); const defaults = { _id: Random.id(), productId: product._id, shopId: options.shopId || getShop()._id, quantity: _.random(1, selectedOption.inventoryQuantity), product, variants: selectedOption, title: product.title }; return _.defaults(options, defaults); }
export default function () { const shopId = getShopId(); /** * @name order * @summary Create an Order Factory * @example order = Factory.create("order") * @property {String} additionalField OrderItems - `faker.lorem.sentence()` * @property {String} status OrderItems - `faker.lorem.sentence(3)` * @property {Array} history OrderItems History - `[]` * @property {Array} documents OrderItems Document - `[]` * @property {String} cartId Order - `Random.id()` * @property {Array} notes Order - `[]` * @property {String} shopId Cart - `shopId` * @property {String} shopId.userId Cart - `userId` * @property {String} shopId.sessionId Cart - `"Session"` * @property {String} shopId.email Cart - `faker.internet.email()` * @property {String} shopId.workflow Cart - Object * @property {String} shopId.workflow.status Cart - `"new"` * @property {String} shopId.workflow Cart - `"coreOrderWorkflow/created"` * @property {Array} shopId.items Array of products * @property {String} shopId.items._id Cart - Product - cart ID * @property {String} shopId.items.title Cart - Product - `"itemOne"` * @property {String} shopId.items.shopId Cart - Product - store ID * @property {String} shopId.items.productId Cart - Product - product ID * @property {Number} shopId.items.quantity Cart - Product - `1` * @property {Object} shopId.items.variants Cart - Product - variants * @property {Object} shopId.items.workflow Cart - Product - Object * @property {String} shopId.items.workflow.status Cart - Product - `"new"` * @property {Boolean} requiresShipping - `true` * @property {Array} shipping - Shipping - `[{}]` * @property {Object} items - Shipping - `Object` * @property {String} item._id - Shipping - `itemIdOne` * @property {String} item.productId - Shipping - `Random.id()` * @property {String} item.variantId - Shipping - `Random.id()` * @property {Boolean} item.packed - Shipping - `false` * @property {Array} billing - Billing - `[]` * @property {String} billing._id - Billing - `Random.id()` * @property {Object} billing.address - Billing - Address object * @property {Object} billing.paymentMethod - Billing - Payment Method * @property {String} billing.paymentMethod.method - `"credit"` * @property {String} billing.paymentMethod.processor - `"Example"` * @property {String} billing.paymentMethod.storedCard - `"Mastercard 2346"` * @property {String} billing.paymentMethod.paymentPackageId - `getPkgData("example-paymentmethod")._id` * @property {String} paymentSettingsKey - `"example-paymentmethod"` * @property {String} mode - `"authorize"` * @property {String} status - `"created"` * @property {Number} amount - `12.4` * @property {Object} invoice - Object * @property {Number} invoice.total - `12.45` * @property {Number} invoice.subtotal - `12.45` * @property {Number} invoice.discounts - `0` * @property {Number} invoice.taxes - `0.12` * @property {Number} invoice.shipping - `4.0` * @property {String} state - `"new"` * @property {Date} createdAt - `new Date()` * @property {Date} updatedAt - `new Date()` */ Factory.define("order", Orders, { // Schemas.OrderItems additionalField: faker.lorem.sentence(), status: faker.lorem.sentence(3), history: [], documents: [], // Schemas.Order cartId: Random.id(), notes: [], // Schemas.Cart shopId, userId: getUserId(), sessionId: "Session", email: faker.internet.email(), workflow: { status: "new", workflow: [ "coreOrderWorkflow/created" ] }, items() { const product = addProduct({ shopId }); const variant = Products.findOne({ ancestors: [product._id] }); const childVariants = Products.find({ ancestors: [ product._id, variant._id ] }).fetch(); const selectedOption = Random.choice(childVariants); const product2 = addProduct({ shopId }); const variant2 = Products.findOne({ ancestors: [product2._id] }); const childVariants2 = Products.find({ ancestors: [ product2._id, variant2._id ] }).fetch(); const selectedOption2 = Random.choice(childVariants2); return [{ _id: itemIdOne, title: "firstItem", shopId: product.shopId, productId: product._id, quantity: 1, product, variants: selectedOption, workflow: { status: "new" } }, { _id: itemIdTwo, title: "secondItem", shopId: product2.shopId, productId: product2._id, quantity: 1, product: product2, variants: selectedOption2, workflow: { status: "new" } }]; }, requiresShipping: true, shipping: [{ shopId, address: getAddress({ isShippingDefault: true }), items: [ { _id: itemIdOne, productId: Random.id(), quantity: 1, shopId, variantId: Random.id(), packed: false }, { _id: itemIdTwo, productId: Random.id(), quantity: 1, shopId, variantId: Random.id(), packed: false } ] }], // Shipping Schema billing: [{ _id: Random.id(), shopId, address: getAddress({ isBillingDefault: true }), paymentMethod: paymentMethod({ method: "credit", processor: "Example", storedCard: "Mastercard 2346", paymentPackageId: getPkgData("example-paymentmethod") ? getPkgData("example-paymentmethod")._id : "uiwneiwknekwewe", paymentSettingsKey: "example-paymentmethod", mode: "authorize", status: "created", amount: 12.45 }), invoice: { total: 12.45, subtotal: 12.45, discounts: 0, taxes: 0.12, shipping: 4.00 } }], state: "new", createdAt: new Date(), updatedAt: new Date() }); /** * @name authorizedApprovedPaypalOrder * @summary Defines order factory which generates an authorized, approved, paypal order. * @memberof Fixtures * @property {Array} billing - Array of Billing objects * @property {String} billing._id * @property {String} billing.shopId * @property {Object} billing.address - Address object * @property {Object} billing.paymentMethod * @property {String} billing.paymentMethod.processor "Paypal" * @property {String} billing.paymentMethod.mode "authorize" * @property {String} billing.paymentMethod.status "approved */ Factory.define( "authorizedApprovedPaypalOrder", Orders, Factory.extend("order", { billing: [{ _id: Random.id(), shopId: getShopId(), address: getAddress({ isBillingDefault: true }), paymentMethod: paymentMethod({ processor: "Paypal", mode: "authorize", status: "approved" }) }] }) ); }