Discussions

Installments

Hi i would like to have an option it the payment methods that the user can specify how much installments he wants so he can buy a product.Depending on his choice there has to be a field that calculates the installment for each month.

To make my self clear lets say that he wants to buy a product that costs 1000 $ an he wants to pay with 5 installments. So he writes in a field the number 5 and in another field he has to see "5 installments of 200$"

No credit card involved.

I tried to do it but i can figure out how to get the value of the order price from a .module page that is responsible for an extra option in the payment methods.

I know some php but its not enough i cant figure out how to call specific fields from the page.

Sorry for my English its horrible.

Thanks i am hoping for your help.

Posted: Jan 18, 2012

Comments

oz_an on January 18, 2012

I couldn't understand what u mean by how to get the value of the order price from a .module page that is responsible for an extra option in the payment methods .
But if you want to present some installment choices after user presses a payment method, your_module_submit_from is for you, I think. For instance you can prepare a table which shows the options and total amount like this:

$header=array('num_of_installment'=>'Number of Installment','installment_amount'=>'Installment Amount','total_amount'=>'Total');
$installment_options = calculate_installment($order->commerce_order_total[LANGUAGE_NONE][0]['amount']);

$form['installment table'] = array(
  '#type' => 'tableselect',
  '#name'=>'installment',
  '#title' => t('Your Payment Options'),
  '#header' =>$header,
  '#multiple'=>FALSE,
  '#options' =>$installment_options ,
);

return $form;

You can implement a "calculate_installment" function, basically it has to return an options array like:

$options = array(1=>('num_of_installment'=> '2','installment_amount' => '234.00','total_amount'=> '468.00'),
2=>(...));
return $options;

You should definitely see the commerce_payment_example module.

pit_zavra on January 18, 2012

thanks oz_an for your reply i will test it and i will give feedback.
i was refering to the commerce_payment _example.module page
when i said .module, that was the page that i wanted to get the order total
I used this module because i diden't know any other way to make another payment method.

So can i put your code in that module page?
thanks again

pit_zavra on January 19, 2012

Ok i think i got it I have to declare the function like this But Dreamweaver says there is a syntax error.

function calculate_installment() {

$options = array();
$options = array(1=>('num_of_installment'=> '2','installment_amount' => '234.00','total_amount'=> '468.00'),

2=>(...)

);

return $options;

}

pit_zavra on January 19, 2012

function calculate_installment() {

$options = array();

I think i found the error
$options = array(
1 => array('num_of_installment' => '2',
'installment_amount' => '234.00',
'total_amount' => '468.00'

),
2 => (''),

);

return $options;

}

pit_zavra on January 19, 2012

Thank you that was it but 2 more questions if you do not mind.
First i want the commerce_order_total[LANGUAGE_NONE][0]['amount']) to return the price with 2 decimals
and the currency sign, example from 14000 to 140,00 €.

Second witch option of installment was clicked,

to show in the administrator order form /admin/commerce/orders/19/payment
and it would be great if the user can see it in the /user/1/orders page.

Thanks again you saved me i was searching this for many days.

oz_an on January 19, 2012

Obviously I tried to give an example array and the first entry for it. The part 2=> (...) means you should enter values like the first one.
This, of course, should be prepared dinamically and you should call the function with the order_amount parameter. I think you should get some help to get it done.