- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Add Shopware actions for order management #18874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      3c67ef4
              
                Add Shopware actions for order management
              
              
                luancazarine 01dbb82
              
                Bump Shopware component version to 0.1.0 and add dependency on @piped…
              
              
                luancazarine 71e770e
              
                pnpm update
              
              
                luancazarine cef35d4
              
                Fix currency factor parsing in create-order action and update descrip…
              
              
                luancazarine dd98cb4
              
                Update components/shopware/actions/update-order/update-order.mjs
              
              
                luancazarine fefe757
              
                Update descriptions for item and total rounding in create-order actio…
              
              
                luancazarine File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
        
          
          
            106 changes: 106 additions & 0 deletions
          
          106 
        
  components/shopware/actions/create-order/create-order.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-create-order", | ||
| name: "Create Order", | ||
| description: "Create a new order. [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| billingAddressId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "customerAddressId", | ||
| ], | ||
| label: "Billing Address ID", | ||
| description: "The ID of the billing address to use for the order", | ||
| }, | ||
| currencyId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "currencyId", | ||
| ], | ||
| }, | ||
| salesChannelId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "salesChannelId", | ||
| ], | ||
| }, | ||
| stateId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "stateId", | ||
| () => ({ | ||
| type: "order.state", | ||
| }), | ||
| ], | ||
| }, | ||
| orderDateTime: { | ||
| type: "string", | ||
| label: "Order Date Time", | ||
| description: "The date and time the order was created", | ||
| }, | ||
| priceObject: { | ||
| type: "object", | ||
| label: "Price Object", | ||
| description: "Price object to use for the order. Example: `{ \"netPrice\": 1.00, \"totalPrice\": 1.00, \"positionPrice\": 1.00, \"rawTotal\": 1.00, \"taxStatus\": \"Free\", \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.", | ||
| }, | ||
| shippingCostsObject: { | ||
| type: "object", | ||
| label: "Shipping Costs Object", | ||
| description: "Shipping costs object to use for the order. Example: `{ \"unitPrice\": 1.00, \"totalPrice\": 1.00, \"quantity\": 1, \"calculatedTaxes\": {}, \"taxRules\": {} }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.", | ||
| }, | ||
| currencyObject: { | ||
| type: "object", | ||
| label: "Currency Object", | ||
| description: "Currency object to use for the order. Example: `{ \"factor\": 1.0, \"symbol\": \"€\", \"isoCode\": \"EUR\", \"itemRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true }, \"totalRounding\": { \"decimals\": 2, \"interval\": 1.0, \"roundForNet\": true } }` [See the documentation](https://shopware.stoplight.io/docs/admin-api/52ce9936f6ea4-create-a-new-order-resources) for more information.", | ||
| }, | ||
| currencyFactor: { | ||
| type: "string", | ||
| label: "Currency Factor", | ||
| description: "Rate at which currency is exchanged", | ||
| }, | ||
| itemRounding: { | ||
| type: "object", | ||
| label: "Item Rounding", | ||
| description: "The rounding method to use for the order items. Example: {\"extensions\":[],\"decimals\":2,\"interval\":0.01,\"roundForNet\":true}", | ||
| }, | ||
| totalRounding: { | ||
| type: "object", | ||
| label: "Total Rounding", | ||
| description: "The rounding method to use for the order total. Example: {\"extensions\":[],\"decimals\":2,\"interval\":0.01,\"roundForNet\":true}", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { data } = await this.shopware.createOrder({ | ||
| $, | ||
| params: { | ||
| _response: "json", | ||
| }, | ||
| data: { | ||
| billingAddressId: this.billingAddressId, | ||
| currencyId: this.currencyId, | ||
| salesChannelId: this.salesChannelId, | ||
| stateId: this.stateId, | ||
| orderDateTime: this.orderDateTime, | ||
| price: parseObject(this.priceObject), | ||
| shippingCosts: parseObject(this.shippingCostsObject), | ||
| currencyFactor: this.currencyFactor && parseFloat(this.currencyFactor), | ||
| currency: parseObject(this.currency), | ||
| itemRounding: parseObject(this.itemRounding), | ||
| totalRounding: parseObject(this.totalRounding), | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully created order with ID: ${data.id}`); | ||
| return data; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-get-order", | ||
| name: "Get Order", | ||
| description: "Get an order by ID. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0b7d9d489b841-search-for-the-order-resources)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| orderId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "orderId", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { data } = await this.shopware.getOrder({ | ||
| $, | ||
| orderId: this.orderId, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully retrieved order with ID: ${data.id}`); | ||
| return data; | ||
| }, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-list-orders", | ||
| name: "List Orders", | ||
| description: "List all orders. [See the documentation](https://shopware.stoplight.io/docs/admin-api/f95b395c5ae73-list-with-basic-information-of-order-resources)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "The maximum number of orders to return", | ||
| default: 100, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const orders = this.shopware.paginate({ | ||
| $, | ||
| fn: this.shopware.listOrders, | ||
| maxResults: this.maxResults, | ||
| }); | ||
|  | ||
| const data = []; | ||
| for await (const order of orders) { | ||
| data.push(order); | ||
| } | ||
| $.export("$summary", `Successfully retrieved ${data.length} orders`); | ||
| return data; | ||
| }, | ||
| }; | 
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  components/shopware/actions/list-payment-methods/list-payment-methods.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-list-payment-methods", | ||
| name: "List Payment Methods", | ||
| description: "List all payment methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/0ffc5a34d40e4-list-with-basic-information-of-payment-method-resources)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "The maximum number of payment methods to return", | ||
| default: 100, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = this.shopware.paginate({ | ||
| $, | ||
| fn: this.shopware.listPaymentMethods, | ||
| maxResults: this.maxResults, | ||
| }); | ||
|  | ||
| const data = []; | ||
| for await (const paymentMethod of response) { | ||
| data.push(paymentMethod); | ||
| } | ||
|  | ||
| $.export("$summary", `Successfully retrieved ${data.length} payment methods`); | ||
| return data; | ||
| }, | ||
| }; | 
        
          
          
            39 changes: 39 additions & 0 deletions
          
          39 
        
  components/shopware/actions/list-shipping-methods/list-shipping-methods.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-list-shipping-methods", | ||
