2024.2 [b2b] Company Export to NetSuite
The Company Export process is a B2B specific process and requires the Magento Company module to work. As with all Export processes, it has two parts. The first part works in two different ways.
- if company is synced with NetSuite - \RocketWeb\NetSuiteCompany\Observer\NetsuiteCustomerSendBeforeObserver::execute() which is triggered for our own event netsuite_customer_send_before. It checks if Customer belongs to a Company and if it does, it runs \RocketWeb\NetSuiteCompany\Observer\NetsuiteCustomerSendBeforeObserver::saveCompany() to trigger the second part directly.
- if company is NOT synced with NetSuite then \RocketWeb\NetSuiteCompany\Observer\CompanySaveObserver::execute() checks if the following conditions are met:
- Module is Enabled
- Feature is Enable
- Is not marked to be skipped
If all are met, an Export Queue Message is created with Company ID attached to it & sent into the Queue. The Observer is linked into company_save_after event which means it's triggered in all areas (frontend/adminhtml).
Transform Magento Company into NetSuite Format
Before the transformation happens, the \RocketWeb\NetSuiteCompany\Model\Process\Export\CompanySave::process() checks that Company exists in Magento. The actual mapping happens in \RocketWeb\NetSuiteCompany\Model\Mapper\Company::getNetsuiteFormat(). The Mapping is hardcoded which means that any modifications require an Observer or Plugin usage. The Event trigger is netsuite_company_send_before and contains both $netsuiteCompany format and $magentoCompany that was pulled from the database. The recommended approach creating customizations is a use of Plugin on \RocketWeb\NetSuiteCompany\Model\Mapper\Company::getNetsuiteFormat() when modifications of structure or main data is needed and use of Plugin on \RocketWeb\NetSuiteCompany\Model\Mapper\Company::getAddressBookInNetsuiteFormat() when Address-related modifications are needed.
Sending request to NetSuite
If the Company is not found in NetSuite, we send an \NetSuite\Classes\AddRequest to NetSuite. If it exists, we send \NetSuite\Classes\UpdateRequest request. In some cases, the Company is not found by our first check thru the usage of externalIdString (so AddRequest is sent) but NetSuite reports DUP_ENTITY. In that case, we retry the request by using UpdateRequest. The response contains the Company internal ID which we save into netsuite_internal_id custom attribute.