Forked from varinen/file_custom_option_script.php
Created
September 25, 2015 09:48
-
-
Save shaibon/f276302534f69224d593 to your computer and use it in GitHub Desktop.
Dynamically adding a file type custom option to multiple products (IDs 100, 101, and 102) in Magento.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'app/Mage.php'; | |
| Mage::app('default'); | |
| $productIds = array(100, 101, 102); | |
| $option = array( | |
| 'title' => 'Test Option', | |
| 'type' => 'file', | |
| 'is_require' => 1, | |
| 'price' => 10, | |
| 'price_type' => 'fixed', | |
| 'sku' => 'testsku', | |
| 'file_extension' => 'png,jpg', | |
| 'image_size_x' => '100', | |
| 'image_size_y' => '200' | |
| ); | |
| foreach ($productIds as $productId) { | |
| $product = Mage::getModel('catalog/product')->load($productId); | |
| $optionInstance = $product->getOptionInstance()->unsetOptions(); | |
| $product->setHasOptions(1); | |
| if (isset($option['is_require']) && ($option['is_require'] == 1)) { | |
| $product->setRequiredOptions(1); | |
| } | |
| $optionInstance->addOption($option); | |
| $optionInstance->setProduct($product); | |
| $product->save(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment