Skip to main content

Shipping Plugin $usable_methods

More
9 years 10 months ago #256015 by c0untfl0yd
I am developing a shipping plugin for hikashop. The plugin makes requests to an API to determine price and all other parameters.

I need to have two methods in $usable_methods.

here is demo sample from my pluginName.php
Code:
<?php defined('_JEXEC') or die('Restricted access'); require_once __DIR__.'\$_include_functions.php'; ?> <?php class plgHikaShopshippingpluginName extends hikashopShippingPlugin { var $multiple = true; var $name = 'pluginName'; var $doc_form = 'pluginName'; var $use_cache = true; function onShippingDisplay(&$order,&$methods,&$usable_methods,&$messages){ $pluginName_methods_object = null; foreach($methods as $key => $value){ if($methods[$key]->shipping_name === "pluginName"){ $pluginName_methods_object = $methods[$key]; } } $pluginName_methods_object->shipping_price = 14; $pluginName_methods_object->shipping_params->yadiyadiyada2_api = "yadiyadiyada2"; $pluginName_methods_object->shipping_params->yadiyadiyada3_api = "yadiyadiyada3"; array_push($usable_methods,$pluginName_methods_object); //no problems here everything is displayed fine $new_method = $pluginName_methods_object; $new_method->shipping_id = 9199; $new_method->shipping_type = 'lalalala'; $new_method->shipping_name = 'lalalala1'; array_push($usable_methods, $new_method); // problem here
after the second array_push two shipping methods are displayed as expected. and also "Notice: Undefined offset: 1 in C:\Bitnami\wampstack-5.6.27-0\apache2\htdocs\joomla_1\administrator\components\com_hikashop\classes\shipping.php on line 394" is displayed. I need to have two methods in $usable_methods and no Notice. Any help would be appreciated.

An obvious solution would be to add a new shipping method of the "pluginName" type from the admin panel and everything would be ok. However this doesn't work for me.

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

More
9 years 10 months ago #256020 by Mohamed Thelji
Hello,

Note that in production mode you'll have to disable your error reporting, so no notice will be shown on your website.

Also, you should probably how we developped existing shipping plugins like USPS/UPS/... and instead, add available shipping services like this :
Code:
$usable_rates[$new_method->shipping_id] = $new_method;

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

More
9 years 10 months ago - 9 years 10 months ago #256296 by c0untfl0yd
Thank you for your response. I have done what you have asked and moved to your naming conventions as follows:
Code:
function onShippingDisplay(&$order,&$dbrates,&$usable_rates,&$messages)
, also i have changed the way I populate the $usable_rates array as follows:
Code:
$usable_rates[$new_method->shipping_id] = $new_method;

I have also red the documentation at Hikashop Documentation . However this doesn't resolve my issue, as I still need to display two shipping methods of the same type in my checkout process without having a duplicate shipping method in my "Administrator >> Components >> Hika Shop >> System >> Shipping Methods". While reading the UPS Plugin's code i think i need to use the shippingMethods(&$method) funtion to diplay some kind of dropdown options, or i could use onShippingSave(&$order,&$methods,&$shipping_id) function when the user selects his shipping method some kind of options are displayed, or I will need to implement warehouses. The reeson i need two visible methods or options for my shipping plugin is that the api i am calling has an option "Delivery to your door" or "Delivered to the closest Courier's office" and the prices for those options are different. Scince i am developing a plugin and not a single website i can't resolve the issue in any other way such as custom fields or the like.
Last edit: 9 years 10 months ago by c0untfl0yd.

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

More
9 years 10 months ago - 9 years 10 months ago #256300 by Mohamed Thelji
Hello,

Then in that case you should create 2 services for your shipping method. In the UPS shipping plugin, these services are also defined through the "$ups_methods" variable.

or I will need to implement warehouses.


Note that your shipping method will already support Warehouses by default without adding more code.
Last edit: 9 years 10 months ago by Mohamed Thelji.

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

More
9 years 10 months ago #256415 by c0untfl0yd
Can you give me some sort of example of using the variable properly
Code:
<?php class plgHikaShopshippingpluginName extends hikashopShippingPlugin { var $pluginName_methods = array();
to work with, please? And how to add them perhaps.

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

More
9 years 9 months ago #256424 by Mohamed Thelji
Hello,

About which variable are you talking about ?

The best solution will probably be to directly check the code and replicate the structure of the AuPost2 shipping method.

Also, note that you can directly check the "Shipping API" section of the developer documentation :
www.hikashop.com/support/documentation/6...tation.html#shipping
The following user(s) said Thank You: c0untfl0yd

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

More
9 years 9 months ago #256553 by c0untfl0yd
I am happy to inform you I have resolved my problem by first cloning the object and then pushing it to the usable rates array. The issue has to do with all object oriented languages not just php, and how objects are stored in the computer's ram. Thank you for your attention and support. :)

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

Time to create page: 0.202 seconds
Powered by Kunena Forum