Skip to content

Instantly share code, notes, and snippets.

@varinen
Last active May 25, 2018 07:22
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save varinen/6186371 to your computer and use it in GitHub Desktop.
Save varinen/6186371 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.
<?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();
}
@mano42023
Copy link

$product->save();
is not working

@Niroshan3
Copy link

Niroshan3 commented May 25, 2018

Anyone know how to programmatically create add to cart with custom option type file with params.?
Note problem in send file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment