Hi,
You need to use a specific "name" in your input field:
$name = 'checkout[shipping][custom]'.(isset($order->shipping_warehouse_id) ? ('['.$order->shipping_warehouse_id.']') : '').'['.$method->shipping_id.']';
Then, it will be saved in the cart in the database for you.
However, you will have to save it in the order yourself in the "onBeforeOrderCreate" event like so:
public function onBeforeOrderCreate(&$order, &$do) {
$cart_shipping_ids = $order->cart->cart_shipping_ids;
$cart_params = $order->cart->cart_params;
$process = array();
if(empty($cart_shipping_ids))
return;
if(is_string($cart_shipping_ids))
$cart_shipping_ids = explode(',', $cart_shipping_ids);
foreach($cart_shipping_ids as $shipping_id) {
list($sip,$warehouse) = explode('@', $shipping_id, 2);
$current = null;
foreach($order->cart->shipping as $shipping) {
if($shipping->shipping_id != $sip)
continue;
$current = $shipping;
break;
}
if(empty($current) || $current->shipping_type != $this->name)
continue;
$process[$warehouse] = $sip;
}
if(empty($process))
return;
$order_shipping_params = $order->order_shipping_params;
foreach($process as $warehouse => $id) {
$shipping_data = null;
if(!empty($order->cart->cart_params->shipping) && is_object($order->cart->cart_params->shipping) && isset($order->cart->cart_params->shipping->{$warehouse}))
$shipping_data = $order->cart->cart_params->shipping->{$warehouse};
if(!empty($order->cart->cart_params->shipping) && is_array($order->cart->cart_params->shipping) && isset($order->cart->cart_params->shipping[$warehouse]))
$shipping_data = $order->cart->cart_params->shipping[$warehouse];
if(!empty($shipping_data)) {
$data = (isset($shipping_data->{$id}) ? $shipping_data->{$id} : null);
if(empty($order_shipping_params->newpluginshipping))
$order_shipping_params->newpluginshipping = array();
$order_shipping_params->newpluginshipping[$warehouse] = $data;
}
}
$order->order_shipping_params = $order_shipping_params;
}
It's a bit complex to do because with HikaShop, you can have different shipping methods sections for the same cart, one for each warehouse / vendor. So, for one order, you can potentially end up with several shipping methods of the same plugin to process.
While, in most cases, this is overkill, if you want to share your plugin so that it can work for anyone using HikaShop, this is the best approach.
A simpler approach would be to implement the event onShippingSave in order to look in the POST for your input value (in that case, you can use whatever name you want in the input), store the value in the user session, and then you can use onBeforeOrderCreate to store the value from the session to the order.
However, there are several limitations with this. You will have a hard time supporting different warehouses/vendors, if the user session timeout, you'll loose the value previously entered by the user, even though there rest of the information provided by the user will still be available to him if he logs back in, and you need to build some logic and checks yourself when the user doesn't fill in the field, or when another shipping method is selected.