Like in the title, i want to make custom shipping method which will appears only for the logged users.
I had reward points module, and i wanna make a "FreeShipping for Points" you can use the reward points only if you are logged in user so the shipping for points option have to be available only for logged users.
I already made custom shipping method based on http://code.tutsplus.com/tutorials/create-a-custom-shipping-method-in-magento--cms-23747.
<?php
// app/code/local/Envato/Customshippingmethod/Model
class Envato_Customshippingmethod_Model_Demo
extends Mage_Shipping_Model_Carrier_Abstract
implements Mage_Shipping_Model_Carrier_Interface
{
protected $_code = 'envato_customshippingmethod';
public function collectRates($carrierCode, $request)
{
if (!$this->_isAvailable($carrierCode, $request)) {
return $this;
}
return parent::collectCarrierRates($carrierCode, $request);
}
public function getAllowedMethods()
{
return array(
'envato_customshippingmethod' => $this->getConfigData('name'),
);
}
protected function _isAvailable($carrierCode, $request)
{
$regionCode = $request->getDestRegionCode();
switch ($carrierCode) {
case 'envato_customshippingmethod':
if (!Mage::getSingleton('customer/session')->isLoggedIn()) {
return false;
}
break;
}
return true;
}
protected function _getDefaultRate()
{
$rate = Mage::getModel('shipping/rate_result_method');
$rate->setCarrier($this->_code);
$rate->setCarrierTitle($this->getConfigData('title'));
$rate->setMethod($this->_code);
$rate->setMethodTitle($this->getConfigData('name'));
$rate->setPrice($this->getConfigData('price'));
$rate->setCost(0);
return $rate;
}
}
?>