Skip to content

Instantly share code, notes, and snippets.

@magefast
Created January 19, 2022 17:35
Show Gist options
  • Save magefast/f11f8f2bb61556f6089796df26dd1e3d to your computer and use it in GitHub Desktop.
Save magefast/f11f8f2bb61556f6089796df26dd1e3d to your computer and use it in GitHub Desktop.

Revisions

  1. magefast created this gist Jan 19, 2022.
    32 changes: 32 additions & 0 deletions Add attribute to attribute set
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    <?php

    $locale = 'en_US';
    Mage::getSingleton('core/session')->setMyLang($langCode);
    $locale = Mage::getSingleton('core/session')->getMyLang();


    Mage::getSingleton('core/translate')->setLocale($locale)->init('frontend', true);

    $defaultStore = Mage::app()->getStore()->getCode();
    Mage::app()->setCurrentStore($defaultStore);
    Mage::app()->getLocale()->setLocale($locale);
    Mage::app()->getTranslator()->init('frontend', true);

    $entityType = Mage::getModel('catalog/product')->getResource()->getTypeId();
    $attributeSetCollection = Mage::getResourceModel('eav/entity_attribute_set_collection');
    $attributeSetCollection->setEntityTypeFilter($entityType);
    foreach ($attributeSetCollection as $attributeSet) {
    $name = $attributeSet->getAttributeSetName();
    $attributeSetId = $attributeSet->getId();
    addToAttributeSet('name_ukr', $name, 'Основна');
    echo '+<br>';
    }

    function addToAttributeSet($code, $attributeSetName = 'Default', $groupName = 'Details') {
    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
    $attributeSetId = $setup->getAttributeSetId('catalog_product', $attributeSetName);
    $attributeGroupId = $setup->getAttributeGroupId('catalog_product', $attributeSetId, $groupName);
    $attributeId = $setup->getAttributeId('catalog_product', $code);
    $setup->addAttributeToSet($entityTypeId = 'catalog_product', $attributeSetId, $attributeGroupId, $attributeId, 1);
    }