To display the category-based subtotal in the shopping cart

We display the subtotal for products in the salon category on the cart page. Items other than those in the salon category are categorized as Jan/Sen products.

cart_summary.tpl

  {{#if GlossLab}}
        <td class="cart-summary-item-count-total custom">
           
            <div>Jan/Sen products : {{Symbol}}{{nonSalonProduct}} </div>
            <div>Salon products : {{Symbol}}{{salonProduct}}    </div>
        </td>
        {{/if}}

Cart.Summary.View.Site.js

var GlossLab;
                var customersegment = _.find(profile_model.attributes.customfields, function (cust) {
                    return cust.name == "custentity_hidden_customersegment"
                });
                if (customersegment && customersegment.value) {
                    var parseSegment = JSON.parse(customersegment.value)
                    if (configCustomer) {
                        if (_.findWhere(parseSegment, {id: configCustomer})) {
                            GlossLab = true;
                        }
                    }
                    else {
                        if (_.findWhere(parseSegment, {id: "6636"})) {
                            GlossLab = true;
                        }
                    }
                }
                if (lines) {
                    var itemsSalon = [];
                    var nonSalon = []
                    _.each(lines, function (record) {
                        var item = record.get('item');
                        var commercecategory = item.get('commercecategory')
                        var primaryPath = commercecategory.primarypath;
                        var categories = commercecategory.categories;
                        var salon;
                        if (primaryPath.length > 0) {
                            _.each(primaryPath, function (path) {
                                if (path.name == "Salon Products"&&path.id == segmentId) {
                                    salon = true;
                                }
                            });
                        }
                        else if (categories.length > 0){
                            _.each(categories, function (path) {
                                if (path.name == "Salon Products" &&path.id == segmentId) {
                                    salon = true;
                                }
                            });
                        }
                        if (salon === true) {
                            itemsSalon.push(record)
                        }
                        else {
                            nonSalon.push(record)
                        }
                    });
                    salonProduct = parseFloat(addPriceToAmountUnderscore(itemsSalon)).toFixed(2)
                    nonSalonProduct = parseFloat(addPriceToAmountUnderscore(nonSalon)).toFixed(2)
                }
                function addPriceToAmountUnderscore(items) {
                    return items.reduce(function (sum, item) {
                        return sum + item.get('amount');
                      }, 0);
                }

Leave a comment

Your email address will not be published. Required fields are marked *