fix(medusa): Add relations to cart retrieval to correctly calculate tax context (#1823)
This commit is contained in:
@@ -191,6 +191,7 @@ class CartService extends TransactionBaseService<CartService> {
|
|||||||
// relationSet.add("discounts.parent_discount.rule")
|
// relationSet.add("discounts.parent_discount.rule")
|
||||||
// relationSet.add("discounts.parent_discount.regions")
|
// relationSet.add("discounts.parent_discount.regions")
|
||||||
relationSet.add("shipping_methods")
|
relationSet.add("shipping_methods")
|
||||||
|
relationSet.add("shipping_address")
|
||||||
relationSet.add("region")
|
relationSet.add("region")
|
||||||
relationSet.add("region.tax_rates")
|
relationSet.add("region.tax_rates")
|
||||||
relations = Array.from(relationSet.values())
|
relations = Array.from(relationSet.values())
|
||||||
@@ -287,8 +288,11 @@ class CartService extends TransactionBaseService<CartService> {
|
|||||||
)
|
)
|
||||||
const validatedId = validateId(cartId)
|
const validatedId = validateId(cartId)
|
||||||
|
|
||||||
const { select, relations, totalsToSelect } =
|
const {
|
||||||
this.transformQueryForTotals_(options)
|
select,
|
||||||
|
relations,
|
||||||
|
totalsToSelect,
|
||||||
|
} = this.transformQueryForTotals_(options)
|
||||||
|
|
||||||
const query = buildQuery(
|
const query = buildQuery(
|
||||||
{ id: validatedId },
|
{ id: validatedId },
|
||||||
@@ -894,7 +898,9 @@ class CartService extends TransactionBaseService<CartService> {
|
|||||||
protected async createOrFetchUserFromEmail_(
|
protected async createOrFetchUserFromEmail_(
|
||||||
email: string
|
email: string
|
||||||
): Promise<Customer> {
|
): Promise<Customer> {
|
||||||
const schema = Validator.string().email().required()
|
const schema = Validator.string()
|
||||||
|
.email()
|
||||||
|
.required()
|
||||||
const { value, error } = schema.validate(email.toLowerCase())
|
const { value, error } = schema.validate(email.toLowerCase())
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new MedusaError(
|
throw new MedusaError(
|
||||||
@@ -1553,10 +1559,9 @@ class CartService extends TransactionBaseService<CartService> {
|
|||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
const cartCustomShippingOptions =
|
const cartCustomShippingOptions = await this.customShippingOptionService_
|
||||||
await this.customShippingOptionService_
|
.withTransaction(transactionManager)
|
||||||
.withTransaction(transactionManager)
|
.list({ cart_id: cart.id })
|
||||||
.list({ cart_id: cart.id })
|
|
||||||
|
|
||||||
const customShippingOption = this.findCustomShippingOption(
|
const customShippingOption = this.findCustomShippingOption(
|
||||||
cartCustomShippingOptions,
|
cartCustomShippingOptions,
|
||||||
@@ -1934,13 +1939,16 @@ class CartService extends TransactionBaseService<CartService> {
|
|||||||
async (transactionManager: EntityManager) => {
|
async (transactionManager: EntityManager) => {
|
||||||
const cart = await this.retrieve(id, {
|
const cart = await this.retrieve(id, {
|
||||||
relations: [
|
relations: [
|
||||||
"items",
|
"customer",
|
||||||
"gift_cards",
|
|
||||||
"discounts",
|
"discounts",
|
||||||
"discounts.rule",
|
"discounts.rule",
|
||||||
"shipping_methods",
|
"gift_cards",
|
||||||
|
"items",
|
||||||
|
"items.adjustments",
|
||||||
"region",
|
"region",
|
||||||
"region.tax_rates",
|
"region.tax_rates",
|
||||||
|
"shipping_address",
|
||||||
|
"shipping_methods",
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user