shane
shane

Reputation: 862

adding the 'custom' hidden field to simplecart (paypal)

I would like to send over some custom data to the Paypal Checkout using the 'custom' hidden form field. When not using SimpleCart.js, this is as easy as appending this to the html form:

<input type="hidden" name="custom" value="My Custom data">

Any idea how I can achieve the same thing with simplecart?

Looking through the source I can see where the form is created/submitted.

generateAndSendForm: function (opts) 
{
    var form = simpleCart.$create("form");
    form.attr('style', 'display:none;');
    form.attr('action', opts.action);
    form.attr('method', opts.method);
    simpleCart.each(opts.data, function (val, x, name) 
    {
        form.append(
            simpleCart.$create("input").attr("type","hidden").attr("name",name).val(val)
        );
    });
    simpleCart.$("body").append(form);
    form.el.submit();
    form.remove();
}

So, I could just modify this code to make it work, but I'm sure there there must be a better way. Anyone have any ideas?

Upvotes: 0

Views: 1307

Answers (2)

LordVee
LordVee

Reputation: 104

old thread, but may be interesting for somebody else. you are looking at the wrong method:

generateAndSendForm:

is used to generate a form that will (most likely) POST data to your backend

what you want to be looking at is:

simpleCart.extendCheckout({
  PayPal: function (opts) {
  [...]

and you may want to add:

if (opts.custom) {
  data.custom = opts.custom;
}

somewhere after the equivalent for notifications:

if (opts.notify) {
 data.notify_url = opts.notify;
}

I have not tested it personally but it should do exactly what you need

Upvotes: 0

Erik5388
Erik5388

Reputation: 2211

Adding anything extra in simple cart requires adding a simple class...

For example,

<input type="hidden" name="custom" value="My Custom data" class="item_customdataname">

Notice my class and nomenclature. "item_customdataname".

However, due to the nature of simplecart, I'd reccomend the following;

<span style="display: none;" class="item_customdataname">My Custom data</span>

Not to say using a hidden input wouldn't work...

E

Upvotes: 1

Related Questions