How to trigger add $10 from radio selection?

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #17833

How to trigger add $10 from radio selection?

I have a custom field "radio" in my check out page. i want to be able to add $10 to this if it's not null or false. would the simplest way be to just add some PHP code to a file somewhere to add $10 to the shopping cart?

i have most figured out but what code would i need to just add $10 extra if radio box was true on checkout page?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13375
  • MODERATOR
13 years 5 months ago #17843

You would have to edit the file cart of the view checkout via the menu Display->Views.
There, you could add something like that:

$already = false;  
foreach($this->rows as $i => $row){  
 if($row->product_code =='10_dollars_product') $already = true;
}  
if($this->order->custom_field_column_name){
 if(!$already){
  $app =& JFactory::getApplication();  
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));  
 }
}else{
 if($already){
  $app =& JFactory::getApplication();  
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));  
 }
}
supposing that the 10 dollars product has the id 106 and the product code 10_dollars_product and that your custom order field has the column name custom_field_column_name

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #17856

Why then use of the if else? can you explain the code more if you can? i just want to understand for future resources.. thanks..

Last edit: 13 years 5 months ago by Rickhavoc.

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13375
  • MODERATOR
13 years 5 months ago #17869

As you can see, in the if, the redirect url has a quantity of 1, which means that it adds the product 106 to the cart.
In the else, it has a quantity of 0, which means that it removes the product 106 from the cart.
So if the user changes his mind and toggle several times your custom field of the table order, the $10 product will be added or removed based on the user's change.

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #18893

i now have the radio selection in my field step of checkout do i add this code there instead?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13375
  • MODERATOR
13 years 5 months ago #18895

Why instead ?
You need to add it yes but you need to keep the code of the custom fields... Otherwise, you won't see your custom fields...

Please Log in or Create an account to join the conversation.

  • Posts: 156
  • Thank you received: 0
13 years 5 months ago #19003

the Radio selection field is now in the fields step of check out, i will be putting the custom fields differently using the code you gave me on the other post about echoing each field separately.

so this code

$already = false;  
foreach($this->rows as $i => $row){  
 if($row->product_code =='10_dollars_product') $already = true;
}  
if($this->order->custom_field_column_name){
 if(!$already){
  $app =& JFactory::getApplication();  
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));  
 }
}else{
 if($already){
  $app =& JFactory::getApplication();  
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=106&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));  
 }
}

do i add it to the view field of checkout? or which one?

Please Log in or Create an account to join the conversation.

  • Posts: 82868
  • Thank you received: 13375
  • MODERATOR
13 years 5 months ago #19024

That code uses mainly the data of the products in the cart, so I would put it in the cart file of the view checkout.

Please Log in or Create an account to join the conversation.

Time to create page: 0.047 seconds
Powered by Kunena Forum