feat: Add DiscountConditions (#1230)
* feat: Add DiscountCondition entity + Join table per relation (#1146) * feat: Convert DiscountService to TypeScript (#1149) * feat: Add DiscountRepository + bulk insert and remove (#1156) * feat: Add `conditions` to payload in `POST /discounts` and `POST /discounts/:id` (#1170) * feat: Add DiscountRuleCondition entity * fix relation * fix join key * Add discount rule condition repo * add join table per relation * Convert DiscountService to TypeScript * feat: Add DiscountConditionRepository * Add migration + remove use of valid_for * revert changes to files, not done yet * init work on create discount endpoint * Add conditions to create discount endpoint * Add conditions to update discount endpoint * Add unique constraint to discount condition * integration tests passing * fix imports of models * fix tests (excluding totals calculations) * Fix commented code * add unique constraint on discount condition * Add generic way of generating retrieve configs * Requested changes + ExactlyOne validator * Remove isLocal flag from error handler * Use postgres error constant * remove commented code * feat: Add `isValidForProduct` to check if Discount is valid for a given Product (#1172) * feat: Add `canApplyForCustomer` to check if Discount is valid for customer groups (#1212) * feat: Add `calculateDiscountForLineItem` (#1224) * feat: Adds discount condition test factory (#1228) * Remove use of valid_for * Tests passing * Remove valid_for form relations * Add integration tests for applying discounts to cart
This commit is contained in:
1 parent
b7f699654b
commit
a610805917
60 files changed
+4805
-2021
No files matched your search
@@ -29,20 +29,14 @@ class OrderSubscriber {
|
||||
this.eventBus_.subscribe("order.placed", this.updateDraftOrder)
|
||||
}
|
||||
|
||||
handleOrderPlaced = async data => {
|
||||
handleOrderPlaced = async (data) => {
|
||||
const order = await this.orderService_.retrieve(data.id, {
|
||||
select: ["subtotal"],
|
||||
relations: [
|
||||
"discounts",
|
||||
"discounts.rule",
|
||||
"discounts.rule.valid_for",
|
||||
"items",
|
||||
"gift_cards",
|
||||
],
|
||||
relations: ["discounts", "discounts.rule", "items", "gift_cards"],
|
||||
})
|
||||
|
||||
await Promise.all(
|
||||
order.items.map(async i => {
|
||||
order.items.map(async (i) => {
|
||||
if (i.is_giftcard) {
|
||||
for (let qty = 0; qty < i.quantity; qty++) {
|
||||
await this.giftCardService_.create({
|
||||
@@ -58,7 +52,7 @@ class OrderSubscriber {
|
||||
)
|
||||
|
||||
await Promise.all(
|
||||
order.discounts.map(async d => {
|
||||
order.discounts.map(async (d) => {
|
||||
const usageCount = d?.usage_count || 0
|
||||
return this.discountService_.update(d.id, {
|
||||
usage_count: usageCount + 1,
|
||||
@@ -67,11 +61,11 @@ class OrderSubscriber {
|
||||
)
|
||||
}
|
||||
|
||||
updateDraftOrder = async data => {
|
||||
updateDraftOrder = async (data) => {
|
||||
const order = await this.orderService_.retrieve(data.id)
|
||||
const draftOrder = await this.draftOrderService_
|
||||
.retrieveByCartId(order.cart_id)
|
||||
.catch(_ => null)
|
||||
.catch((_) => null)
|
||||
|
||||
if (draftOrder) {
|
||||
await this.draftOrderService_.registerCartCompletion(
|
||||
|
||||
Reference in new issue
Block a user