Add product to table, shopping cart style.

  • 2
  • Question
  • Updated 5 years ago
  • Answered
I am yet to start using Skuid, i am interested as i hate the current look of salesforce however i am looking for a solution to a couple of specific user cases also and was wondering if Skuid will help. So without further ado:

1 - Shopping cart of opportunities.

When an opportunity is created we allow the users to add products to it from a price book. At the moment i have hacked together a decent enough page that has a table at the top (shopping cart) and all the items listed below with an "Add" button. Upon clicking on the "Add" button that product is added to the shopping cart, and it's fields can be edited as needed. What's key here is that the product has to remains available to be added multiple times.

Is this do-able in Skuid relatively easily? The implementation i currently have is done with various bits of custom classes and jQuery, but it's rather hacky and i would very much like something more solid.

2 - Drag Sorting of Tables

Related to the above, something i have looked at adding but haven't yet, is the ability to drag items around in the table to change the sort order. Important for creating quotes where the order the lines appear is critical?

If anyone could help me out with the above i would be most grateful, i'm sure i have many more question but those are the important ones for me before i look at deploying this into Sandbox to play with properly.

Thanks

Gareth
Photo of Gareth Jeanne

Gareth Jeanne

  • 100 Points 100 badge 2x thumb

Posted 5 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Hi Gareth,

The following is an answer to the first part of your question. The second part is doable as well but we'll answer it separately.

Here is a link to the XML for the Opportunity Detail page included in our Skuid for CRM starter pack, which has a "Shopping Cart" view for picking Products to add as Line Items.

OpportunityDetail.xml

And here is the tutorial for how to copy/paste page XML into a Skuid Page.

Just go to the "Line Items" tab once you've got your page up and running and have Previewed it, then click "Add Products" in the Line Items table, once you've picked a Pricebook for your Opportunity.

Here's what it looks like:









Photo of Gareth Jeanne

Gareth Jeanne

  • 100 Points 100 badge 2x thumb
Hi Zach, thanks for the speedy reply!

I have that installed and working, looks really good.

First question, i seem to be seeing items from multiple price books when i go to add items, is that correct?

Thanks

Gareth
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Have you selected a Pricebook already for the Opportunity before you go to add Items?
Photo of Gareth Jeanne

Gareth Jeanne

  • 100 Points 100 badge 2x thumb
Hi Zach, ignore me someone had modified the price book in Sandbox with some more items which I wasn't expecting. You mentioned you also had a solution for drag and drop sorting of line items?

Thanks

Gareth
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
Hi Gareth,

We can give you an example of making a Skuid Table's items drag/drop sortable, but this can't be used to affect the "SortOrder" field on Salesforce's OpportunityLineItem object because this field is not editable unless you use Salesforce's native Line Item sorting interface. So unless you have a custom Sort Order field on the OpportunityLineItem object in your org, we won't be able to help you much here. Here is one of several IdeaExchange ideas posted more than 5 years ago asking Salesforce to make this field Sortable:

Idea: OpportunityLineItem SortOrder to be Creatable/Updatable

If you DID have a custom Sort Order field, here's how you would do it:

  1. Give your Line Items Table a Unique Id -- go to the table's Advanced properties and enter "LineItemsTable" for the "Unique Id" property.
  2. Drag a "Custom" Component into your page, to be located just below your Line Items table. Set "Component Type" to MakeLineItemsTableSortable
  3. Go to JavaScript Resources and create a new JavaScript Resource of type Inline (Component) named MakeLineItemsTableSortable. Its Resource Body should be the following, only replace "Sort_Order__c" with whatever your custom Sort Order field is called:


var LINE_ITEMS_TABLE_ID = 'LineItemsTable';
var SORT_ORDER_FIELD_ID = 'Sort_Order__c';
var element = arguments[0],
   $ = skuid.$;
setTimeout(function(){
    // Find our LineItemsTable
    var T = $('#'+LINE_ITEMS_TABLE_ID),
        TBody = T.find('tbody'),
        list = T.data('object').list,
        model = list.model;
    
    // Return a helper with preserved width of cells
    var fixHelper = function(e, ui) {
        ui.children().each(function() {
            $(this).width($(this).width());
        });
        return ui;
    };
    
    TBody.sortable({
        helper: fixHelper,
        // Run as soon as the user stops sorting
        stop: function(event,ui){
            // Loop over the tr rows in the table body,
            // and update the corresponding data rows' SortOrder
            var updates = {},
                items = [];
            TBody.children('tr').each(function(){
               var tr = $(this),
                    item = tr.data('object'),
                    row = item.row,
                    updateObj = {};
                updateObj[SORT_ORDER_FIELD_ID]=tr.index()+1;
                updates[row.Id]=updateObj;
                items.push(item);
            });
            model.updateRows(updates);
            // Now reorder the rows in our Model based on Sort Order
            model.data.sort(function(a,b){return a[SORT_ORDER_FIELD_ID]-b[SORT_ORDER_FIELD_ID]});
            $.each(items,function(){
               $.each(this.fields,function(){
                 if (this.id===SORT_ORDER_FIELD_ID)this.render();  
               });
            });
        }
    }).disableSelection();
    
},1000);