BCApps icon indicating copy to clipboard operation
BCApps copied to clipboard

[Bug]: Shopify Connector: customer created from a B2B company gets no payment terms (Update Customer used without SetShop)

Open calpeyser opened this issue 1 month ago • 2 comments

Describe the issue

Consider a B2B shop. In Shopify, a company location has the payment terms "Net 30". In BC, "Sync Payment Terms" has run, and the Shopify payment terms row for "Net 30" is mapped to the BC payment terms code 30 DAYS. "Auto Create Unknown Companies" is on.

Now the company is imported, and the connector creates a new customer for it. The new customer has no payment terms. If the customer template had a payment terms code, that code is cleared too. No error is shown.

This is because CreateCustomerFromCompany looks up the BC code through a local Shpfy Update Customer codeunit that it never gives a shop:

https://github.com/microsoft/BCApps/blob/a1db0b7737a5919564e3f7cbec6fc5a470df5f4c/src/Apps/W1/Shopify/App/src/Customers/Codeunits/ShpfyCreateCustomer.Codeunit.al#L171-L172

if CompanyLocation."Shpfy Payment Terms Id" <> 0 then
    Customer.Validate("Payment Terms Code", UpdateCustomer.GetPaymentTermsCodeFromShopifyPaymentTermsId(CompanyLocation."Shpfy Payment Terms Id"));

GetPaymentTermsCodeFromShopifyPaymentTermsId filters on the codeunit's own Shop.Code, which is blank here:

https://github.com/microsoft/BCApps/blob/a1db0b7737a5919564e3f7cbec6fc5a470df5f4c/src/Apps/W1/Shopify/App/src/Customers/Codeunits/ShpfyUpdateCustomer.Codeunit.al#L205-L213

The primary key of Shpfy Payment Terms is ("Shop Code", Id), and the payment terms sync always fills "Shop Code" (ShpfyPaymentTermsAPI.Codeunit.al line 62). So the lookup never finds the row, returns '', and Validate("Payment Terms Code", '') clears the field.

The update path does not have this problem, because Shpfy Company Import calls UpdateCustomer.SetShop(Shop) before UpdateCustomerFromCompany (ShpfyCompanyImport.Codeunit.al line 34). Only new customers are affected.

The existing test UnitTestCreateCustomerFromCompanyWithPaymentTerms does not catch this, because its helper CreateShopifyPaymentTerms inserts the payment terms row with a blank "Shop Code", which matches the blank shop.

Expected behavior

A customer created from a Shopify company gets the BC payment terms code mapped to the company location's Shopify payment terms, the same as when an existing customer is updated from the company.

Steps to reproduce

  1. On a Shopify shop with B2B, set "Auto Create Unknown Companies" on.
  2. Run "Sync Payment Terms". On the Shopify Payment Terms page, map "Net 30" to a BC payment terms code, for example 30 DAYS.
  3. In Shopify, create a company whose location has payment terms "Net 30".
  4. In BC, run "Sync Companies".
  5. Open the new customer. "Payment Terms Code" is empty. Expected: 30 DAYS.

Additional context

Proposed fix, one line in CreateCustomerFromCompany, before the lookup:

UpdateCustomer.SetShop(Shop);

In ShpfyCompanyImportTest.Codeunit.al, the helper CreateShopifyPaymentTerms should set "Shop Code" to the test shop's code, as the payment terms sync does. Then UnitTestCreateCustomerFromCompanyWithPaymentTerms covers the real case: it fails on main and passes with the fix. UnitTestUpdateCustomerFromCompanyWithPaymentTerms then needs UpdateCustomer.SetShop(Shop) before it runs, the same as Shpfy Company Import does.

I will provide a fix for a bug

  • [x] I will provide a fix for a bug

calpeyser avatar Nov 02 '26 16:11 calpeyser

:robot: AI triage completed. Product group, please validate the triage report (Microsoft internal access only, use Ctrl+Click to open in new tab).


Was this triage helpful? React with :thumbsup: or :thumbsdown: on this comment to provide feedback.

github-actions[bot] avatar Nov 02 '26 16:11 github-actions[bot]

@AndreiPanko / @onbuyuka, could you triage, please?

JesperSchulz avatar Nov 04 '26 14:11 JesperSchulz