2

Want to fetch all Carrier Names in a .PHP file In a Core PHP file which is available in a inner folder of Magento,

For Ex. MagentoRootFolder/CorePHPFolder/File.php**

For Using Magento Code Externally I am using following Code :

<?php
require_once('../app/Mage.php'); //Path to Magento
umask(0);
Mage::app();
// extra code 
?>
<select>
    <?php 
        // **Here I need Code** to Get *All Shipping Carrier List*
    ?>
</select>
2
  • 1
    Can you please be more clear? What do you mean by the $this object. Do you want to use Magento core functionality? What have you tried so far?
    – Sander Mangel
    Mar 30, 2015 at 9:10
  • @Sander, Forget about $this, I want to get Courier List in a Core PHP file which is available in a inner folder of Magento, For Ex. MagentoRoot/CorePHPFolder/File.php
    – LuFFy
    Mar 30, 2015 at 9:20

3 Answers 3

2

Using the Mage_Shipping_Model_Config model you can get a list of active carriers, their code in Magento and the model used for that carrier.

Mage::getSingleton('shipping/config')->getActiveCarriers();

returns an array with the code as key, the model as value.

To get the name or any other System > Configuration value you could use the code

Mage::getStoreConfig("carriers/{$code}/title");
5
  • its providing following output : postimg.org/image/no8eiyzcn in print_r(Mage::getSingleton('shipping/config')->getActiveCarriers());
    – LuFFy
    Mar 30, 2015 at 9:32
  • yes, that is correct, it's an object
    – Sander Mangel
    Mar 30, 2015 at 9:34
  • But I am not seeing any courier name in it. :(
    – LuFFy
    Mar 30, 2015 at 9:36
  • You could use the code to retrieve the name field from the core_config_data table. Updated my answer
    – Sander Mangel
    Mar 30, 2015 at 9:43
  • Hmm alright, i try my efforts too.. :)
    – LuFFy
    Mar 30, 2015 at 9:48
3

If you are looking for all the carriers, use the below code for reference.

<code>
$carriersData = array();
$carriers = Mage::getsingleton("shipping/config")->getAllCarriers();
foreach($carriers as $code => $method){
    $carriersData[$code] = array(
        "title"     => Mage::getStoreConfig("carriers/$code/title"),
        "methods"   => $method->getMethods(),
     );
}
</code>

That will get you all the shipping modules, even if there are custom ones installed from other modules.

1

Robs answer is great, but if you just need the custom once like in my case then the following

$carriers = array();
$carrierInstances = Mage::getSingleton('shipping/config')->getAllCarriers();
$carriers['custom'] = Mage::helper('sales')->__('Custom Value');
foreach ($carrierInstances as $code => $carrier) {
    if ($carrier->isTrackingAvailable()) {
        $carriers[$code] = $carrier->getConfigData('title');
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.