use develop line-item service

This commit is contained in:
Vilfred Sikker committed 2021-08-27 11:19:04 +02:00
1 parent af59095d85
commit ab5704208b
1 file changed
+10 -15
+10 -15
View File
@@ -90,16 +90,11 @@ class LineItemService extends BaseService {
} }
async generate(variantId, regionId, quantity, config = {}) { async generate(variantId, regionId, quantity, config = {}) {
return this.atomicPhase_(async (manager) => { const variant = await this.productVariantService_.retrieve(variantId, {
const variant = await this.productVariantService_
.withTransaction(manager)
.retrieve(variantId, {
relations: ["product"], relations: ["product"],
}) })
const region = await this.regionService_ const region = await this.regionService_.retrieve(regionId)
.withTransaction(manager)
.retrieve(regionId)
let price let price
let shouldMerge = true let shouldMerge = true
@@ -114,9 +109,10 @@ class LineItemService extends BaseService {
price = config.unit_price price = config.unit_price
} }
} else { } else {
price = await this.productVariantService_ price = await this.productVariantService_.getRegionPrice(
.withTransaction(manager) variant.id,
.getRegionPrice(variant.id, region.id) region.id
)
} }
const toCreate = { const toCreate = {
@@ -126,14 +122,13 @@ class LineItemService extends BaseService {
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.discountable, allow_discounts: !variant.product.is_giftcard,
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
})
} }
/** /**
@@ -142,7 +137,7 @@ class LineItemService extends BaseService {
* @return {LineItem} the created line item * @return {LineItem} the created line item
*/ */
async create(lineItem) { async create(lineItem) {
return this.atomicPhase_(async (manager) => { return this.atomicPhase_(async manager => {
const lineItemRepository = manager.getCustomRepository( const lineItemRepository = manager.getCustomRepository(
this.lineItemRepository_ this.lineItemRepository_
) )
@@ -160,7 +155,7 @@ class LineItemService extends BaseService {
* @return {LineItem} the update line item * @return {LineItem} the update line item
*/ */
async update(id, update) { async update(id, update) {
return this.atomicPhase_(async (manager) => { return this.atomicPhase_(async manager => {
const lineItemRepository = manager.getCustomRepository( const lineItemRepository = manager.getCustomRepository(
this.lineItemRepository_ this.lineItemRepository_
) )
@@ -188,7 +183,7 @@ class LineItemService extends BaseService {
* @return {Promise} the result of the delete operation * @return {Promise} the result of the delete operation
*/ */
async delete(id) { async delete(id) {
return this.atomicPhase_(async (manager) => { return this.atomicPhase_(async manager => {
const lineItemRepository = manager.getCustomRepository( const lineItemRepository = manager.getCustomRepository(
this.lineItemRepository_ this.lineItemRepository_
) )