grap line item from develop
This commit is contained in:
1 parent
f34a099a77
commit
5261999d12
1 file changed
+37
-32
@@ -90,45 +90,50 @@ class LineItemService extends BaseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async generate(variantId, regionId, quantity, config = {}) {
|
async generate(variantId, regionId, quantity, config = {}) {
|
||||||
const variant = await this.productVariantService_.retrieve(variantId, {
|
return this.atomicPhase_(async manager => {
|
||||||
relations: ["product"],
|
const variant = await this.productVariantService_
|
||||||
})
|
.withTransaction(manager)
|
||||||
|
.retrieve(variantId, {
|
||||||
|
relations: ["product"],
|
||||||
|
})
|
||||||
|
|
||||||
const region = await this.regionService_.retrieve(regionId)
|
const region = await this.regionService_
|
||||||
|
.withTransaction(manager)
|
||||||
|
.retrieve(regionId)
|
||||||
|
|
||||||
let price
|
let price
|
||||||
let shouldMerge = true
|
let shouldMerge = true
|
||||||
|
|
||||||
if (config.unit_price && typeof config.unit_price !== `undefined`) {
|
if (config.unit_price && typeof config.unit_price !== `undefined`) {
|
||||||
// if custom unit_price, we ensure positive values
|
// if custom unit_price, we ensure positive values
|
||||||
// and we choose to not merge the items
|
// and we choose to not merge the items
|
||||||
shouldMerge = false
|
shouldMerge = false
|
||||||
if (config.unit_price < 0) {
|
if (config.unit_price < 0) {
|
||||||
price = 0
|
price = 0
|
||||||
|
} else {
|
||||||
|
price = config.unit_price
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
price = config.unit_price
|
price = await this.productVariantService_
|
||||||
|
.withTransaction(manager)
|
||||||
|
.getRegionPrice(variant.id, region.id)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
price = await this.productVariantService_.getRegionPrice(
|
|
||||||
variant.id,
|
|
||||||
region.id
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
const toCreate = {
|
const toCreate = {
|
||||||
unit_price: price,
|
unit_price: price,
|
||||||
title: variant.product.title,
|
title: variant.product.title,
|
||||||
description: variant.title,
|
description: variant.title,
|
||||||
thumbnail: variant.product.thumbnail,
|
thumbnail: variant.product.thumbnail,
|
||||||
variant_id: variant.id,
|
variant_id: variant.id,
|
||||||
quantity: quantity || 1,
|
quantity: quantity || 1,
|
||||||
allow_discounts: !variant.product.is_giftcard,
|
allow_discounts: variant.product.discountable,
|
||||||
is_giftcard: variant.product.is_giftcard,
|
is_giftcard: variant.product.is_giftcard,
|
||||||
metadata: config?.metadata || {},
|
metadata: config?.metadata || {},
|
||||||
should_merge: shouldMerge,
|
should_merge: shouldMerge,
|
||||||
}
|
}
|
||||||
|
|
||||||
return toCreate
|
return toCreate
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user