grap line item from develop

This commit is contained in:
Vilfred Sikker
2021-08-27 11:22:14 +02:00
parent f34a099a77
commit 5261999d12
+37 -32
View File
@@ -90,45 +90,50 @@ class LineItemService extends BaseService {
}
async generate(variantId, regionId, quantity, config = {}) {
const variant = await this.productVariantService_.retrieve(variantId, {
relations: ["product"],
})
return this.atomicPhase_(async manager => {
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 shouldMerge = true
let price
let shouldMerge = true
if (config.unit_price && typeof config.unit_price !== `undefined`) {
// if custom unit_price, we ensure positive values
// and we choose to not merge the items
shouldMerge = false
if (config.unit_price < 0) {
price = 0
if (config.unit_price && typeof config.unit_price !== `undefined`) {
// if custom unit_price, we ensure positive values
// and we choose to not merge the items
shouldMerge = false
if (config.unit_price < 0) {
price = 0
} else {
price = config.unit_price
}
} 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 = {
unit_price: price,
title: variant.product.title,
description: variant.title,
thumbnail: variant.product.thumbnail,
variant_id: variant.id,
quantity: quantity || 1,
allow_discounts: !variant.product.is_giftcard,
is_giftcard: variant.product.is_giftcard,
metadata: config?.metadata || {},
should_merge: shouldMerge,
}
const toCreate = {
unit_price: price,
title: variant.product.title,
description: variant.title,
thumbnail: variant.product.thumbnail,
variant_id: variant.id,
quantity: quantity || 1,
allow_discounts: variant.product.discountable,
is_giftcard: variant.product.is_giftcard,
metadata: config?.metadata || {},
should_merge: shouldMerge,
}
return toCreate
return toCreate
})
}
/**