Have your say in Community Polls: What was/is your greatest motivation to start your own business?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: Retreive Company object custom metafield using graphql

Solved

Retreive Company object custom metafield using graphql

Khasim1
Shopify Partner
30 0 0

Hi

 

I am trying to retreive Company object custom metafield using graphql on custom apps(cart and checkout validation based) for implementing credit limit feature in the B2B store.

I updated Input to Company in the schema.graphl file Below I added all the files

Khasim1_0-1719566009793.png

Khasim1_2-1719566042936.png

Khasim1_3-1719566063711.png

I get this error when I try to deploy the app:

Command failed with exit code 1: npm exec -- graphql-code-generator --config package.json
[FAILED] GraphQL Document Validation failed with 1 errors;
[FAILED] Error 0: Cannot query field "company" on type "Input".
[FAILED] at C:/Users/xyz/shopify-functions/lucrative-consumer-app/extensions/cart-checkout-validatio
n/src/run.graphql:14:3

 

Kindly let me know how this can be resolved.

 

Thanks

Khasim

Accepted Solution (1)

Eric-HAN
Shopify Partner
247 29 26

This is an accepted solution.

Hi there

The company inside in the buyerIdentity -purchasingCompany-company

so you should rewrite your input to as below.

{
  cart: {
    buyerIdentity: {
      customer{
        numberOfOrders
    }
      purchasingCompany{
         company{
             metafield{
                key(xxx)
                namespace
             }
         }
    }
  }
  cost{

  }
}

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee

View solution in original post

Replies 7 (7)

Eric-HAN
Shopify Partner
247 29 26

This is an accepted solution.

Hi there

The company inside in the buyerIdentity -purchasingCompany-company

so you should rewrite your input to as below.

{
  cart: {
    buyerIdentity: {
      customer{
        numberOfOrders
    }
      purchasingCompany{
         company{
             metafield{
                key(xxx)
                namespace
             }
         }
    }
  }
  cost{

  }
}

 

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Khasim1
Shopify Partner
30 0 0

FYI I ran this query to get the metafield value of Company object

query RunInput {
  cart {
    buyerIdentity {
      purchasingCompany {
        company {
          testValue: metafield(namespace: "b2b", key: "credit_limit_remaining") {value}
        }
      }
    }
    cost {
      subtotalAmount {
        amount
      }
    }

  }
}
Khasim1
Shopify Partner
30 0 0

Hi @Eric-HAN 

 

Can you let me know if the validation can be done on checkout page instead of cart page(https://shopify.dev/docs/api/functions/reference/cart-checkout-validation/graphql) . At present I am blocking the customer on the cart page if their credit limit is less than order total, I want them to proceed to checkout but block them only if they select net payment option in the checkout. And allow them to place order if they select credit card payment option.

 

Thanks

Khasim

Eric-HAN
Shopify Partner
247 29 26

H i,there

   i  suggest you use Payment Customization API (https://shopify.dev/docs/api/functions/reference/payment-customization)  to do this feature . when your customer  credit limit is less than order total, you could  limit their payment options or hide some of them .  otherwise  show the available options.

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Khasim1
Shopify Partner
30 0 0

Hi @Eric-HAN 

 

Is it possible to accept split payments, such as deducting from the available credit limit and charging the remaining amount from a credit card?

 

 

Eric-HAN
Shopify Partner
247 29 26

sorry   

The current stage might not be supported.
If you discover appropriate solutions, please share them to me . Thanks
- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
Khasim1
Shopify Partner
30 0 0

Can you please help on how we can target "choose payment later" option using the payment customization, in the hide function I tried to add using these "Choose payment later", "Net-7", Net-15" but still payment method shows on the checkout. I wanted to hide choose payment method later based on some order total and show only credit card option