Skip to main content
2 of 2
deleted 5 characters in body
Balaji Kandasamy
  • 597
  • 1
  • 12
  • 33

I did the customer update section outside the Magento directory like this,

<?php
require_once ("../../app/Mage.php");
umask(0);
Mage::app();
Mage::app()->loadArea('frontend');
Mage::getSingleton('core/session', array('name' => 'frontend'));
$layout = Mage::getSingleton('core/layout');
$_SESSION[msg] = "";
if (isset($_POST['updateCustomer'])) {
    $customerId = $_POST['customerId'];
    $customer_email = $_POST['customerEmail'];
    $customer_fname = $_POST['customerFirstname'];
    $customer_lname = $_POST['customerLastname'];
    $customer_password = $_POST['customerPassword'];
    $shipping_id = $_POST['shippingId'];
    $shippingParent = $_POST['shippingParent'];
    $street = $_POST['shippingStreet'];
    $city = $_POST['shippingCity'];
    $postal = $_POST['shippingPostcode'];
    $telephone = $_POST['shippingTelephone'];
    $region = $_POST['shippingRegion'];
    $country = 'IN';
    $customer = Mage::getModel('customer/customer')->load($customerId);
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
    if ($customer->getId()) {
        $customer->setEmail($customer_email);
        $customer->setFirstname($customer_fname);
        $customer->setLastname($customer_lname);
        if ($customer_password != '') {
            $customer->setPassword($customer_password);
        }
        try {
            $customer->save();
            $customer->setConfirmation(null);
            $customer->save();
            $_SESSION['username'] = $customer_email;
            $_SESSION['firstname'] = $customer_fname;
            $_SESSION['first_order'] = "Y";
            $_SESSION['user_id'] = $customer->getId();
            $customer->sendNewAccountEmail();
        } catch (Exception $ex) {
            
        }
        $address = Mage::getModel("customer/address")->load($shipping_id);
        $address->setCustomerId($shippingParent)
                ->setShippingId($shipping_id)
                ->setFirstname($customer->getFirstname())
                ->setMiddleName($customer->getMiddlename())
                ->setLastname($customer->getLastname())
                ->setCountryId($country)
                ->setRegionId($region)
                ->setPostcode($postal)
                ->setCity($city)
                ->setTelephone($telephone)
                ->setStreet($street)
                ->setIsDefaultBilling('1')
                ->setIsDefaultShipping('1')
                ->setSaveInAddressBook('1');
        try {
            $address->save();
            $address->setConfirmation(null);
            $address->save();
        } catch (Exception $e) {
            
        }
    } else {
        echo "User does not exist";
    }
}

Form:

if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customer = Mage::getModel('customer/customer')->load(Mage::getSingleton('customer/session')->getId())->getData();
    $address = Mage::getModel("customer/address");
    $shipping = $address->load($customer['default_shipping'])->getData();
}
?>
<form action="" method="post" name="thisForm">
    <input type="hidden" name="customerId" id="customerId" value="<?= $customer['entity_id'] ?>" />
    <input type="text" name="customerEmail" id="customerEmail" value="<?= $customer['email'] ?>" />
    <input type="text" name="customerFirstname" id="customerFirstname" value="<?= $customer['firstname'] ?>" />
    <input type="text" name="customerLastname" id="customerLastname" value="<?= $customer['lastname'] ?>" />
    <input type="hidden" name="customerDefault_billing" id="customerDefault_billing" value="<?= $customer['default_billing'] ?>" />
    <input type="hidden" name="customerDefault_shipping" id="customerDefault_shipping" value="<?= $customer['default_shipping'] ?>" />
    <input type="hidden" name="shippingId" id="shippingId" value="<?= $shipping['entity_id'] ?>" />
    <input type="hidden" name="shippingParent" id="shippingParent" value="<?= $shipping['parent_id'] ?>" />
    <input type="hidden" name="shippingFirstname" id="shippingFirstname" value="<?= $shipping['firstname'] ?>" />
    <input type="hidden" name="shippingLastname" id="shippingLastname" value="<?= $shipping['lastname'] ?>" />
    <input type="text" name="shippingStreet" id="shippingStreet" value="<?= $shipping['street'] ?>" />
    <?php
    $collection = Mage::getModel('directory/region')->getResourceCollection()
                    ->addCountryFilter('IN')->load();
    ?>
    <select class="txtbox" name="shippingRegion" id="shippingRegion">
        <?php foreach ($collection as $region) { ?>
            <option value="<?= $region['region_id'] ?>" <?php if ($region['region_id'] == $shipping['region_id']) { ?> selected="selected" <?php } ?>><?= $region['name'] ?></option>
        <?php } ?>
    </select>
    <input type="text" name="shippingTelephone" id="shippingTelephone" value="<?= $shipping['telephone'] ?>" />
    <input type="text" name="shippingRegion" id="shippingRegion" value="<?= $shipping['region'] ?>" />
    <input type="text" name="shippingCity" id="shippingCity" value="<?= $shipping['city'] ?>" />
    <input type="text" name="shippingPostcode" id="shippingPostcode" value="<?= $shipping['postcode'] ?>" />
    <input type="text" name="shippingCountryId" id="shippingCountryId" value="<?= $shipping['country_id'] ?>" /> 
</form>
Balaji Kandasamy
  • 597
  • 1
  • 12
  • 33