Take the 2-minute tour ×
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It's 100% free, no registration required.

Scenario: I have created a new product type (configurable_b), that extends the configurable product type.

The issue is that when I edit the product in the backend I cannot see many attributes.

The reason are:

  • Many attribute are assigned specifically to configurable so I need to manually assign them to the configurable_b type.
  • Even if the attribute is assigned to all product types, I need to save the attribute to display in my new configurable_b

Any way to fix this programmatically ?

Cycle on every attribute:

  • assign it to configurable_b if they are assigned to configurable
  • fix the issue with the attribute assigned to all product type

NOTE
I will accept also info that help me to create a script by myself, what I really miss is where the association to product type/attribute (apply_to) is stored in DB

Thansk

share|improve this question

1 Answer 1

up vote 6 down vote accepted

I assume you created a module to support your new product type.
You should write an install/upgrade script for your module that changes the apply_to of the attributes you need to be available for your product type also.
Make an array with all the attributes you need and run this script:

<?php

/* @var $installer Mage_Eav_Model_Entity_Setup*/
$installer = $this;

$installer->startSetup();
$newType =  'configurable_b';

$attributes = Mage::getResourceModel('catalog/product_attribute_collection')
    ->getItems();

foreach ($attributes as $attribute) {
    $applyTo = explode(',', $installer->getAttribute('catalog_product', $attribute->getAttributeCode(), 'apply_to'));

    if ( in_array('configurable', $applyTo) && !in_array($newType, $applyTo)) {
        $applyTo[] = $newType;
        $installer->updateAttribute('catalog_product', $attribute->getAttributeCode(), 'apply_to', join(',', $applyTo));
    }
}

$installer->endSetup();

NOTE:
The installer class need to be Mage_Eav_Model_Entity_Setup or a derivate

share|improve this answer
    
thanks, that is exactly what I need –  Fra Aug 7 at 7:54
    
@Fra. You may want to make the installer be an instance of Mage_Catalog_Model_Resource_Setup instead of Mage_Core_Model_Resource_Setup . The core one does not have the method updateAttribute. Or make it at least Mage_Eav_Model_Entity_Setup –  Marius Aug 7 at 8:12
    
got It I have added the info to your answer as well, thanks –  Fra Aug 7 at 9:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.