0

I am building a web app for a client. The gist of it is this...

Using Angular JS / Cartthrob / Stash to load all products. AngularJS to filter through. Cartthrob handling the cart side of things.

The resulting HTML all looks OK to me. I think something is not quite right with the multi-add_to_cart tag and the why I have coded it. I have tried a zillion different set ups to get it to work.

Currently, when I submit, I get a refresh, no errors, but nothing is adding to the cart and debug doesn't show anything. I think I am missing a trick with the add to cart tag. Can you see what I have done wrong?

Product loop:

{exp:cartthrob:multi_add_to_cart_form return="" show_errors="yes"}
    <div class="accordion" id="product_list">
        <div class="accordion-group" ng-repeat="prod in products | filter:query ">
            <div class="accordion-heading order_listing">
                <div class="row">
                    <div class="col-lg-2 image_container">
                        <img ng-src="{{prod.images_url}}" width="100px">
                    </div>
                    <div class="col-lg-7">
                        <h4>{{prod.series_description | uppercase}}: <small>{{prod.product_sku}}</small></h4>
                        <span ng-show="prod.sort_group !=''" class="label label-info">{{prod.sort_group}}</span>
                        <span ng-show="prod.tool_type !=''" class="label label-warning">{{prod.tool_type}}</span>
                        <span ng-show="prod.material !=''" class="label label-danger">{{prod.material}}</span>
                        <em class="text-muted">{{prod.finish}}</em>
                        <br><br>
                        <p class="text-muted">{{prod.application_details}}</p>
                    </div>

                    <div class="col-lg-1">
                        <i class="icon-heart icon-2x icon-grey pull-right"></i>
                    </div>

                    <div class="col-lg-2">
                        <a class="accordion-toggle pull-right btn btn-primary btn-mini" data-toggle="collapse" ng-click="getDetail($index)" data-parent="#product_list" href="#collapse{{prod.entry_id}}">
                            View Details
                        </a>
                    </div>
                </div>
            </div>
            <div id="collapse{{prod.entry_id}}" class="accordion-body collapse">
                <div class="accordion-inner">
                    <div class="panel">
                      <div class="panel-heading"><strong>Pack Details:</strong></div>
                      {{prod.pack_details}}
                    </div>
                    {sn:general:detailloader}
                    <table class="table table-hover">
                        <tr>
                            <th>Series Code</th>
                            <th>Size</th>
                            <th>Price</th>
                            <th>Add to order</th>
                        </tr>

                        <input type="text" name="entry_id[{{prod.entry_id}}]" value="{{prod.entry_id}}" style="width: 40px;" />
                        <input type="text" name="title[{{prod.entry_id}}]" value="{{prod.entry_id}}" style="width: 40px;" />

                        <tr ng-repeat="series_detail in productDetail">
                            <td>{{series_detail.part_no}}</td>
                            <td>{{series_detail.size}}</td>
                            <td>{{series_detail.price2020 | currency:"£"}}</td>
                            <td>
                                <div class="form-inline">
                                    <input class="form-control input-small" ng-model="qty" ng-init="qty=''" type="text"  name="quantity[{{prod.entry_id}}-{{$index}}]" style="width: 40px;">

                                    <input type="text" value="{{series_detail.part_no}}" name="item_options[{{prod.entry_id}}-{{$index}}][option_value]" style="width: 40px;"/>

                                    <input type="text" name="price[{{prod.entry_id}}-{{$index}}]" value="{{series_detail.price2020 * qty}}" style="width: 60px;" />
                                    <button type="submit" class="btn btn-default btn-small">Add</button>
                                </div>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    {/exp:cartthrob:multi_add_to_cart_form}

Thanks all

2

Your rendered HTML would be far more useful than your template code in this case, but there are some irregularities here that I see:

<input type="text" name="entry_id[{{prod.entry_id}}]" value="{{prod.entry_id}}" style="width: 40px;" />
<input type="text" name="title[{{prod.entry_id}}]" value="{{prod.entry_id}}" style="width: 40px;" />

These indicate to me that you're using each product's entry_id as the key for your array of items. But later you have:

<input class="form-control input-small" ng-model="qty" ng-init="qty=''" type="text"  name="quantity[{{prod.entry_id}}-{{$index}}]" style="width: 40px;">
<input type="text" value="{{series_detail.part_no}}" name="item_options[{{prod.entry_id}}-{{$index}}][option_value]" style="width: 40px;"/>
<input type="text" name="price[{{prod.entry_id}}-{{$index}}]" value="{{series_detail.price2020 * qty}}" style="width: 60px;" />

Here you're using entry_id-$index as the key, so your quantity, item_options and price will not match your entry_id and title.

(By the way, I'm pretty sure that title is ignored when adding products which are not "on-the-fly", and that allow_user_price must be set and if you want to pass a custom price for the same.)

1
  • Thanks very much Derek. I actually posted experimental code on here. Sorry. I did have the array correct at one point, but it didn't work. I got some support over at CT Forum - their back!! Really fast response. The issue was with the array. I had a '-' in it which threw it off. EG: 248-1 Should have been 2481 Nailed it. Thanks again Derek.
    – T2theC
    Aug 29 '13 at 7:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.