0

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!

asked Apr 14, 2015 at 21:33

1 Answer 1

1

If I clearly understand you, we can reduce your question to following:

How to preselect any shipping method?

If yes - look here: change default shipping method on button click (ajax call) on checkout page

answered Apr 15, 2015 at 8:20
2
  • 1
    This is almost correct. I was looking for a solution without editing the template so that all my code lives in my extension. It looks like its not possible with PHP (in app/code) but with an extra Js file. Thanks for your help! Commented Apr 15, 2015 at 13:17
  • You are welcome Commented Apr 15, 2015 at 13:19

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.