Hi,
The MyParcel plugins do the same as what you want to do, but for MyParcel:
- The pickup location selector plugin (
www.hikashop.com/marketplace/product/251...selector-plugin.html
) will allow you to add a shipping method to the checkout ( based on the shipping API:
www.hikashop.com/support/documentation/6...tation.html#shipping
), and when selected, it will display a pickup location selector. The plugin won't allow the customer to finish the checkout if that shipping method is selected and a pickup location is not selected. And the plugin will also store the selected pickup location in the order.
- The label and track plugin (
www.hikashop.com/marketplace/product/245...shipping-plugin.html
) has an automatic export option which, when activated, will send the details of the order, along with the selected pickup location, to the MyParcel server when the order is created or confirmed. It has extra features, like printing the shipping label, retrieving the tracking information of the package etc.
So, you could potentially base yourself on these plugins. That might be quite helpful, but they are not free...
1. In onShippingDisplay you can add your custom HTML in the "custom_html" attribute of your shipping method object. HikaShop will automatically hide / display your HTML when the shipping method is selected or another shipping method is selected.
On top of the widget's HTML, you should add a hidden input with the name:
$map = 'checkout[shipping][custom]'.(isset($order->shipping_warehouse_id) ? ('['.$order->shipping_warehouse_id.']') : '').'['.$rate->shipping_id.']';
2. HikaShop will make sure the customer select something in the widget by making sure this input is filled before proceeding.
It will also store the data in that input in $order->cart->cart_params->shipping which will be available to you in the event onBeforeOrderCreate. There, you can store the data you want in either a custom order field, or in the order_shipping_params data of the order.
3. If you want to send the data of the order to the API when the order is created, I recommend doing so in the onAfterOrderCreate event. In that case, the data of the shipping method will be available in $order->cart->cart_params->shipping so you don't even need to store it in onBeforeOrderCreate, unless you want to display it in the order details, the emails, the backend, etc.
If you want to send the data of the order to the API when the order is confirmed (after the payment is made), then you want to implement onAfterOrderUpdate and check $order->order_status and $order->old->order_status to make sure the order status is being changed from created to confirmed.
You can read more about these events here:
www.hikashop.com/support/documentation/6...mentation.html#order