1

I have written a script to create attribute set and attribute from csv and it worked fine on my localhost but after uploading it to server I found that it is taking so much time to do the job even with 1 entry. So I was debugging it and I found out that "initFromSkeleton" is taking time.

$entityTypeId = Mage::getModel('eav/entity')
                ->setType('catalog_product')
                ->getTypeId(); // 4 - Default 

$newSet = Mage::getModel('eav/entity_attribute_set');
$newSet->setEntityTypeId($entityTypeId);
$newSet->setAttributeSetName($setName);
$newSet->save();

$newSet->initFromSkeleton($entityTypeId);
$newSet->save();

I don't know what to do because to build new attribute based on default attribute set I have to write this initFromSkeleton. While searching google I found this link. But it understood from there.

Could any one has done this before. Please help me out. Thanks in advance

2 Answers 2

2

initFromSkeleton builds an attribute set based on another attribute set. It probably takes so much time because that other attribute set is so big (i.e. has many attributes in it). If you take a really simple initFromSkeleton it might take less time.

In your case you also use wrong code. You call initFromSkeleton with an entity type id, but that's not how it works. You need to call it with an attribute set id which specifies the 'parent' attribute set from which it is built.

I'd suggest find the attribute set id of the default or the simplest attribute set you have and give that as parameter to initFromSkeleton.

0

This is a really "fun" Magento problem. If you’re using the initFromSkeleton method, take note that calling "$newAttributeSet->save();" before executing initFromSkeleton is the correct process... However you have to look up the default attribute set for the entity type... I detailed the process in the blog post below in-case anyone is having a similar problem! I've also included the code you're missing.

Building a new attribute set in Magento - Programatically

     $templateAttributeSet = $this->_getDefaultAttributeSet();
      $newAttributeSet->initFromSkeleton($templateAttributeSet->getId());

protected function _getDefaultAttributeSet()
    {
        $entityTypeId = Mage::getModel('eav/entity')->setType('catalog_product')->getTypeId();
        $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection')
            ->setEntityTypeFilter($entityTypeId)
            ->addFilter('attribute_set_name', 'Default');

        if ($attributeSetCollection->count() > 0) {
            $response = $attributeSetCollection->getFirstItem();
        } else {
            $response = FALSE;
        }
        return $response;
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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