Skip to content

Instantly share code, notes, and snippets.

@magefast
Created February 5, 2024 09:20
Show Gist options
  • Save magefast/722f4aceada7a149aedf58dca48136c4 to your computer and use it in GitHub Desktop.
Save magefast/722f4aceada7a149aedf58dca48136c4 to your computer and use it in GitHub Desktop.

Revisions

  1. magefast created this gist Feb 5, 2024.
    40 changes: 40 additions & 0 deletions UpdateAttributeOptionStoreLabel.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    <pre>
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ini_set('time_limit', 180);
    set_time_limit(180);
    require_once dirname(__FILE__) . '/app/Mage.php';
    $app = Mage::app('admin');
    umask(0);

    $mageCsv = new Varien_File_Csv();
    $mageCsv->setDelimiter(',');
    $mageCsv->setEnclosure('"');
    $data = $mageCsv->getData('/var/www/' . DS . 'options-label-ua.csv');
    unset($data[0]);
    foreach ($data as $d) {
    echo '+' . $d[0] . ' ';
    updateOptionToAttribute($d[1], $d[3], $d[4], $d[2]);
    }


    function updateOptionToAttribute($attributeId, $valueAdmin, $valueUA, $valueId)
    {
    $valueUA = trim($valueUA);
    $uaStoreId = 5;
    $ruStoreId = 1;
    $adminStoreId = 0;

    $option = array();
    $option['attribute_id'] = $attributeId;
    $option['value'][$valueId] = [
    $adminStoreId => $valueAdmin,
    $uaStoreId => $valueUA,
    $ruStoreId => $valueAdmin
    ];

    $setup = new Mage_Eav_Model_Entity_Setup('core_setup');
    $setup->addAttributeOption($option);
    unset($setup);
    }