Quantity not appearing on invoice created by WHMCS

488 views Asked by At

I am trying to place an order via WHMCS API on my local environment. This is my order code,

$postfields["action"] = "addorder";
$postfields["clientid"] = "104";
$postfields["billingcycle"] = "monthly";
$postfields["pid"] = "55";
$postfields['configoptions'] = base64_encode(serialize(array(1 => 3)));
$postfields["regperiod"] = "5";
$postfields["paymentmethod"] = "paypal";

It is listed on the API doc that 'configoptions',

$postfields['configoptions'] = base64_encode(serialize(array(1 => 3)));

^ is for changing the order quantity and other options(first element is for the quantity). Problem is that the invoice generated by WHMCS only contains quantity as 1 and not 3.

---------------------------------------------------------Edit 1 ------------------------------------------------------------------

I have looked into the product configurations, "Tick this box to allow customers to specify if they want more than 1 of this item when ordering" option is ticked as well!

1

There are 1 answers

1
anthonyPHP On

A bit late to the game but oh well.

In the current WHMCS API documentation for the AddOrder function I have not been able to find anything regarding quantity, I have a feeling that at this point that simply enables an input in the order form and WHMCS handles that input somehow.

I did find a way that might work for you though. Im not sure how you are actually using the API if it's driven by some custom form somewhere or what but you can do the following.

in lieu of:$postfields['configoptions'] = base64_encode(serialize(array(1 => 3))); which doesn't seem to work you can just use the 'pid' field to specify the quantity, something like this:

$quantity = trim(str_repeat("{$pid},", $_POST['qty']), ',');
$postfields["pid"] = $quantity;

Simply repeating the product ID as many times as desired sets the quantity, you can do basically the same thing using the local API function, see below:

$quantity = array_fill(0, $_POST['qty'], $pid);
$command = 'AddOrder';
$postData = array(
'clientid' => '1',
'pid' => $quantity,
'domain' => array('example.com'),
'billingcycle' => array('monthly'),
'paymentmethod' => 'PayPal',
);

The result of the above code will be a single order with however many products ($pid) were specified in $_POST['qty']