2016-04-07 16 views
0

Magento CE 1.9'da programsal olarak ürün için nasıl bir özellik oluşturabiliriz? Varsayılan olarak false olarak ayarlanmış ve Varsayılan özellik kümesi olarak atanmış, ancak herhangi bir yönetici paneli kullanıcısı tarafından görünür/düzenlenebilir olmayan bir boolean değerine sahip ürün için bir özellik oluşturmanın çeşitli yollarını deniyorum.Magento'da öznitelik oluşturma

benim Modeli/Kaynak/Eav/mysql4/Setup.php

<?php 

class Mofosys_Quickbuy_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup { 
protected function _prepareValues($attr) { 
    $data = parent::_prepareValues($attr); 
    $data = array_merge($data, array(

     'apply_to'      => $this->_getValue($attr, 'apply_to'), 
     'frontend_input_renderer'  => $this->_getValue($attr, 'input_renderer'), 
     'is_comparable'     => $this->_getValue($attr, 'comparable', 0), 
     'is_configurable'    => $this->_getValue($attr, 'is_configurable', 0), 
     'is_filterable'     => $this->_getValue($attr, 'filterable', 0), 
     'is_filterable_in_search'  => $this->_getValue($attr, 'filterable_in_search', 0), 
     'is_global'      => $this->_getValue(
      $attr, 
      'global', 
      Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL 
      ), 
     'is_html_allowed_on_front'  => $this->_getValue($attr, 'is_html_allowed_on_front', 0), 
     'is_searchable'     => $this->_getValue($attr, 'searchable', 0), 
     'is_used_for_promo_rules'  => $this->_getValue($attr, 'used_for_promo_rules', 0), 
     'is_visible'     => $this->_getValue($attr, 'visible', 0), 
     'is_visible_on_front'   => $this->_getValue($attr, 'visible_on_front', 0), 
     'is_wysiwyg_enabled'   => $this->_getValue($attr, 'wysiwyg_enabled', 0), 
     'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0), 
     'position'      => $this->_getValue($attr, 'position', 0), 
     'used_for_sort_by'    => $this->_getValue($attr, 'used_for_sort_by', 0), 
     'used_in_product_listing'  => $this->_getValue($attr, 'used_in_product_listing', 0), 
     )); 
    return $data; 
} 
} 

?> 

benim etc/Config.xml

<global> 
     <resources> 
      <mofosys_quickbuy_setup> 
       <setup> 
        <module>Mofosys_Quickbuy</module> 
       <class>Mofosys_Quickbuy_Model_Resource_Eav_Mysql4_Setup</class> 
       </setup> 
      </mofosys_quickbuy_setup> 
     </resources> 
    </global> 

benim sql/mofosys_quickbuy_setup/install-0.0.1.php

<?php 
// Installer file to create an attribute name "approved" inside Default attribute set 
$installer = $this; 
$setup = new Mage_Eav_Model_Entity_Setup('core_setup'); 
$installer->startSetup(); 


// the attribute added will be displayed under the group/tab Special Attributes in product edit page 
$setup->addAttribute('catalog_product', 'approved', array(
    'group'       =>   'Default', 
    'input'       =>   'select', 
    'type'       =>   'int', 
    'default'      =>   '0', 
    'label'       =>   'Testing', 
    'backend'      =>   '', 
    'visible'      =>   0, 
    'required'      =>   0, 
    'user_defined'     =>   0, 
    'searchable'     =>   0, 
    'filterable'     =>   0, 
    'comparable'     =>   0, 
    'visible_on_front'    =>   0, 
    'visible_in_advanced_search' =>   0, 
    'is_html_allowed_on_front'  =>   0, 
    'global'      =>   Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, 
)); 


$installer->endSetup(); 

?> 
+0

Kodunuzu buraya kadar gönderebilir misiniz? –

+0

Tüm özniteliğimi oluşturmak için tüm kodumu koydum –

cevap

1

Bunu deneyin, işe yarayacak, sadece benim için iyi çalıştı, sadece bu kodu install.php'ye koyun.

$installer = $this; 
$installer->startSetup(); 
// Set data: 
$attributeName = 'Approve'; // Name of the attribute 
$attributeCode = 'approve'; // Code of the attribute 
$attributeGroup = 'General';   // Group to add the attribute to 
$attributeSetIds = array(4);   // Array with attribute set ID's to add this attribute to. (ID:4 is the Default Attribute Set) 

// Configuration: 
$data = array(
    'type'  => 'select',  // Attribute type 
    'input'  => 'boolean',   // Input type 
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL, // Attribute scope 
    'required' => false,   // Is this attribute required? 
    'user_defined' => false, 
    'searchable' => false, 
    'filterable' => false, 
    'comparable' => false, 
    'visible_on_front' => false, 
    'unique' => false, 
    'used_in_product_listing' => true, 
    'default_value_yesno' => '0', 
    // Filled from above: 
    'label' => $attributeName 
); 

// Create attribute: 
// We create a new installer class here so we can also use this snippet in a non-EAV setup script. 
$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup'); 

$installer->addAttribute('catalog_product', $attributeCode, $data); 

// Add the attribute to the proper sets/groups: 
foreach($attributeSetIds as $attributeSetId) 
{ 
    $installer->addAttributeToGroup('catalog_product', $attributeSetId, $attributeGroup, $attributeCode); 
} 

$installer->endSetup();