开发者

How do I add a logo on shipping option?

I cloned tablerate shipping method to have another option (fast courier). I checked everywhere on how can I add a logo when displaying shipping options.

What I did: in public function collectRates inside my shipping model I added

开发者_运维百科$method->setLogo( $this->getShipmentImageSrc('postaromana') );
$result->append($method);

So now I have the logo path, the problem is that I don't know how to call it. I supose the call is made in

/app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml

Any ideas how to solve this?


Solution for my question.

I share my solution in case anyone need it.

In app/code/core/Mage/Shipping/etc/system.xml add this on your new carrier

<logo>
    <label>Logo</label>
    <frontend_type>image</frontend_type>
    <backend_model>adminhtml/system_config_backend_image</backend_model>
    <upload_dir config="system/filesystem/media" scope_info="0">freeshippingtimisoara/logo</upload_dir>
    <base_url type="media" scoope_info="0">freeshippingtimisoara/logo</base_url>
    <sort_order>3</sort_order>
    <show_in_default>1</show_in_default>
    <show_in_website>1</show_in_website>
    <show_in_store>1</show_in_store>
</logo>

Add this function on carrier model from /app/code/core/Mage/Shipping/Model/Carrier

public function getShipmentImageSrc($shipping)
{
    $logo = $this->getConfigData('logo');
    $imageFilepath = DS . $shipping . DS . $_code . 'logo' . DS . $logo;
    if( file_exists(Mage::getBaseDir('media').$imageFilepath) ){
        return Mage::getBaseUrl('media').$imageFilepath;
    }
    return false;
}

Clone /app/code/core/Mage/Checkout/Block/Onepage/Shipping/Method/Available.php to local and add this function:

public function getCarrierLogo($carrierCode)
{
    if ($logo = Mage::getStoreConfig('carriers/'.$carrierCode.'/logo')) 
    {
        $carrierModel = Mage::getModel('shipping/carrier_' . $carrierCode);
        $logo = $carrierModel->getShipmentImageSrc($carrierCode);
        return $logo;
    }
    //$shippingModel = Mage::getModel('shipping/shipping');
    //$carrier = $shippingModel->getShipmentImageSrc($carrierCode);
    //Mage::helper('firephp')->debug( $carrier );
}

Use this in app/design/frontend/default/sex/template/checkout/onepage/shipping_method/available.phtml I have this file in my template, it's best to copy it to your template if you want to alter.

<?php if($this->getCarrierLogo($code)): ?>
    <span class="carrier-desc" style="margin:0 10px">
        <img src="<?php echo $this->getCarrierLogo($code) ?>" alt="<?php echo $_code; ?>" />
    </span>
<?php endif; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