Tôi muốn thêm thuộc tính sản phẩm mới hiển thị danh sách thả xuống với tất cả các trang CMS làm tùy chọn của nó. Tôi đã tạo tiện ích mở rộng và muốn thêm thuộc tính này thông qua tập lệnh cài đặt. nhưng sau khi chạy này, Magento hỏng bảng eav_entity_type ...Magento: Thuộc tính sản phẩm tùy chỉnh để chọn trang CMS
gì tôi đã cố gắng cho đến nay:
MySQL4-cài đặt-0.1.0.php:
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();
$setup->addAttribute('catalog_product', 'test_report', array(
'label' => 'Test report',
'required' => false,
'input' => 'select',
'source' => 'cmspageselect/entity_source',
'default' => 'none',
'position' => 1,
'sort_order' => 3,
));
$installer->endSetup();
Nguồn cmspageselect/entity_source class:
class Mandarin_CMSPageSelect_Model_Source extends Mage_Eav_Model_Entity_Attribute_Source_Abstract {
/**
* Retrieve Full Option values array
*
* @param bool $withEmpty Add empty option to array
* @return array
*/
public function getAllOptions($withEmpty = true)
{
$storeId = $this->getAttribute()->getStoreId();
if (!is_array($this->_options)) {
$this->_options = array();
}
if (!isset($this->_options[$storeId])) {
$collection = Mage::getResourceModel('cms/page_collection')
->setPositionOrder('asc')
->setStoreFilter($this->getAttribute()->getStoreId())
->load();
$this->_options[$storeId] = $collection->toOptionIdArray();
}
$options = $this->_options[$storeId];
if ($withEmpty) {
array_unshift($options, array('label' => '', 'value' => ''));
}
return $options;
}
/**
* Get a text for option value
*
* @param string|integer $value
* @return string
*/
public function getOptionText($value)
{
$isMultiple = false;
if (strpos($value, ',')) {
$isMultiple = true;
$value = explode(',', $value);
}
$options = $this->getAllOptions(false);
if ($isMultiple) {
$values = array();
foreach ($options as $item) {
if (in_array($item['value'], $value)) {
$values[] = $item['label'];
}
}
return $values;
}
foreach ($options as $item) {
if ($item['value'] == $value) {
return $item['label'];
}
}
return false;
}
}
Như tôi đã nói, thay vì tạo thuộc tính mới "test_report", Magento chỉ làm hỏng eav_entity_type ta ble. Không có thông báo lỗi cũng như mục nhập nhật ký về những gì đã xảy ra.
Làm cách nào để tạo thuộc tính như vậy?
Cảm ơn, aeno
bạn có thể cung cấp mã nguồn cho lớp cmspageselect/entity_source không? –
Tôi đã chỉnh sửa câu hỏi để bao gồm nguồn – aeno
bạn xác định bảng bị hỏng như thế nào? –