Hello Nicolas, Mohamed Thelji, javierymirna
Thank you for your informations, I managed to do this with your help.
Here is what I've done :
" If a field is filled, then I can create an entry for that shipping method and its related rates/limits"
class plgHikaShopshippingMyfedex extends hikashopShippingPlugin
{
var $multiple = true;
var $name = 'myfedex';
var $doc_form = 'myfedex';
function onShippingDisplay(&$order,&$dbrates,&$usable_rates,&$messages){
if(!hikashop_loadUser())
return false;
$local_usable_rates = array();
$local_messages = array();
$ret = parent::onShippingDisplay($order, $dbrates, $local_usable_rates, $local_messages);
if($ret === false)
return false;
//dumpTrace();
//dumpTemplate($this);
//dump($order, 'ORDER');
//dump($dbrates, 'DBRATES');
//dump($usable_rates, 'USABLE RATES BEFORE');
//dump($local_usable_rates, 'LOCAL USABLE RATES');
//dump($order->billing_address->adress_fedexaccount, 'address fedex account');
if (trim($order->billing_address->adress_fedexaccount) != '') {
foreach ($local_usable_rates as $i => $rate) {
//load your custom field and check its value
$usable_rates[$rate->shipping_id] = $rate;
}
}
//dump($usable_rates, 'USABLE RATES AFTER');
}
}
- Install JDump is very usefull to understand how variables simple or complex are filled.
- I understood that $usable_rates is an array that contains an array of shipping limits/rates, and you can deal with to add the limits/rates for that shipping_id.
- $dbrates are the shipping methods available.
Anway, this works at 95%. Here is my test case :
- I have a customer with 2 billing addresses. One has the feded field filled, the other not. When I change billing address, Hikashop does not enter onShippingDisplay(). I believe another function is used.
BUT it's a very rare test case and can be managed offline. To hikashop : is this normal ? should it be a bug or not ?
Thank you