How to update custom options programatically in magento?

后端 未结 3 1865
小蘑菇
小蘑菇 2020-12-15 14:59

I have lot of products with custom options, now I have requirement to update only custom options through csv file. so how we can do this programatically?

3条回答
  •  [愿得一人]
    2020-12-15 15:12

    Do you create a module to do that ? If you do, you must use the cron system of Magento and call a method of a custom model :

    
        
        
            
                
                    
                        0,15,30,45 * * * *
                    
                    
                        test/testmodel::testMethod
                    
                
            
        
    
    

    When this is done, you can update the option of a specific product by using the model Mage_Catalog_Model_Product_Option. I don't know how the CSV is made, but the algorithm can be something like that :

    // foreach option
    /** @var $opt Mage_Catalog_Model_Product_Option */
    $opt = Mage::getModel('catalog/product_option');
    $opt->setProduct($product);
    
    $optionArray = array(
        'is_delete' => 0,
        'title' => 'Blabla',
        'previous_group' => '',
        'previous_type' => '',
        'type' => 'field',  //can be radio, drop_down, file, area...
        'is_require' => 0,
        'sort_order' => 42,
        'values' => array()
    );
    
    $opt->addOption($optionArray);
    $opt->saveOptions();
    // end foreach
    

    Also check this link : http://subesh.com.np/2009/12/adding-custom-options-product-magento/

提交回复
热议问题