News:

Support the VirtueMart project and become a member

Main Menu

Shipping Plugin Developpement

Started by kyrotomia, October 31, 2011, 16:11:17 PM

Previous topic - Next topic

kyrotomia

Hi,

I am currently developping a Canada Post shipping plugin for vm2. I'm basically trying to reproduce the one I found for vm 1.x, starting from scratch with the new hooks found in vm2.

I managed to get a good start from the currently existing weight_countries vmshipper plugin and the doc found at http://dev.virtuemart.net/projects/virtuemart/wiki/Shipper_Plugins

Now, I am stuck with some problems... Since Canada Post offers different shipping options, my plugins shows a list of available options to select, with their respective rates and details. Now, the only way I could make virtuemart detect the user has selected canadapost as a shipping option, is to insert a radio button like this :
<input type="radio" name="shipper_id" id="shipper_id_3" value="3">

I didn't find yet where that 3 comes from, but it works. When I do this, virtuemart detects the user has selected my plugin. However, how would I detect which option he has selected? If I use any other value than 3, virtuemart thinks my plugin was NOT selected as the shipping carrier.

I usually manage to succeed to do my stuff by simply reading the documentation... but this time, I'm stuck.

Thanks for your help.


kyrotomia

To make sure I'm understood correctly, maybe I can simplify my question :

How would I implement a shipping plugin which itself has multiple shipping options (example : Express, Expedited, Normal, etc.)?

alatak

Hi,

I did not update the wiki, because actually i prefer to comment correctly the function in the files. And then i would like to use phpdocumentor.

Look also to the file vmshipperplugin.php. The file is in components/com_virtuemart/helpers .
The function plgVmOnSelectShipper() returns an array . Each row is one of the shippper options.
The number 3 is actuallly the virtuemart_shippingcarrier_id, the key of the table  #__virtuemart_shippingcarriers.

May be  you do not even need to overwrite that function, you can use the default one.


Do not hesitate to ask questions. I will help you.


kyrotomia

Thank you for your follow up. I did read the full wiki as well as the comments included in vmshipperplugin prior to posting here.

The thing is , I am still lost... Since my initial posting, I managed to try out different ways. I understand plgVmOnSelectShipper() returns an array, but the documentation says 'HTML code to display the form'. This is somewhat too general in my opinion... I think this needs some clarification on what the html code should look like.

As I said earlier, it seems the radio button needs to have the value 3 for virtuemart to detect my plugin is the selected shipper. How would I then find out which option the user has choosen if the value has to be 3 for any option coming from my plugin?

The only workaround I found for now is to have my plugin display a radio button with the value 3, and display below that checkboxes with my custom data. The user needs to select the radio button AND a checkbox. I then couldn't find a way to keep the value of shipping in the cart object itself, so I had to use some setUserState / getUserState from the JApplication class... I understand this is not the way to go, but never found out how to do it the proper way.

Thank you for your time and support.

Maybe I can send you my working copy so you can see what I'm talking about?

alatak

#4
Hi,

The function plgVmOnSelectShipper() returns an array . Each row contains the HTML that displays the radio button.

The code for the radio button  is in the function getShippingHtml()

$html = '<input type="radio" name="shipper_id" id="shipper_id_' . $shipper->virtuemart_shippingcarrier_id . '" value="' . $shipper->virtuemart_shippingcarrier_id . '" ' . $checked . '>'
. '<label for="shipper_id_' . $shipper->virtuemart_shippingcarrier_id . '">' . $shipper->shipping_carrier_name . " (" . $shippingCostDisplay . ")</label>\n";


The code of the function plgVmOnSelectShipper (The file is in components/com_virtuemart/helpers/ vmshipperplugin.php)

public function plgVmOnSelectShipper(VirtueMartCart $cart, $selectedShipper = 0) {

if ($this->getShippers($cart->vendorId) === false) {
    return false;
}
$html = array();
foreach ($this->shippers as $shipper) {
    if ($this->checkShippingConditions($cart, $shipper)) {
$params = new JParameter($shipper->shipping_carrier_params);
$salesPrice = $this->calculateSalesPriceShipping($this->getShippingValue($params, $cart->pricesUnformatted), $this->getShippingTaxId($params));
$shipper->shipping_carrier_name = $this->getShippingName($shipper);

$html[] = $this->getShippingHtml($shipper, $selectedShipper, $salesPrice);
    }
}
return $html;
    }


The function getShippers() returns all the shippers created with your specific shipping plugin.
And then for each of them, it creates the html with the radio button.

In your case, if it works with the ID 3, it just means that you have create a shipping method that has the ID 3. But that number should be
the one from  the table $shipper->virtuemart_shippingcarrier_id

GooRu

Krytomania...

I am very much interested in a Canada Post shipping mod for VM2. How is it coming along, are you going to make it available?
Joomla Web Development, Hosting and site management

alatak

Hello Curt

Please send me some technical infos about Canada Post shipping .
If I develop it, it will be under a commercial licence. if you are interested, please PM me.

it_lux

Hi!
I installed VM2, and I was wondering to downgrade to VM1 to get back the Post Canada feature...  :-[
I would say I'm also interested by this module, under commercial licence or not, because of the VM2's look and feel... 8)
VM2 deserves to be known and it can't be without such kind of features.
Let me know if it starts, and what are the conditions! ;-)
If you always do what you've always done,
You'll always get what you've always got.

================================
La Saponnière Québécoise
http://www.saponniereqc.com

GJC Web Design

Did this get finished and is it available somewhere?

Thanks
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation