Ajout d'attributs dans magento à partir de l'extension - résolu
-
12-12-2019 - |
Question
j'essaie d'insérer quelques attributs (liste déroulante) dans le magento.La création de l'attribut avec option s'est terminée avec succès.Je crée également avec succès un ensemble d'attributs basé sur cet attribut.Le problème est que lorsque j'ajoute un produit basé sur cet ensemble d'attributs, le produit n'est pas visible sur le site Web.
Voici ma configuration pour l'attribut dropdown :
$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' => ''
);
--
j'ai remplacé le tableau ci-dessus par celui-ci :
$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' => ''
);
mais j'ai toujours le même problème.je pense qu'il me manque quelque chose ici.
La solution 3
Le tableau correct avec les attributs est le suivant:
$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'
);
Il semble que l'attribut "Backend_Type" soit défini sur "INT" pour configurer l'attribut tel qu'il devrait être.
merci
Autres conseils
Voici ce que j'ai utilisé récemment dans mon projet et je l'ai créé avec succès par programme.Je vois que ton apply_to
utilise un tableau, même si je pense que vous n'avez pas besoin de tableau et que vous pouvez transmettre plusieurs types de produits séparés par des virgules.
$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
Mise à jour - À afficher lors de l'utilisation du frontend visible_on_front
Si vous jetez un œil à /app/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)
va définir is_visible_on_front
depuis 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;
}
Essayez d'ajouter à votre option de tableau
array(
....
'visible_on_front' => 1,
....
)
Tu peux soit :
Supprimer et rajouter en utilisant
// Remove Product Attribute
$installer->removeAttribute(Mage_Catalog_Model_Product::ENTITY, 'product_attribute_code');
Ou mettre à jour
$installer->updateAttribute(Mage_Catalog_Model_Product::ENTITY, 'product_attribute_code', array(
'visible_on_front' => 1,
));
(en supposant que votre installateur soit de type 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>
Sinon, ajoutez dans votre fichier mysql4-install-*.php
<?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(...);