Documente Academic
Documente Profesional
Documente Cultură
This simply means that you cannot configure the store to show the shipping method
at the admin side only.
How can we overcome this issue, and configure the shipping method to be shown
only
in
the
admin
area?
Simple!
You
will
need
to
rewrite
Mage_Shipping_Model_Config and Mage_Sales_Model_Quote_Address
Go to app/code/local/Mycompany/Myextension/etc/config.xml
<models>
<shipping>
<rewrite>
<config>Mycompany_Myextension_Model_Shipping_Config</config>
</rewrite>
</shipping>
<sales>
<rewrite>
<quote_address>Mycompany_Myextension_Model_Sales_Quote_Address</q
uote_address>
</rewrite>
</sales>
</models>
Configuring the shipping methods
Go to
app/code/local/Mycompany/Myextension/Model/Adminhtml/System/Config/Source/Sh
ipping/M
ethods
<?php
class
Mycompany_Myextension_Model_Adminhtml_System_Config_Source_Shipping_Meth
ods
{
protected $_options;
$carriersActive = Mage::getSingleton('shipping/config')->getActiveCarriers();
$carriersActive = array_keys($carriersActive);
if (!$this->_options) {
foreach ($carriers as $carrier) {
$carrierCode = $carrier->getId();
$carrierTitle = Mage::getStoreConfig('carriers/'.$carrierCode.'/title',
Mage::app()->getStore()->getId());
$carrierTitle = trim($carrierTitle);
if (empty($carrierTitle)) {
continue;
}
if (in_array($carrierCode, $carriersActive)) {
$carrierTitle = sprintf('%s (currently active)', $carrierTitle);
} else {
$options = $this->_options;
return $options;
}
}
The system.xml defines the file source_model
Go to app/code/local/Mycompany/Myextension/etc/system.xml
<fields>
<frontend_hidden_methods>
<label>Hide Shipping Methods on Frontend</label>
<comment><![CDATA[If a shipping method has been enabled under its
settings, you can choose to hide it on the frontend by selecting it here from the list.
This way, the shipping method would be available from the admin area but not from
the frontend.]]></comment>
<frontend_type>multiselect</frontend_type>
<source_model>mycompany_myextension/adminhtml_system_config_source_s
hipping_methods</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</frontend_hidden_methods>
</fields>
The actual config definition has been shown partially as part of the above code
Defining the helper data
Go to app/code/local/Mycompany/Myextension/Helper/Data.php. Paste the following
code here
<?php
class Mycompany_Myextension_Helper_Data extends Mage_Core_Helper_Abstract
{
const CONFIG_PATH_HIDE_FRONTEND_SHIPPING_METHODS = 'some-path-tosystem-xml-field';
extends
===
$carriersCodes = array_keys($carriers);
$hiddenShippingMethods = Mage::helper('mycompany_myextension')>getHiddenFrontendShippingMethods();
extends
$hiddenFrontendShippingMethods
=
Mage::helper('mycompany_myextension')->getHiddenFrontendShippingMethods();
$removeRates = array();
foreach ($this->_rates as $key => $rate) {
if (in_array($rate->getCarrier(), $hiddenFrontendShippingMethods)) {
$removeRates[] = $key;
}
}
foreach ($removeRates as $key) {
$this->_rates->removeItemByKey($key);
}
return $this->_rates;
}
}
With these rewrites, you have created a select option using which you can click on
methods that you want to display at the front end, and the ones that you want to
enable at the admin area. Do not confuse this hide from frontend method with
enable/disable for shipping methods.
Conclusion
With this method, you can hide certain shipping methods from the front end. With
this method in use, you can customize shipping methods such that you can display
certain methods on the frontend, while enable certain others only in the backend.
Author Bio:
Deepa is writer who loves writing blog on Magento Topic. In case if you are looking
for Magento Development Services and Magento Development in UK you may check
for getting the same at https://www.silvertouchtech.co.uk.