1

I am trying to save life time savings as customer attribute. After every successful purchase, I am incrementing the value.

To create the attribute I have below install script

<?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "life_time_total_saving",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Life Time Savings",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "life_time_total_saving");

$used_in_forms=array();

        $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 0)
        ->setData("sort_order", 100)
        ;
        $attribute->save();

$installer->endSetup();

config.xml:

<resources>
        <total_savings>
            <setup>
                <module>Ucs_Saving</module>
                <class>Mage_Sales_Model_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </total_savings>
    </resources>

After running this script, I can able to see attribute created in eav_attribute but in customer object I cant find the same.

below is my script inside mycustomer dashboard.phtml

$customerData = Mage::getSingleton('customer/session')->getCustomer();
echo '<pre>'; print_r($customerData);

But the object printed does not have the field life_time_total_saving.

Whats wrong with my code?

1

Please make sure is_visible field value 1

 ->setData("is_visible", 1)
  • I have written a upgrade script with is_visible field but its not working – Butterfly Jan 26 '16 at 15:22
  • Thanks for your help. Since no value stored for the user, it is no reflecting on customer object. +1 for your help – Butterfly Jan 26 '16 at 15:48
  • you are welcome – Amit Bera Jan 26 '16 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.