In the template app/design/frontend/base/default/template/customer/address/edit.phtml
you can see at the bottom there are two input items one for default shipping and one for default billing addresses.
<li<?php if($this->canSetAsDefaultShipping()) echo ' class="control"' ?>>
<?php if($this->isDefaultShipping()): ?>
<strong><?php echo $this->__('Default Shipping Address') ?></strong>
<?php elseif($this->canSetAsDefaultShipping()): ?>
<input type="checkbox" id="primary_shipping" name="default_shipping" value="1" title="<?php echo $this->__('Use as My Default Shipping Address') ?>" class="checkbox" /><label for="primary_shipping"><?php echo $this->__('Use as my default shipping address') ?></label>
<?php else: ?>
<input type="hidden" name="default_shipping" value="1" />
<?php endif; ?>
</li>
What I would suggest is that you have two options.
- Override the template used via layout xml and then simply remove this part from your new template.
- Override the block so that the function
canSetAsDefaultShipping
always returns false.
Personally I would choose the template way at the moment as template changes feel easier to me.
If you have a sample layout xml the following snippet should work.
<customer_address_form>
<reference name="customer_address_edit">
<action method="setTemplate"><template>your/path/to/template.phtml</template></action>
</reference>
</customer_address_form>
It's just part of Magento's architecture to use a first name and a last name.
Your question asks why this is the case. Presumably, Magento has added the firstname
and lastname
attributes (along with even an optional middlename
one is defined as default but not displayed) to provide as much flexibility as possible for the merchant. This is a departure from other more established sites, as you noted, but Magento has to cater for a range of possible merchants, and tries to be as non-specific as possible.
However, like all of Magento, nothing is set in stone, and it can be changed, however this is a coding exercise, and as a result can be quite a complicated procedure. To enable this, you'd need to do a few different things. I'll try and detail the steps I'd take below.
1. Add Full Name Attribute
The full name needs to be added as an attribute to a customer. You can create a module to handle this, but essentially, you'll need to run an installer script to install fullname
as an attribute against the customer attribute set.
There are lots of useful tutorials about this around the web. Excellence Magento has a great one (code partially shown below, edited to your requirements)
$setup->addAttribute('customer', 'fullname', array(
'type' => 'text',
'input' => 'text',
'label' => 'Full Name',
'global' => 1,
'visible' => 1,
'required' => 1,
'user_defined' => 1,
'default' => '0',
'visible_on_front' => 1
));
2. Add your new attribute in your templates
You'd now need to go through and add the field for your new attribute to all relevant templates; thereby allowing the user input of it.
You can remove the First Name and Last Name fields in the process, wherever they are applicable.
3. Adjust the firstname and lastname attributes
First Name and Last Name are required attributes in the database, so you won't be able to do much until you remove their required
status from the attributes themselves.
You'll need to write a single-use script to adjust the settings; the code should resemble the following:
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','firstname');
if ($attributeId) {
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attribute->setIsRequired(false)->save();
}
$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('customer','lastname');
if ($attributeId) {
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attribute->setIsRequired(false)->save();
}
After that, you should have successfully transferred firstname
and lastname
into a single fullname
field.
If you have any existing customers, you'll be able to write a script that will combine the firstname
and lastname
fields into the fullname
one.
Best Answer
Disclaimer: Please make a backup of your database and/or test on a copy before trying out the query!
To set the first found customer address as default shipping address, use
Then repeat with
'default_shipping'
replaced by'default_billing'
in both places.This will probably set the same address as default for both but since it is an arbitrary choice anyway I did not go the extra mile to write a second query that compares the address against the assigned shipping address.
Updated with tested query