|
1
|
{"slug":"/references/promotion/computeActions","title":"computeActions - Promotion Module Reference","frontmatter":{"displayed_sidebar":"promotionReference","slug":"/references/promotion/computeActions","sidebar_label":"computeActions"},"toc":[{"title":"Example","id":"example","level":2},{"title":"Parameters","id":"computeactions-parameters","level":2},{"title":"Returns","id":"computeactions-returns","level":2}],"blocks":[{"kind":"markdown","html":"This documentation provides a reference to the `computeActions` method. This belongs to the Promotion Module."},{"kind":"note","variant":"note","html":"You should only use this methods when implementing complex customizations. For common cases, check out [available workflows instead](/medusa-workflows-reference)."},{"kind":"markdown","html":"This method provides the actions to perform on a cart based on the specified promotions\nand context."},{"kind":"heading","level":2,"text":"Example","id":"example"},{"kind":"markdown","html":"```ts\nconst actions = await promotionModuleService.computeActions(\n [\"50OFF\"],\n {\n items: [\n {\n id: \"cali_123\",\n quantity: 2,\n subtotal: 1000,\n },\n ],\n shipping_methods: [\n {\n id: \"casm_123\",\n subtotal: 0,\n adjustments: [\n {\n id: \"adj_123\",\n code: \"FREESHIPPING\",\n },\n ],\n },\n ],\n }\n)\n```"},{"kind":"heading","level":2,"text":"Parameters","id":"computeactions-parameters"},{"kind":"typeList","sectionTitle":"computeActions","types":[{"name":"promotionCodesToApply","type":"`string`[]","description":"The promotion codes to be applied on the cart.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"applicationContext","type":"[ComputeActionContext](/references/promotion/interfaces/promotion.ComputeActionContext)","description":"The items and shipping methods of the cart.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"currency_code","type":"`string`","description":"The cart's currency","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"customer","type":"`object`","description":"The customer associated with the cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"groups","type":"`object`[]","description":"The customer groups the customer belongs to.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"region","type":"`object`","description":"The region associated with the cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_address","type":"`object`","description":"The shipping address associated with the cart.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"country_code","type":"`string`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]}]},{"name":"sales_channel_id","type":"`string`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"email","type":"`string`","description":"The cart's email","optional":true,"defaultValue":"","expandable":false,"children":[],"since":"2.11.0"},{"name":"items","type":"[ComputeActionItemLine](/references/promotion/interfaces/promotion.ComputeActionItemLine)[]","description":"The cart's line items.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the item line.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"quantity","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The quantity of the line item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtotal","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The subtotal of the line item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"original_total","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The total of the line item.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"is_discountable","type":"`boolean`","description":"Whether the line item is discountable.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"adjustments","type":"[ComputeActionAdjustmentLine](/references/promotion/interfaces/promotion.ComputeActionAdjustmentLine)[]","description":"The adjustments applied before on the line item.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"product","type":"`object`","description":"The product ID of the line item. Our default promotion rules rely on the product ID to apply the promotion.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"shipping_methods","type":"[ComputeActionShippingLine](/references/promotion/interfaces/promotion.ComputeActionShippingLine)[]","description":"The cart's shipping methods.","optional":true,"defaultValue":"","expandable":false,"children":[{"name":"id","type":"`string`","description":"The ID of the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"subtotal","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The subtotal of the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"original_total","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The total of the shipping method.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"adjustments","type":"[ComputeActionAdjustmentLine](/references/promotion/interfaces/promotion.ComputeActionAdjustmentLine)[]","description":"The adjustments applied before on the shipping method.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_option","type":"`object`","description":"The shipping option type associated with the shipping method.","optional":true,"defaultValue":"","expandable":false,"children":[]}]}]},{"name":"options","type":"`Record<string, any>`","description":"Any relevant options that may change how the actions are computed.","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"kind":"heading","level":2,"text":"Returns","id":"computeactions-returns"},{"kind":"typeList","sectionTitle":"computeActions","types":[{"name":"Promise","type":"Promise<[ComputeActions](/references/promotion/types/promotion.ComputeActions)[]>","optional":false,"defaultValue":"","description":"The list of computed actions to be applied on the cart.","expandable":false,"children":[{"name":"ComputeActions[]","type":"[ComputeActions](/references/promotion/types/promotion.ComputeActions)[]","optional":false,"defaultValue":"","description":"","expandable":false,"children":[{"name":"action","type":"`\"addItemAdjustment\"`","description":"The type of action.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"item_id","type":"`string`","description":"The associated item's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"amount","type":"[BigNumberInput](/references/promotion/types/promotion.BigNumberInput)","description":"The amount to remove off the item's total.","optional":false,"defaultValue":"","expandable":false,"children":[{"name":"value","type":"`string` \\| `number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"numeric","type":"`number`","description":"","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"raw","type":"[BigNumberRawValue](/references/promotion/types/promotion.BigNumberRawValue)","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"bigNumber","type":"`BigNumber`","description":"","optional":true,"defaultValue":"","expandable":false,"children":[]}]},{"name":"is_tax_inclusive","type":"`boolean`","description":"Whether the promotion amount includes tax.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"code","type":"`string`","description":"The promotion's code.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"description","type":"`string`","description":"The promotion's description.","optional":true,"defaultValue":"","expandable":false,"children":[]},{"name":"adjustment_id","type":"`string`","description":"The associated adjustment's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]},{"name":"shipping_method_id","type":"`string`","description":"The associated shipping method's ID.","optional":false,"defaultValue":"","expandable":false,"children":[]}]}]}]}]} |