Search

Aug 11, 2015

Create custom attribute in magento

Lưu ý: tên biến không được có số app/local/customerAttribute/sql/custom_setup/mysql4-install-0.1.0.php
$installer->addAttribute("customer", "fix_state_issued_by",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "State Issued By",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "fix_state_issued_by");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$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", 1)
->setData("sort_order", 100)
;
$attribute->save();
 
 
 

$installer->addAttribute("customer", "fix_resale_expired",  array(
    "type"     => "datetime",
    "backend"  => "eav/entity_attribute_backend_datetime",
    "label"    => "Expiration Date",
    "input"    => "date",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

));

$attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "fix_resale_expired");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
$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", 1)
->setData("sort_order", 100)
;
$attribute->save();

Aug 10, 2015

Get Custom Attribute in Magento


<?php 

$_product= Mage::getSingleton('catalog/product')->load($_item->getProductId());
echo $_product->getResource()->getAttribute('attributeCode')->getFrontend()->getValue($_product);
        
$product->getData("attributeCode");
$product->getAttributeText("attributeCode");

?>