How to trigger add $10 from radio selection?part2

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21057

So i now have a custom field name numberchoice which is a radio selection with the values of keepnumber or newnumber. i want something like this to happpen based on the selection. what can i do to the code below to get what i am looking for.


$already = false;
foreach($this->rows as $i => $row){
if($row->product_code =='Transfer_Number_Fee') $already = true;
}
if($this->order->numberchoice){
if(!$already){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&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=9&quantity=0&add=1&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21064

You say that the custom field numberchoice can have the values of keepnumber or newnumber, so your if should reflect that.
Instead of:
if($this->order->numberchoice){

you should have:
if($this->order->numberchoice=='newnumber'){

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21196

$already = false;
foreach($this->rows as $i => $row){
if($row->product_code =='Transfer_Number_Fee') $already = true;
}
if($this->order->numberchoice=='keepnumber'){
if(!$already){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}else{
if($this->order->numberchoice=='newnumber'){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=1&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}
This is what i have now. it's not doing anything.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21208

That's not what I said. You should do like that:

$already = false;
foreach($this->rows as $i => $row){
if($row->product_code =='Transfer_Number_Fee') $already = true;
}
if($this->order->numberchoice=='newnumber'){
if(!$already){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&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=9&quantity=0&add=1&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21271

$already = false;
foreach($this->rows as $i => $row){
if($row->product_code =='Transfer_Number_Fee') $already = true;
}
if($this->order->numberchoice=='newnumber'){
if(!$already){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&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=9&quantity=0&add=1&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}

i don't think this is going to give me the result i want. the code says if they select they want a new number and there isn't a transfer fee there it will add one. I want the transfer fee to come up when they select that they want to keep their number, so it would be 'keepnumber' instead of 'newnumber'. also based on the code you sent me wouldn't it get stuck in a loop? adding and removing the product? if the selection was left on 'newnumber'.


so over all what we want is that if the selection is 'keepnumber' to add the transfer fee to the cart, and if they select 'newnumber' it gets removed. That is why i thought this might work.
$already = false;
foreach($this->rows as $i => $row){
if($row->product_code =='Transfer_Number_Fee') $already = true;
}
if($this->order->numberchoice=='keepnumber'){
if(!$already){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}
}else{
if($this->order->numberchoice=='newnumber'){
$app =& JFactory::getApplication();
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=1&return='.urlencode(base64_encode(hikashop::currentUrl()))));
}

it's not doing anything at the moment. just thought it might need some tweaking to make it work. also since this on the custom field part should i add the code there or in the cart view? also since it's in the custom fields part should we add the a check for the user selection like we had in the code for the custom fields?

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21292

It might be because of your checkout workflow. If the cart and the field view are not on the same step, your code will either miss the $this->order (from the field view) or the $this->rows (from the cart view). Please make sure that you have both cart and field view on the same step and try again.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21295

well i don't want to mess up the flow of the checkout. this is what it is now cart,login_address_terms,fields,shipping_payment,confirm_address_cart_status,end

your saying to change it to
cart_fields,login_address_terms,shipping_payment,confirm_address_cart_status,end

i don't want the fields to be under the cart. i would like them to be as they are now. what can i do to the code above to make it work like that.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21302

What you could do is to put that code in the cart view and add before it the code below:
$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop_get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');
That will initialize the custom fields data on the cart view.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21305

i think that might work since i got the cart view before the end for review. i will be using authorize.net as SIM when will the payment be processed in the checkout i assume at the step end? so that this gets added to the charge at the review step.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21314

Yes, that would be done on the review step before the confirmation of the order.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21358

landing on the cart i get this.
Fatal error: Call to undefined function hikashop_get() in /home/iqcellul/public_html/templates/ja_anion/html/com_hikashop/checkout/cart.php on line 234


This is the whole code right now


$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop_get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');

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

Last edit: 13 years 4 months ago by Rickhavoc.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21369

That's because you don't use the latest version. change the code hikashop_get with hikashop::get and it should work.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21404

is that change across for all the code? will hikashop::completeLink be hikashop_completeLink in the new version?

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21408

this is what i have now to try to accomplish a product being added to the cart if a radio selection is selected from the order fields.

$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop::get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');

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

i tried it with and without the false,true

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21419

Yes, that change will be for all the hikashop:: code. However, we kept the backward compatibility so that you can continue to use hikashop:: in your customized views. We had to do that change in order to avoid the deprecated warnings from PHP 5.3 when the strict mode is activated.

That code seems correct. You should put some traces to make sure that the $already has the correct value before the if and that the $this->order variable contains the numberchoice custom field value.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21511

So it's down to the $app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop::get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');

cause i used firephp to echo the value of $this->order->numberchoice and in the cart view i get null , but in the fields view i get the correct value. so it's something to do with the code above and bring in the data from the order table.

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21518

here i got it working like this

$order = $app->getUserState(HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop::get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');
$already = false;
$clean = false;  
foreach($this->rows as $i => $row){   
 if($row->product_code =='Transfer_Number_Fee') $already = true;
}
  
if(!$already && $plan){
  if($order->numberchoice=='keepnumber'){
  $app =& JFactory::getApplication();   
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));   
  }
}
  elseif($order->numberchoice=='newnumber'){
   if($already){
   $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));
  }
}
   elseif($order->numberchoice=='keepnumber'){
   if($already && !$plan){
  
  if(!$clean){
  $clean = true;
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));
 }
}
  }else{}
now the problem is that when i click the last next it gives me a 505 error.
i removed
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);
$fieldsClass = hikashop::get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order')
and i got it working so how do i undo the loading off all the extra fields before going to the next step.

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21521

Try to remove just the two lines:
$fieldsClass = hikashop::get('class.field');
$this->order = $fieldsClass->getFields('frontcomp',$order,'order');

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

  • Posts: 156
  • Thank you received: 0
13 years 4 months ago #21523

That worked. The issue now is on the payment view when you click next, which is suppose to go the the review page where it will where the cart view is again with the updated totals. it takes me back to step one of the cart.

$order = $app->getUserState(HIKASHOP_COMPONENT.'.checkout_fields',null);
$already = false;
$clean = false;  
foreach($this->rows as $i => $row){   
 if($row->product_code =='Transfer_Number_Fee') $already = true;
}
  
if(!$already && $plan){
  if($order->numberchoice=='keepnumber'){
  $app =& JFactory::getApplication();   
  $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=1&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));   
  }
}
  elseif($order->numberchoice=='newnumber'){
   if($already){
   $app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));
  }
}
   elseif($order->numberchoice=='keepnumber'){
   if($already && !$plan){
  
  if(!$clean){
  $clean = true;
$app->redirect(hikashop::completeLink('product&task=updatecart&product_id=9&quantity=0&add=0&return='.urlencode(base64_encode(hikashop::currentUrl())),false,true));
 }
}
  }else{}

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

  • Posts: 82868
  • Thank you received: 13376
  • MODERATOR
13 years 4 months ago #21533

In your code, try to change &return= by &return_url=

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

Time to create page: 0.087 seconds
Powered by Kunena Forum