I need to return two fields

  • Posts: 83
  • Thank you received: 10
12 years 2 months ago #66790

I need to adjust the shipping_id prior to payment. To do so I need to get the value of two custom fields in order "co_villa" and "co_addon" so that I can apply them to a sql statement.

I then need to set the shipping_id accordingly.

This will be an "include" and run on the payment.php workflow

<?php
Include ("databaselogin.php");

//get the customer's villa name and determine if it is an add-on order
$thevilla = $this->co_villa; ********help me with this line please*********
$addonorder = $this->co_addon;********help me with this line please*********


if ($addonorder)
  {
  $deliveryarea = 3;
  }
else
  {
$theSQL = "SELECT ib_villas.villa_deliverylocation
FROM jos_hikashop_zone INNER JOIN ib_villas ON jos_hikashop_zone.zone_id = ib_villas.villa_zone
WHERE (((jos_hikashop_zone.zone_type)='ship') AND ((jos_hikashop_zone.zone_namekey)= '" . $thevilla . "'))";

$query = mysql_query($theSQL);
while ($result = mysql_fetch_array($query)) {
           $deliveryarea =  $result["villa_deliverylocation"];
  }
  }


//at this point the delivery should be 1,2,or 3 depending on the location of the villa and if this is an add-on order
$this->shipping_id  == $deliveryarea;********help me with this line please*********

?>

Please can you help me with the lines that I have drawn attention to above.

Last edit: 12 years 2 months ago by jrod.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #67027

It would have helped if you would have given the table of your custom fields.
User ? item ? address ? order ?

Without knowing how your custom fields are configured I can't tell you how to access them.

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

  • Posts: 83
  • Thank you received: 10
12 years 1 month ago #67029

the two custom fields are in the order table, i put that in the first line, but I can see how it is not clear at all.

Last edit: 12 years 1 month ago by jrod.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #67034

You can do like that:

$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);

$thevilla = $order->co_villa;
...etc...


And to set the shipping id, you will have to do like that:
$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);

Note that in the payment view, the cart info is already loaded. So you will see the newly selected shipping method only on the next page.

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

  • Posts: 83
  • Thank you received: 10
12 years 1 month ago #67046

returning the two custom fields works perfectly the way you described.

I am not successful in setting the shipping_id though. This is what I have:

<?php
Include ("databaselogin.php");
$app =& JFactory::getApplication();
$order = $app->getUserState( HIKASHOP_COMPONENT.'.checkout_fields',null);


//get the customer's villa name
$thevilla = $order->co_villa;
$addonorder = $order->co_addon;


if ($addonorder)
  {
  $deliveryarea = 3;
  }
else
  {
$theSQL = "SELECT ib_villas.villa_deliverylocation
FROM jos_hikashop_zone INNER JOIN ib_villas ON jos_hikashop_zone.zone_id = ib_villas.villa_zone
WHERE (((jos_hikashop_zone.zone_type)='ship') AND ((jos_hikashop_zone.zone_namekey)= '" . $thevilla . "'))";

$query = mysql_query($theSQL);
while ($result = mysql_fetch_array($query)) {
           $deliveryarea =  $result["villa_deliverylocation"];
  }
  }

// the following line successfully returns a 1,2,or 3
echo $deliveryarea;

// the following lines do not set the shipping_id to 1,2, or 3
$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);

?>



it is the last line that I'm having the issue with:
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);
Note, its not necessary for the shipping choices to actually show, as long as the shipping is adjusted before the credit card is processed.

Last edit: 12 years 1 month ago by jrod.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 1 month ago #67151

You will probably also need to add additional code to give the shipping data:

$app =& JFactory::getApplication();
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_id',$deliveryarea);
$class = hikashop_get('class.shipping');
$shipping = $class->get($deliveryarea);
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_method',$shipping->payment_type);
$app->setUserState( HIKASHOP_COMPONENT.'.shipping_data',$shipping);

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

Time to create page: 0.063 seconds
Powered by Kunena Forum