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

Enable order page in the core #30

Merged
merged 17 commits into from
May 22, 2024
58 changes: 58 additions & 0 deletions src/data/demo/orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import OrderData from '@data/faker/order';

import dataCustomers from '@data/demo/customers';
import dataOrderStatuses from '@data/demo/orderStatuses';
import dataPaymentMethods from '@data/demo/paymentMethods';

export default {
order_1: new OrderData({
id: 1,
reference: 'XKBKNABJK',
newClient: true,
delivery: 'United States',
customer: dataCustomers.johnDoe,
totalPaid: 61.80,
paymentMethod: dataPaymentMethods.checkPayment,
status: dataOrderStatuses.canceled,
}),
order_2: new OrderData({
id: 2,
reference: 'OHSATSERP',
newClient: false,
delivery: 'United States',
customer: dataCustomers.johnDoe,
totalPaid: 69.90,
paymentMethod: dataPaymentMethods.checkPayment,
status: dataOrderStatuses.awaitingCheckPayment,
}),
order_3: new OrderData({
id: 3,
reference: 'UOYEVOLI',
newClient: false,
delivery: 'United States',
customer: dataCustomers.johnDoe,
totalPaid: 14.90,
paymentMethod: dataPaymentMethods.checkPayment,
status: dataOrderStatuses.paymentError,
}),
order_4: new OrderData({
id: 4,
reference: 'FFATNOMMJ',
newClient: false,
delivery: 'United States',
customer: dataCustomers.johnDoe,
totalPaid: 14.90,
paymentMethod: dataPaymentMethods.checkPayment,
status: dataOrderStatuses.awaitingCheckPayment,
}),
order_5: new OrderData({
id: 5,
reference: 'KHWLILZLL',
newClient: false,
delivery: 'United States',
customer: dataCustomers.johnDoe,
totalPaid: 20.90,
paymentMethod: dataPaymentMethods.wirePayment,
status: dataOrderStatuses.awaitingCheckPayment,
}),
};
103 changes: 103 additions & 0 deletions src/data/faker/order.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import FakerCustomer from '@data/faker/customer';
import FakerPaymentMethod from '@data/faker/paymentMethod';
import FakerOrderStatus from '@data/faker/orderStatus';
import FakerAddress from '@data/faker/address';
import dataCustomers from '@data/demo/customers';
import dataPaymentMethods from '@data/demo/paymentMethods';
import dataOrderStatuses from '@data/demo/orderStatuses';

import type {OrderCreator, OrderDeliveryOption, OrderProduct} from '@data/types/order';

import {faker} from '@faker-js/faker';

/**
* Create new order to use on creation form order page on BO
* @class
*/
export default class OrderData {
public readonly id: number;

public readonly reference: string;

public readonly newClient: boolean;

public readonly delivery: string;

public readonly customer: FakerCustomer;

public readonly totalPaid: number;

public readonly paymentMethod: FakerPaymentMethod;

public readonly status: FakerOrderStatus;

public readonly deliveryAddress: FakerAddress;

public readonly invoiceAddress: FakerAddress;

public readonly products: OrderProduct[];

public readonly discountGiftValue: number;

public readonly discountPercentValue: number;

public readonly totalPrice: number;

public readonly deliveryOption: OrderDeliveryOption;

/**
* Constructor for class Order
* @param orderToCreate {OrderCreator} Could be used to force the value of some members
*/
constructor(orderToCreate: OrderCreator = {}) {
/** @type {number} */
this.id = orderToCreate.id || 0;
/** @type {string} */
this.reference = orderToCreate.reference || faker.string.alpha({
casing: 'upper',
length: 9,
});

/** @type {boolean} */
this.newClient = orderToCreate.newClient === undefined ? true : orderToCreate.newClient;

/** @type {string} */
this.delivery = orderToCreate.delivery || 'France';

/** @type {FakerCustomer} */
this.customer = orderToCreate.customer || dataCustomers.johnDoe;

/** @type {number} */
this.totalPaid = orderToCreate.totalPaid || 0;

/** @type {FakerPaymentMethod} */
this.paymentMethod = orderToCreate.paymentMethod || dataPaymentMethods.checkPayment;

/** @type {FakerOrderStatus|null} */
this.status = orderToCreate.status || dataOrderStatuses.paymentAccepted;

/** @type {FakerCustomer} */
this.deliveryAddress = orderToCreate.deliveryAddress || new FakerAddress();

/** @type {FakerCustomer} */
this.invoiceAddress = orderToCreate.invoiceAddress || new FakerAddress();

/** @type {OrderProduct[]} */
this.products = orderToCreate.products || [];

/** @type {number} */
this.discountGiftValue = orderToCreate.discountGiftValue || 0;

/** @type {number} */
this.discountPercentValue = orderToCreate.discountPercentValue || 0;

/** @type {number} */
this.totalPrice = orderToCreate.totalPrice || 0;

/** @type {OrderDeliveryOption} */
this.deliveryOption = orderToCreate.deliveryOption || {
name: '',
freeShipping: false,
};
}
}
Loading
Loading