| name: "List Shipping Methods", | ||
| description: "List all shipping methods. [See the documentation](https://shopware.stoplight.io/docs/admin-api/7d33c6b3c151d-list-with-basic-information-of-shipping-method-resources)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| maxResults: { | ||
| type: "integer", | ||
| label: "Max Results", | ||
| description: "The maximum number of shipping methods to return", | ||
| default: 100, | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = this.shopware.paginate({ | ||
| $, | ||
| fn: this.shopware.listShippingMethods, | ||
| maxResults: this.maxResults, | ||
| }); | ||
|  | ||
| const data = []; | ||
| for await (const shippingMethod of response) { | ||
| data.push(shippingMethod); | ||
| } | ||
|  | ||
| $.export("$summary", `Successfully retrieved ${data.length} shipping methods`); | ||
| return data; | ||
| }, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import shopware from "../../shopware.app.mjs"; | ||
|  | ||
| export default { | ||
| key: "shopware-update-order", | ||
| name: "Update Order", | ||
| description: "Partially update information about an order resource. [See the documentation](https://shopware.stoplight.io/docs/admin-api/3cc867261ff28-partially-update-information-about-a-order-resource)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| annotations: { | ||
| destructiveHint: false, | ||
| openWorldHint: true, | ||
| readOnlyHint: true, | ||
| }, | ||
| props: { | ||
| shopware, | ||
| orderId: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "orderId", | ||
| ], | ||
| }, | ||
| tagIds: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "tagIds", | ||
| ], | ||
| withLabel: true, | ||
| optional: true, | ||
| }, | ||
| ruleIds: { | ||
| propDefinition: [ | ||
| shopware, | ||
| "ruleIds", | ||
| ], | ||
| optional: true, | ||
| }, | ||
| orderNumber: { | ||
| type: "string", | ||
| label: "Order Number", | ||
| description: "Unique number associated with every order", | ||
| optional: true, | ||
| }, | ||
| affiliateCode: { | ||
| type: "string", | ||
| label: "Affiliate Code", | ||
| description: "An affiliate code is an identification option with which website operators can mark outgoing links", | ||
| optional: true, | ||
| }, | ||
| campaignCode: { | ||
| type: "string", | ||
| label: "Campaign Code", | ||
| description: "A campaign code is the globally unique identifier for a campaign", | ||
| optional: true, | ||
| }, | ||
| customerComment: { | ||
| type: "string", | ||
| label: "Customer Comment", | ||
| description: "Comments given by the customer", | ||
| optional: true, | ||
| }, | ||
| internalComment: { | ||
| type: "string", | ||
| label: "Internal Comment", | ||
| description: "Comments given by the internal user", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { data } = await this.shopware.updateOrder({ | ||
| $, | ||
| orderId: this.orderId, | ||
| params: { | ||
| _response: "json", | ||
| }, | ||
| data: { | ||
| tags: parseObject(this.tagIds)?.map(({ | ||
| value, label, | ||
| }) => ({ | ||
| id: value, | ||
| name: label, | ||
| })), | ||
| ruleIds: parseObject(this.ruleIds), | ||
| orderNumber: this.orderNumber, | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| affiliateCode: this.affiliateCode, | ||
| campaignCode: this.campaignCode, | ||
| customerComment: this.customerComment, | ||
| internalComment: this.internalComment, | ||
| }, | ||
| }); | ||
|  | ||
| $.export("$summary", `Successfully updated order with ID: ${this.orderId}`); | ||
| return data; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export const LIMIT = 100; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| export const parseObject = (obj) => { | ||
| if (!obj) return undefined; | ||
|  | ||
| if (Array.isArray(obj)) { | ||
| return obj.map((item) => { | ||
| if (typeof item === "string") { | ||
| try { | ||
| return JSON.parse(item); | ||
| } catch (e) { | ||
| return item; | ||
| } | ||
| } | ||
| return item; | ||
| }); | ||
| } | ||
| if (typeof obj === "string") { | ||
| try { | ||
| return JSON.parse(obj); | ||
| } catch (e) { | ||
| return obj; | ||
| } | ||
| } | ||
| return obj; | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.