Download PDF
Download page Updating Price For A Cart.
Updating Price For A Cart
This API enables you to update the price for items in a given cart. Only line items in pending status are updated.
API | Signature |
---|---|
updatePriceForCart | webService static Apttus_CPQApi.CPQ.UpdatePriceResponseDO updatePriceForCart(Apttus_CPQApi.CPQ.UpdatePriceRequestDO request) |
Parameters | ||
---|---|---|
Name | Type | Description |
Request | Apttus_CPQApi.CPQ.UpdatePriceRequestDO | The request data object. |
Request Data Object - Apttus_CPQApi.CPQ.UpdatePriceRequestDO | ||
---|---|---|
Field | Type | Description |
CartId | ID | The Id of the cart to update the price for. |
Response Data Object - Apttus_CPQApi.CPQ.UpdatePriceResponseDO | ||
---|---|---|
Field | Type | Description |
CompletedLineNumbers | List<Integer> | The list of line numbers representing line items that were updated in the current update price invocation. |
IsPostPricePending | Boolean | Indicates whether the execution of post-price logic is pending. |
IsPrePricePending | Boolean | Indicates whether the execution of pre-price logic is pending. |
IsPricePending | Boolean | Indicates whether there are more items to update in future invocations. The caller needs to invoke the update price method in a separate transaction. This should be repeated until there are no more items pending. |
IsTotalPricePending | Boolean | Indicates whether the calculation of the total price is pending. |
PendingLineNumbers | List<Integer> | The list of line numbers in pending status after the method completes. |
Code Sample
The sample below enables you to update the net price in the cart for pending line items. In the sample below, with a single call of updatePriceForCart API, the API computes the net price for a single line item with status pending. updatePriceForCart API is invoked using <apex:actionPoller> command until compute net price operation is completed for all the line items in the cart. For example, there are 10 line items in the cart and you invoke updatePriceForCart API 10 times at a regular interval of 5 seconds using <apex:actionPoller> command to complete the computing net price operation for all 10 line items.
<apex:actionPoller action="{!doUpdatePrice}" rerender="MessageID" interval="5" rendered="{!actionPollerActive}" enabled="{!actionPollerActive}"/> .
In the sample below the action poller is executed as soon as the page is loaded. The hasPendingitems flag returns false since no pending items have been added to the cart yet. If a valid cartID has been passed as an argument to the API and isPricePending returns true, run the action poller and invoke the updatePriceforCart API. The action poller does not run when hasPendingitems=false. You can invoke this API when the user adds discounts to the cart and clicks Reprice.
public void updatePriceforCart()
{
hasPendingItems = false;
actionPollerActive = true;
if(String.isBlank(cartId))
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.severity.info, 'Please create cart.'));
objUpdatePriceRequestDO = new Apttus_CpqApi.CPQ.UpdatePriceRequestDO();
}
else
{
// create the update price request
objUpdatePriceRequestDO = new Apttus_CpqApi.CPQ.UpdatePriceRequestDO();
// add request parameters
objUpdatePriceRequestDO.CartId = cartId;
// update price for the cart
Apttus_CpqApi.CPQ.UpdatePriceResponseDO result = Apttus_CpqApi.CPQWebService.updatePriceForCart(objUpdatePriceRequestDO);
hasPendingItems = result.IsPricePending;
// Start the action poller. If isPricePending=true returns true, run the action poller and the updatePrice API is invoked again
if (hasPendingItems)
{
actionPollerActive = true;
flagUpdatePrice = true;
}
}
}
// invoke the following in a new transaction using action poller
public void doUpdatePrice()
{
// update price for the cart
if(String.isNotBlank(cartId) && flagUpdatePrice == true)
{
// create the update price request
objUpdatePriceRequestDO = new Apttus_CpqApi.CPQ.UpdatePriceRequestDO();
// add request parameters
objUpdatePriceRequestDO.CartId = cartId;
Apttus_CpqApi.CPQ.UpdatePriceResponseDO result = Apttus_CpqApi.CPQWebService.updatePriceForCart(objUpdatePriceRequestDO);
hasPendingItems = result.IsPricePending;
List<Integer> pendingLineNumbers = result.PendingLineNumbers;
List<Integer> completedLineNumbers = result.CompletedLineNumbers;
if( hasPendingItems == false && completedLineNumbers.size() != 0 )
{
// stop the action poller
actionPollerActive = false;
}
else if( hasPendingItems == true && pendingLineNumbers.size() > 0 )
{
actionPollerActive = true;
}
}
}
Integration Details
Use the following information in your integrations with CPQ Web Services API. Refer to Integrating Conga with External Systems for information on how to get started.
API Prerequisites
Response/Request XML
Example Request
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:cpq="http://soap.sforce.com/schemas/class/Apttus_CPQApi/CPQWebService"
xmlns:cpq1="http://soap.sforce.com/schemas/class/Apttus_CPQApi/CPQ">
<soapenv:Header>
<cpq:SessionHeader>
<cpq:sessionId>00DZ000000NAEIA!ASAAQLC3rla0VIl_gk7v0A9K1n7dLEcCAANQHwNfXAPFKZEH292fAdeal5Nps8X2klNu98fcp6usnVFmzKARwE99xq_dE8U6</cpq:sessionId>
</cpq:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<cpq:updatePriceForCart>
<cpq:request>
<cpq1:CartId>a1OZ0000002ZQVZ</cpq1:CartId>
</cpq:request>
</cpq:updatePriceForCart>
</soapenv:Body>
</soapenv:Envelope>
Example Response
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="http://soap.sforce.com/schemas/class/Apttus_CPQApi/CPQWebService"
xmlns:UpdatePriceResponseDO="http://soap.sforce.com/schemas/class/Apttus_CPQApi/CPQ">
<soapenv:Body>
<updatePriceForCartResponse>
<result>
<UpdatePriceResponseDO:CompletedLineNumbers>1</UpdatePriceResponseDO:CompletedLineNumbers>
<UpdatePriceResponseDO:IsPostPricePending>false</UpdatePriceResponseDO:IsPostPricePending>
</result>
</updatePriceForCartResponse>
</soapenv:Body>
</soapenv:Envelope>