Custom shipping method

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #196949

-- url of the page with the problem -- : -
-- HikaShop version -- : 2.4.0
-- Joomla version -- : 3.4.1
-- PHP version -- : 5.4.10
-- Browser(s) name and version -- : -

Hi,

i created a custom shipping method for some stuff i'm working on... and its fine in the backend of J3 but it doesn't show up in the front end...

Now i tried many things and read what you wrote on the page for custom plugins, but can't seem to get it to work.

Any help/idea would be greatly accepted to get it to work, so that i can implement the rest of the code in it.

Attachments:

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 7 months ago #196951

Hi,

The issue comes from the end of your shipping plugin class where you have these lines:

function onShippingDisplay(&$order,&$methods,&$usable_methods,&$messages){}
    function onShippingSave(&$order,&$methods,&$shipping_id){}
    function onShippingConfiguration(&$element){}
    function onShippingConfigurationSave(&$element){}
    //function shippingMethods(&$method){}
    function onAfterProcessShippings(&$usable_rates){}
these methods are defined in the parent class.
If you redefine them without any code and without calling the parent class's method then the code handling the shipping plugin in the parent class won't work and the plugin won't add itself to the list of available shipping methods.
If you don't need them, remove them and you'll see that it will be much better.
If you do, then add the necessary code in them.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #197320

ok i will test and return later if need more help then :)

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #197517

well i'm trying to get it display a list of places to ship the package based on the postal code of the shipping address..

i'm not having much luck doing anything at al... as soon as i start to use the function onShippingDisplay(&$order,&$methods,&$usable_methods,&$messages){

i can't get my shipping plugin to show up.... and as far as i have been able to see and deduct from the other shipping plugins, this i s what i need to do it with...

I like your cart alot, but this was so much easier to get to work on virtuemart than it is on here...

more documentation or help is really needed on making custom payment and shipping plugins
or at least an example shipping plugin with some advanced functions like there is for payment.

Last edit: 9 years 7 months ago by jesper.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 7 months ago #197523

Hi,

Do like this:

function onShippingDisplay(&$order,&$methods,&$usable_methods,&$messages){
 $return = parent::onShippingDisplay($order,$methods,$usable_methods,$messages);
 foreach($usable_methods as $key => $method){
  if($method->shipping_type == 'postdk'){
   $usable_methods[$key]->shipping_price = 100;
  }
 }
}
This example of the onShippingDisplay method will force the price of your shipping method to 100 and display it on the checkout.
I suppose that what you want to do is just to force that shipping_price value to whatever is necessary for postDK based on the user address and the product information and all that can be found in $order.

An example shipping plugin is indeed a good idea. We however didn't had the time to do that yet.
If you have more questions, just ask us and we'll answer you. When we get tired of it, we'll do the example plugin ;)

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #197574

Thanx that works... but i need to output a dropdown and some javacript and on choose of the dropdown set it as shipping address of the order

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

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #197596

Hello,

but i need to output a dropdown and some javacript and on choose of the dropdown set it as shipping address of the order

The displaying of your shipping methods won't be controlled by your plugin code, can you give me more details about what you exactly want to do through some screenshots for example ?

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #197665

My postservice has a webservice that can give the closest place to deliver package to, so when ppl choose this services for shipping, i need to select the place i want to pick up the parsel from.

if you understand what i mean

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

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #197676

If you have to display a list of delivery place to display, a solution can be to check the envoimoinscher shipping plugin where we display a list of pickup point just after selecting the good shipping method.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198366

I have gotten it to show me the list of places as individual shipping methods but how can i make this my shipping address for the item when i click on, so that is sets the items shipping adress to be the address i get of this item.

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

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #198378

Hello,

how can i make this my shipping address for the item when i click on, so that is sets the items shipping adress to be the address i get of this item.

I didn't totally understood what your issue is and you want to do, can you give me more details through some screenshots for example please ?
Thanks.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198493

The postal service in denmark has boxes setup at many different locations around the country to where, you can get your package delivered, so that you can pick it up, when you have the time.

Now i have gotten hika to get me a list of them out (seen screenshot)

Now when i click one of them and move on, i need to shop to put in the address info from that, as the shipping address of the order in order for the postal service to know, to where to delivere the package.

Attachments:

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

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
9 years 7 months ago #198530

Hi,

When you configure a shipping method, you have an option called "override shipping address".
www.hikashop.com/support/documentation/i...al-form.html#generic

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: jesper

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198654

Thanx, i will look at that and write back if more help is needed :)

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198846

Jerome it doesn't give me an option to put in a shipping address depending on the selection... thoose 5 have different addresses and are dynamicly fetched from a webservice.

I need to be able to dynamicly set a shipping address for the order.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198851

I'm also getting this error on change of shipping method
Fatal error: Call to a member function onShippingSave() on a non-object in components/com_hikashop/controllers/checkout.php on line 979

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

  • Posts: 12953
  • Thank you received: 1778
9 years 7 months ago #198862

Hello,
1.

Now when i click one of them and move on, i need to shop to put in the address info from that, as the shipping address of the order in order for the postal service to know, to where to delivere the package.

You should then check how we saved the pickup points on the order through the envoimoinscher shipping plugin.

2.
Your issue is probably coming from of your shipping plugin, here is more information about the onShippingSave function : www.hikashop.com/forum/2-general-talk-ab...-shipping-costs.html

Calculating shipping amounts on the fly shouldn't be complicated. All happens in the onShippingDisplay function. There you can just put your method in the $usableMethods array and in your method object, set the shipping_price based on whatever algorithm you need.
The onShippingSave method is called when the shipping method is selected by user on the checkout.
If the shipping method is auto selected by default and that the user does not select another shipping method, that method will indeed not be called at all during the checkout, and that's normal.

Last edit: 9 years 7 months ago by Mohamed Thelji.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198941

1: url for this ?

2: i have created a function like this

function onShippingSave(&$cart, &$methods, &$shipping_id, $warehouse_id = NULL) {
	//function onShippingSave(&$cart,&$methods,&$shipping_id){
		$usable_methods = array();
		$errors = array();
		$this->onShippingDisplay($cart,$methods,$usable_methods,$errors);
		$shipping_id = (int) $shipping_id;
		foreach($usable_methods as $k => $usable_method){
			if($usable_method->shipping_id==$shipping_id){
				return $usable_method;
			}
		}
		return false;
	}

But it still gives the error posted before.

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

  • Posts: 171
  • Thank you received: 4
9 years 7 months ago #198942

on 1 i found something on www.hikashop.com/support/documentation/2...imoinscher-form.html
but can this be used from other plugins, as i get this info dynamicly from a rss feed from my postal service

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
9 years 7 months ago #199009

Hi,

The shipping plugin envoimoinscher actually generate its own extra view on the checkout in order for the customer to select his pickup points and then add that extra data to the order.
While that is a possibility, it is much more complex than just generating several virtual shipping methods out of your main shipping method. Nevertheless, you can look at the plugin in the folder plugins/hikashopshipping/envoimoinscher if you want to check that out.

What I would recommend instead is to keep the solution you're using and just figure out a solution to that error.
Based on it, I can say that the problem comes from the way you initialize the virtual shipping methods in the onShippingDisplay method of your plugin, and more specifically the id of the shipping methods. The shipping id of each one should be unique, and should start with the name of the shipping plugin "postdk" in your case, followed by a - and then a unique identifier for the pickup point.
If the format you use for the shipping_id of your virtual shipping methods, the system won't be able to load the shipping plugin for the selected shipping method and the onShippingSave method call will fail during the checkout.

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

Time to create page: 0.114 seconds
Powered by Kunena Forum