Disabling “Same as Billing Address” Checkbox in Magento 1.5
If you’re running Magento 1.5 and want to disable the pre-checked “Same as Billing Address” option during the re-order process, follow these steps:
Step 1: Understand the Default Behavior
By default, when you view a completed order and click on “Re-Order”, Magento automatically selects the “Same as Billing Address” checkbox for the shipping address. This is controlled by the Mage_Core_Block_Abstract class.
Step 2: Identify the Relevant Code
The relevant code responsible for this behavior can be found in the file /app/code/core/Mage/Core/Block/Abstract.php:
public function getShippingAddressHtmlSelect()
{
$options = array();
$options[0] = Mage::helper('core')->__('Same as billing address');
return $this->_toHtmlSelect($options, 'shipping_address_id', false);
}
Step 3: Create a Custom Block
To override this behavior without modifying core files (which is generally a bad practice), we’ll create a custom block extending Mage_Core_Block_Abstract.
In your local Magento installation, navigate to /app/code/local/Magento/Reorder/Blocks and create the following file: Abstract.php. Add the following code:
class Mage_Reorder_Block_Abstract extends Mage_Core_Block_Abstract
{
public function getShippingAddressHtmlSelect()
{
$options = array();
return $this->_toHtmlSelect($options, 'shipping_address_id', true);
}
}
Note: We’re changing the third parameter of _toHtmlSelect from false to true, which disables the pre-selected option.
Step 4: Update the Reorder Controller
Next, we need to update the reorder controller to use our custom block. Navigate to /app/code/core/Mage/Checkout/controllers/OrderController.php:
Locate the line where the shipping address is rendered:
$this->getLayout()->createBlock('core/template')->setTemplate('checkout/onepage/reorder/shipping.phtml');
Replace it with this code:
$this->getLayout()->createBlock('reorder/abstract', 'shipping_address_block')->setTemplate('checkout/onepage/reorder/shipping.phtml');
Step 5: Clear Cache and Test
Finally, clear your Magento cache (System > Cache Management > Refresh) and test the re-order process on a completed order.
When you click “Re-Order”, you’ll notice that the “Same as Billing Address” checkbox is now unchecked and disabled by default. You can manually select an alternative shipping address if needed.
Conclusion
Disabling pre-selected options in Magento often involves creating custom blocks to override core functionality without directly modifying core files. This approach ensures your changes remain valid even after updating your Magento version.
Remember, always backup your code before making any changes and thoroughly test the functionality after implementation.
For more advanced customizations like this, consider reaching out to professional Magento developers at Laravel Company, who can provide expert guidance tailored to your specific needs.