I created an extension to extend Magento with another shipping method. Actually I used this tutorial to do this. Only difference is that the shipping method only shows up if an item in cart is eligible for this method. So far it works. But now I want to pre select this shipping method. How can I do that? Unfortunately I couldn't find any information about it. The only option I'm seeing right now is to add the logic in the template. But I was wondering if it can't be set in the extenion (app/code/core/Mage/Shipping/Model/Carrier/Flatrate.php) itself.
<?php
class Creativ_Shipping_Model_Carrier_Oneitem_Extended_Flatrate1
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'extendedflatrate1';
protected $_isFixed = true;
public function collectRates(Mage_Shipping_Model_Rate_Request $request)
{
if (!$this->getConfigFlag('active')) {
return false;
}
$result = Mage::getModel('shipping/rate_result');
$items = $request->getAllItems();
$eligible = false;
foreach ($items as $item) {
if ($item->getProduct()->getInsuranceEligible(false)) {
$eligible = true;
break;
}
}
if ($eligible) {
$method = Mage::getModel('shipping/rate_result_method');
$method->setCarrier('extendedflatrate1');
$method->setCarrierTitle($this->getConfigData('title'));
$method->setMethod('oneitemflatrate1');
$method->setMethodTitle($this->getConfigData('name'));
$shippingPrice = $this->getConfigData('price');
$method->setPrice($shippingPrice);
$method->setCost($shippingPrice);
$result->append($method);
}
return $result;
}
public function getAllowedMethods()
{
return array('oneitemflatrate1' => $this->getConfigData('name'));
}
}
Thanks for any help!