Tôi cài đặt thuộc tính với đoạn script sau:
$installer = $this;
$installer->startSetup();
$installer->removeAttribute('catalog_product', 'customizableonly');
$installer->addAttribute('catalog_product', 'customizableonly', array(
'group' => 'General',
'input' => 'select',
'type' => 'int',
'label' => 'Customizable Only',
'source' => 'eav/entity_attribute_source_boolean',
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'visible' => 1,
'required' => 0,
'visible_on_front' => 0,
'is_html_allowed_on_front' => 0,
'is_configurable' => 0,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'unique' => false,
'user_defined' => false,
'default' => 0,
'is_user_defined' => false,
'used_in_product_listing' => true
));
$this->endSetup();
Cũng đã thử với $installer = new Mage_Catalog_Model_Resource_Eav_Mysql4_Setup('core_setup');
Và sau đó tôi đang sử dụng giá trị của thuộc tính trong một số mã khác. Nhưng tôi luôn luôn nhận được null. Tôi phát hiện ra rằng, thuộc tính không được đặt giá trị mặc định. Khi tôi mở một sản phẩm - trình đơn thả xuống hiển thị No, nhưng khi tôi nhận được giá trị của nó trong mã thì nó null. Nếu tôi chỉ cần nhấp vào menu thả xuống, chỉ cần đặt Novà lưu sản phẩm - mọi thứ đều hoạt động.
Làm thế nào để khắc phục điều này?