Domanda

Sto cercando di inserire alcuni attributi (a discesa) nel magento.La creazione dell'attributo con l'opzione è completata con successo.Creo anche un set di attributi in base a quell'attributo con successo. Il problema è che quando aggiungo un prodotto in base a quel set di attributi, il prodotto non è visibile sul sito web.

Ecco la mia configurazione per l'attributo a discesa:

    $data = array(
                    'is_global'                     => '1',
                    'frontend_input'                => 'select',
                    'default_value_text'            => '',
                    'default_value_yesno'           => '0',
                    'default_value_date'            => '',
                    'default_value_textarea'        => '',
                    'is_unique'                     => '0',
                    'is_required'                   => '1',
                    'frontend_class'                => '',
                    'is_searchable'                 => '0',
                    'is_visible_in_advanced_search' => '0',
                    'is_comparable'                 => '0',
                    'is_used_for_promo_rules'       => '0',
                    'is_html_allowed_on_front'      => '1',
                    'is_visible_on_front'           => '0',
                    'used_in_product_listing'       => '0',
                    'used_for_sort_by'              => '0',
                    'is_configurable'               => '1',
                    'is_filterable'                 => '0',
                    'is_filterable_in_search'       => '0',
                    'backend_type'                  => 'varchar',
                    'default_value'                 => '',
                    'option'                        => ''
                );
.

-

I 'VE ha cambiato l'array sopra in questo:

    $data = array(

                    'is_global'                     => true,
                    'frontend_input'                => 'select',
                    'is_required'                   => true,
                    'visible'                       => true,
                    'is_html_allowed_on_front'      => true,
                    'is_visible_on_front'           => true,
                    'is_configurable'               => true,
                    'is_filterable'                 => true,
                    'backend_type'                  => 'varchar',
                    'apply_to'                      => array('simple'),
                    'default_value'                 => '',
                    'position'                      => 1,
                    'visible_on_front'              => true,
                    'option'                        => ''
                );
.

Ma ho ancora lo stesso problema.Penso che mi manchi qualcosa qui.

È stato utile?

Soluzione 3

L'array corretto con gli attributi è il seguente:

    $data = array(

                    'is_global'                     => true,
                    'frontend_input'                => 'select',
                    'is_required'                   => true,
                    'visible'                       => true,
                    'is_html_allowed_on_front'      => true,
                    'is_visible_on_front'           => true,
                    'is_configurable'               => true,
                    'configurable'                  => true,
                    'is_configurableSpecified'      => true,
                    'is_visible_on_frontSpecified ' => true,
                    'is_filterable'                 => true,
                    'apply_to'                      => 'simple',
                    'default_value'                 => '',
                    'position'                      => 1,
                    'visible_on_front'              => true,
                    'option'                        => '',
                    'backend_type'                  => 'int'
                );
.

Sembra che l'attributo "backend_type" debba essere impostato su 'int' per configurare l'attributo come dovrebbe essere.

Grazie

Altri suggerimenti

Ecco cosa ho usato di recente nel mio progetto e lo ha creato con successo.Vedo che il tuo apply_to utilizza l'array, anche se penso che non sia necessario un array e può passare più tipi di prodotti separati da virgola.

$model = Mage::getResourceModel('catalog/setup','catalog_setup');

$data=array(
'type'=>'int',
'input'=>'boolean', //for Yes/No dropdown
'sort_order'=>50,
'label'=>'CUSTOM ATTRIBUTE CODE LABEL',
'global'=>Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
'required'=>'0',
'comparable'=>'0',
'searchable'=>'0',
'is_configurable'=>'1',
'user_defined'=>'1',
'visible_on_front' => 0, //want to show on frontend?
'visible_in_advanced_search' => 0,
'is_html_allowed_on_front' => 0,
'required'=> 0,
'unique'=>false,
'apply_to' => 'configurable', //simple,configurable,bundled,grouped,virtual,downloadable
'is_configurable' => false
);

$model->addAttribute('catalog_product','CUSTOM_ATTRIBUTE_CODE',$data);

