Your carrier shipping object (Mage::getModel('vmr_shipping/carrier_customrate ');)
either returns false for the isTrackingAvailable
method, or can't be instantiated. The rest of this post will trace your method call above and give you multiple debug points. This should give you enough to solve the problem.
If we look at the definition for getCarriers
#File: app/code/core/Mage/Sales/Model/Order/Shipment/Api.php
public function getCarriers($orderIncrementId)
{
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIncrementId);
/**
* Check order existing
*/
if (!$order->getId()) {
$this->_fault('order_not_exists');
}
return $this->_getCarriers($order);
}
and follow that to _getCarriers
#File: app/code/core/Mage/Sales/Model/Order/Shipment/Api.php
protected function _getCarriers($object)
{
$carriers = array();
$carrierInstances = Mage::getSingleton('shipping/config')->getAllCarriers(
$object->getStoreId()
);
$carriers['custom'] = Mage::helper('sales')->__('Custom Value');
foreach ($carrierInstances as $code => $carrier) {
if ($carrier->isTrackingAvailable()) {
$carriers[$code] = $carrier->getConfigData('title');
}
}
return $carriers;
}
You can see the API method calls Mage::getSingleton('shipping/config')->getAllCarriers($store_id);
to get a list of carrier objects, and then only returns the ones where isTrackingAvailable
returns true. So step 1 should be to make sure your object returns true for this method.
Of course, it might be that getAllCarriers
never returns your method, and never has a chance to call it. Let's take a look at that method.
#File: app/code/core/Mage/Shipping/Model/Config.php
public function getAllCarriers($store = null)
{
$carriers = array();
$config = Mage::getStoreConfig('carriers', $store);
foreach ($config as $code => $carrierConfig) {
$model = $this->_getCarrier($code, $carrierConfig, $store);
if ($model) {
$carriers[$code] = $model;
}
}
return $carriers;
}
So this goes through all the top level carriers
configuration nodes. It looks like yours is setup correctly, but adding a
var_dump($code);
Mage::log($code);
to the above loop and looking for vmr_customrate
couldn't hurt. If you jump to this class's _getCarrier
method.
#File: app/code/core/Mage/Shipping/Model/Config.php
protected function _getCarrier($code, $config, $store = null)
{
if (!isset($config['model'])) {
return false;
}
$modelName = $config['model'];
/**
* Added protection from not existing models usage.
* Related with module uninstall process
*/
try {
$carrier = Mage::getModel($modelName);
} catch (Exception $e) {
Mage::logException($e);
return false;
}
$carrier->setId($code)->setStore($store);
self::$_carriers[$code] = $carrier;
return self::$_carriers[$code];
}
You'll see the carrier is instantiated by taking the value from the <model/
> node and using it in a call to getModel
$carrier = Mage::getModel('vmr_shipping/carrier_customrate');
It may be Magento can't instantiate your model for some reason. Check the exception log, or try instantiating the model yourself in a stand alone script/controller action.
maybe this will help you: https://github.com/thebod/Thebod_Shippingrates/blob/master/app/code/community/Thebod/Shippingrates/Model/Email.php (the code is pretty ugly, I wrote it 2-3 years ago).
Basically you need an observer on an event where you want to send out the mail(s).
To send the mails you can use the code from my extension, basically use a check like this:
if (strncmp($order->getShippingMethod(), 'shippingrates_', 14) != 0) {
return false;
}
to see if it matches your shipping rate. Then continue with sending the mail, use the store-emulation to avoid issues with the current store (e.g. if the order is placed somehow from the admin panel).
// Retrieve corresponding email template id and customer name, replace this code in case you use your own mail template
if ($order->getCustomerIsGuest()) {
$templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_GUEST_TEMPLATE, $storeId);
$customerName = $order->getBillingAddress()->getName();
} else {
$templateId = Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_TEMPLATE, $storeId);
$customerName = $order->getCustomerName();
}
// initialize the core mailer model and mail info model
$mailer = Mage::getModel('core/email_template_mailer');
$emailInfo = Mage::getModel('core/email_info');
// addTo($mailaddress) specifies the receiver(s) of the mail
$emailInfo->addTo($notificationMail);
$mailer->addEmailInfo($emailInfo);
// Set all required params and send emails
$mailer->setSender(Mage::getStoreConfig(Mage_Sales_Model_Order::XML_PATH_EMAIL_IDENTITY, $storeId));
$mailer->setStoreId($storeId);
$mailer->setTemplateId($templateId);
// the template params are used in the template file via {{var order.customer_name}}
$mailer->setTemplateParams(
array(
'order' => $order,
'billing' => $order->getBillingAddress(),
'payment_html' => $paymentBlockHtml
)
);
// send out the mail
$mailer->send();
I hope this helps.
Best Answer
You should set shipping method this way:
Check this answer for whole order creation