I am troubleshooting an issue in an extension that...
# suitecommerce
k
I am troubleshooting an issue in an extension that NetSuite Professional Services developed. They used the following line of code in the extension that is run after the SSP library LiveOrder.Model get() method is called. The code is: Application.on(‘after:LiveOrder.get’, function afterGet(self, result, noRecalc) {}); Are the SSP library events, like “after:LiveOrder.get” documented in SuiteCommerce Developer website? I searched and I can’t find them.
s
They're not documented, no. But I've talked about them a few times in my blog posts, eg https://developers.suitecommerce.com/til-thursday-netsuite-professional-services-best-practices#title19
Essentially, any backend model's methods can be listened to and have code fire before or after.
But keep in mind that these are synchronous so you can end up blocking your site's operation if you mess up.
k
@Steve Goldberg, thanks for the quick response. Does the return value of LiveOrder.Model get() method get passed to Application.on(‘after:LiveOrder.get’, function a () {}); before the response is sent back to the client? Does the return value of function a() passed back to the client or the original LiveOrder.Model get() return value?
s
Good questions. I haven't poked around in this area for a while but my understanding is that these events do not interfere, cancel or interrupt the methods they listen to directly. In other words, if you want to, say, modify the value of a line before
get()
then you will need to use standard commerce API methods in your callback.
(Thus you're changing the lines before they can be `get()`ed)
This differentiates them to the events in the extensibility API because these are 'cancellable' events in that they return deferred objects that can be used to prevent the listened-to method from continuing
(But even cancellable events do not 'pass on' any data they have modified)
(If you want to do something that passes on modified data then you'd need to do something else, like using
_.wrap()
)
k
Thanks. This is very helpful and it explains why the original code isn’t working as intended. In this particular instance, the extension is updating the line items, which actually removes and re-adds the line item in the LiveOrder.Model updateLine() method, in the Application.on(‘after:LiveOrder.get’, function afterGet(self, result, noRecalc) {}); method, but this change in the line items isn’t reflected in the LiveOrder.Model get() data passed back to the client.
Is it possible to use _.wrap() to wrap the output of LiveOrder.Model get() method to modify the response passed back to the client using the Extensibility API in an extension? Or, do you need to modify the SCA code?
s
Wrapping a method can be used to change the final returned value from a method, yes. So if your method returns the sub total of the cart and then you wrap it to return its value multipled by 2 then it will always return that to whomever calls it
k
I understand. I was just wondering if there is a way to wrap the standard response from the LiveOrder.Line.ServiceController using the Extensibility Framework without having to create a custom service controller that calls the LiveOrder.Model methods to wrap them.
s
With the extensibility framework? if it's one of these then maybe but it depends on what you want to do https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Backend/BackendCartComponent.html#events
wrapping a service controller's methods and using the extensibility API are different beasts
k
Thanks. I’ll take a look at the BackendCartComponent. In summary, I might be able to modify the existing extension to use BackendCartComponent. If not, I’ll need to customize the SCA LiveOrder.Model or related service controller.
s
You can also look at the code for the backend cart component and see what it's doing, it may be helpful. The code also shows the event mapping
k
I searched the SCA code 2019.1.6 and the code for the BackendCartComponent does not exist. There is a file under APIdocs@sc-2019.1.6/SuiteScript but it’s a stub.
s
Cart > SuiteScript > Cart.Component.js
k
How does the Cart.Component.js get mapped to the BackendCartComponent? I have searched the SCA code and I can’t find any type of linkage. Is this handled by a core server side script that is not exposed in the SCA code?