$model->addAttributeToSet(
    'catalog_product', 'Default', 'General', 'CUSTOM_ATTRIBUTE_CODE'
); //Default = attribute set, General = attribute group
.

Aggiornamento - Per mostrare su Frontend Uso visible_on_front

Se dai un'occhiata a /pp/code/core/mage/catalog/model/resource/setup.php

/**
 * Add attribute to an entity type
 *
 * If attribute is system will add to all existing attribute sets
 *
 * @param string|integer $entityTypeId
 * @param string $code
 * @param array $attr
 * @return Mage_Eav_Model_Entity_Setup
 */
public function addAttribute($entityTypeId, $code, array $attr)
{
    $entityTypeId = $this->getEntityTypeId($entityTypeId);
    $data = array_merge(
        array(
            'entity_type_id' => $entityTypeId,
            'attribute_code' => $code
        ),
        $this->_prepareValues($attr)
     );
.

$this->_prepareValues($attr) impostare is_visible_on_front da visible_on_front

/**
 * Prepare catalog attribute values to save
 *
 * @param array $attr
 * @return array
 */
protected function _prepareValues($attr)
{
    $data = parent::_prepareValues($attr);
    $data = array_merge($data, array(
        'frontend_input_renderer'       => $this->_getValue($attr, 'input_renderer'),
        'is_global'                     => $this->_getValue(
            $attr,
            'global',
            Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
        ),
        'is_visible'                    => $this->_getValue($attr, 'visible', 1),
        'is_searchable'                 => $this->_getValue($attr, 'searchable', 0),
        'is_filterable'                 => $this->_getValue($attr, 'filterable', 0),
        'is_comparable'                 => $this->_getValue($attr, 'comparable', 0),
  --->  'is_visible_on_front'           => $this->_getValue($attr, 'visible_on_front', 0),
        'is_wysiwyg_enabled'            => $this->_getValue($attr, 'wysiwyg_enabled', 0),
        'is_html_allowed_on_front'      => $this->_getValue($attr, 'is_html_allowed_on_front', 0),
        'is_visible_in_advanced_search' => $this->_getValue($attr, 'visible_in_advanced_search', 0),
        'is_filterable_in_search'       => $this->_getValue($attr, 'filterable_in_search', 0),
        'used_in_product_listing'       => $this->_getValue($attr, 'used_in_product_listing', 0),
        'used_for_sort_by'              => $this->_getValue($attr, 'used_for_sort_by', 0),
        'apply_to'                      => $this->_getValue($attr, 'apply_to'),
        'position'                      => $this->_getValue($attr, 'position', 0),
        'is_configurable'               => $this->_getValue($attr, 'is_configurable', 1),
        'is_used_for_promo_rules'       => $this->_getValue($attr, 'used_for_promo_rules', 0)
    ));
    return $data;
}
.

Prova ad aggiungere all'opzione Array

 array(
  ....  
    'visible_on_front'  => 1,
  ....
 )
.

Puoi:

Rimuovi e riaggiunta usando

// Remove Product Attribute
$installer->removeAttribute(Mage_Catalog_Model_Product::ENTITY, 'product_attribute_code');
.

o AGGIORNAMENTO

$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'product_attribute_code', array(
    'visible_on_front'  => 1,
));
.

(supponendo che il tuo programma di installazione sia di tipo mage_catalog_model_resource_setup)

<?xml version="1.0"?>
<config>
 .....
    <models>
      <attr>
        <class>MagePal_Attr_Model</class>
        <resourceModel>attr_mysql4</resourceModel>
      </attr>
    </models>
    <resources>
      <productattr_setup>
        <setup>
          <module>MagePal_Attr</module>
          <class>Mage_Catalog_Model_Resource_Setup</class>
        </setup>
        .......
    </resources>
  </global>
</config> 
.

In caso contrario, quindi nel tuo file MySQL4-INSTALL - *. File PHP Aggiungi

<?php

$installer = $this;

$installer->startSetup();
$setup = new Mage_Catalog_Model_Resource_Setup('core_setup');
//$setup->removeAttribute(Mage_Catalog_Model_Product::ENTITY, 'product_attribute_code');
$setup->addAttribute(...);
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top