Hey everyone, is there any way we can easily creat...
# suitecommerce
j
Hey everyone, is there any way we can easily create a bulk transaction item option rather than manually creating them?
m
Do you mean when an item is added to the cart set multiple options in code? I don't know if this best practice but I extended Cart.AddToCart.Button.View
Copy code
return _.extend(CartAddToCartButtonView.prototype, {
            events: {
                "click [data-type=\"add-to-cart\"]": "addToCartCustom"
            }
            , addToCartCustom: function addToCart(e) {
                e.preventDefault();                            this.model.setOption("custcol_delivery_type", session.delivery_type);
this.model.setOption("custcol_delivery_date", session.delivery_date);
this.model.setOption("custcol_delivery_appointment_id", session.appointment_id);
                    this.addToCart(e);
                }
            }
        });
😮 1
There is another way that I tested that is probably more reliable to work with other extensions.
Copy code
/* eslint-disable no-invalid-this */
define("YourExtension.Cart.AddToCart.Button.Extend"
    , [
        "Cart.AddToCart.Button.View"

        , "underscore"
    ]
    , function EditOrderCustomCartView(
        CartAddToCartButtonView
        , _
    ) {
        "use strict";

        return _.extend(CartAddToCartButtonView.prototype, {

            addToCart: _.wrap(CartAddToCartButtonView.prototype.addToCart, function wrapaddToCart(fn) {
                this.model.setOption("custcol_youroptions", "your_value");
                this.model.setOption("custcol_yourotheroptions", "your_other_value");
                fn.apply(this, _.toArray(arguments).slice(1));
            })
        });
    });