Extra field in own manual shiping plugin

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 5 months ago #241786

-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.4.8
-- PHP version -- : 5.4

Hi,

I’am developing own manual shipping plugin. I want to add a new field (list) inside shipping method that I’m developing. If customer choose my shipping method extra field should appear. Content of that field will be downloaded form api of other services – so it will be dynamic.

So, when customer click on my shipping method, will see a new list field (it will be list of address to shipping, but it will be downloaded by api). Customer selects one address from list. When the order is made, in confirmation email, that value from new field list will appear. In hikashop orders, that information should also be display (but email is more important).

I spend many hours trying to make that plugin, but I don’t know how to:
a) Insert new field in my shipping plugin (in the list of shipping plugins). I try to use onShippingDisplay method but field appear on the top of checkout page. Also when i use that method my, shiping method don’t display at all
b) How to pass value from new list field to email and order information in hikashop admin panel.

Thank for your help.

The following user(s) said Thank You: korzo

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 5 months ago #241811

Hi,

You can't directly add that there.
I would recommend to do it differently:
Use the checkout API to add a new view in the checkout workflow where you would display your selection system based on which shippign method has been selected: www.hikashop.com/support/documentation/6...tation.html#checkout
You can use the onAfterCheckoutStep trigger to store the selection in the session, and then the onBeforeOrderCreate trigger to store it from the session to the order, in order_shipping_params for example. And then you can use onAfterOrderProductsListingDisplay to add the selection in the emails, order details, etc.

I would recommend to look at the envoimoinscher shipping plugin which does all that to handle the selection of the pickup point after the shipping method is selected (so similar to your needs):
github.com/HikaShop/hikashop-envoimoinscher

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

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 5 months ago #242583

Thank You but I have my checkout on one page, I don’t use steps. I have added new field using onShippingSave. I don’t know how to add value from that filed to email with notification.
I find, that i have to add in html version:

Adress: {VAR:ADRESS}
And add in preload version:
$vars['ADRES'] = ??

How can I pass vale from shipping plugin to $vars in email?
Thank You for help

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 5 months ago #242606

Hi,

In the onShippingSave method of your plugin where do you store the data you receive ?
Normally, I would recommend to store it in $_SESSION
Then, add a onBeforeOrderCreate(&$order,&$do) trigger to your plugin to get the data from $_SESSION and put it in a custom field of the order table in $order->custom_field (supposing that the column name of your custom order field is custom_field ).
That way, you can easily find your data in $data->cart->custom_field in your email.
Since it's only for yourself, you can directly add your php where you want it in the HTML version of the email.
It will be simpler than going through tags.

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

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 5 months ago #243005

  1. In onShippingSave method build modal window, that’s shows only when my shipping method was selected. That new window will include new form with list of addresses
  2. After user selected address from dropdown list, that value well be stored in $_SESSION
  3. In html email directly read vale from $_session an write it to email

function onShippingSave(&$cart, &$methods, &$shipping_id, $warehouse_id = NULL){
		print '
			<div id="okonoinpost">
			<h2>Wybierz paczkomat</h2>
				
				<form id="wybierzpczkomatform" method="post">
				<select id="wybranypaczkomatlista" name="wybranypaczkomatlista">
				<option>Packzomat 1</option>
				<option>Packzomat 2</option>
				<option>Packzomat 3</option>
				</select>
				<input type="submit" value="Zapisz" id="zapiszprzycisk"/>
				</form>
				
			</div>';
}


Unfortunately I have two problems:
1. I don’t know how (or where) to put value form my form to $_SESSION, after form was submited. I try many of triggers, but none of them works.
2. onShippingSave method isn’t best solution. That show few times, also when I select different payment method. Maybe I should put my modal window (with form) in another trigger?

Thanks for Yours help.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 5 months ago #243007

Hi,

Yes, onShippingSave is indeed not ideal because of all the problems you mentioned.
I had expected that.
That's why I recommended you to use the checkout API which is more adapted to what you want to do:
www.hikashop.com/forum/development/88485...g-plugin.html#241811
I would recommend to use that.

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

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 5 months ago #243044

I don't want to use many steps in checkout, I'am using all in one view. Checkout API is working only on multisteps, so It will not work in my one page view?

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

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 5 months ago #243119

ok, I make workaround, useing checkout.php file. Everything almost works fine, but I can't chose my shipping plugin in payment plugin when I use restrictions in payment plugin (I don;t see my shipping plugin on dropdown list in restrictions of payment)

I try to use ups plugin, but It still don’t work. I see that $main -> shipping_params->methodsList is empty. What should I do?

Thank You for help

I Add dthis to my shipping plugin:

	var $inpost_methods = array(
		array('key' => '1', 'code'=>'1', 'name' => 'Ground', 'countries' => 'POLAND'),
		array('key' => '2', 'code'=>'2','name' => 'USA')

	);

		var $convertUnit=array(
		'kg' => 'KGS',
		'lb' => 'LBS',
		'cm' => 'CM',
		'in' => 'IN',
		'kg2' => 'kg',
		'lb2' => 'lb',
		'cm2' => 'cm',
		'in2' => 'in',
	);
	

	function shippingMethods(&$main) {
	
	//var_dump($main -> shipping_params->methodsList);
		$methods = array();
		if (!empty($main -> shipping_params -> methodsList)) {
			$main -> shipping_params -> methods = unserialize($main -> shipping_params -> methodsList);
		}
		if (!empty($main -> shipping_params -> methods)) {
			foreach ($main->shipping_params->methods as $key => $value) {
				$selected = null;
				foreach ($this->canpar_methods as $canpar) {
					if ($canpar['name'] == $key)
						$selected = $canpar;
				}
				if ($selected) {
					$methods[$main->shipping_id . '-' . $selected['key']] = $selected['name'];
				}
			}
		}
		return $methods;
	}

Last edit: 8 years 5 months ago by Bprak.

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
8 years 5 months ago #243147

Hi,

That line is wrong:
foreach ($this->canpar_methods as $canpar) {

it should be:
foreach ($this->inpost_methods as $canpar) {

Also, it requires that you have a setting to select the methods to use which is stored in the methodsList setting of your plugin.

The following user(s) said Thank You: Bprak

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

  • Posts: 36
  • Thank you received: 5
  • Hikashop Business
8 years 4 months ago #244072

Thank You for help, finally I do it differently. If someone, will be interested to integrate InPost services with HikaShop on their web side, you can send me a private message.

The following user(s) said Thank You: Jerome

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

Time to create page: 0.066 seconds
Powered by Kunena Forum