For this we can update custome options programaticallyfor alla products at a time :)
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');
$option = array(
'title' => 'custom option title',
'type' => 'drop_down', // could be drop_down ,checkbox , multiple
'is_require' => 1,
'sort_order' => 0,
'values' => getOptions()
);
$collection = Mage::getModel('catalog/product');
$product_id = $collection->getIdBySku('Ac-43SS');
$product = $collection->load($product_id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
$product->save();
echo $sku;
function getOptions() {
return array(
array(
'title' => 'Ship It',
'price' => 0,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '0'
),
array(
'title' => 'Avon',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '1'
),
array(
'title' => 'Bristol',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '2'
),
array(
'title' => 'Barkhamstead',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '3'
),
array(
'title' => 'Burlington',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '4'
),
array(
'title' => 'Canton',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '5'
),
array(
'title' => 'East Granby',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '6'
),
array(
'title' => 'East Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '7'
),
array(
'title' => 'Farmington',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '8'
),
array(
'title' => 'Granby',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '9'
),
array(
'title' => 'Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '10'
),
array(
'title' => 'New Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '11'
),
array(
'title' => 'North Granby',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '12'
),
array(
'title' => 'Simsbury',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '13'
),
array(
'title' => 'Torrington',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '14'
),
array(
'title' => 'West Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '15'
),
array(
'title' => 'West Simsbury',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '16'
)
);
}
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');
$option = array(
'title' => 'custom option title',
'type' => 'drop_down', // could be drop_down ,checkbox , multiple
'is_require' => 1,
'sort_order' => 0,
'values' => getOptions()
);
$collection = Mage::getModel('catalog/product');
$product_id = $collection->getIdBySku('Ac-43SS');
$product = $collection->load($product_id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
$product->save();
echo $sku;
function getOptions() {
return array(
array(
'title' => 'Ship It',
'price' => 0,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '0'
),
array(
'title' => 'Avon',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '1'
),
array(
'title' => 'Bristol',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '2'
),
array(
'title' => 'Barkhamstead',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '3'
),
array(
'title' => 'Burlington',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '4'
),
array(
'title' => 'Canton',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '5'
),
array(
'title' => 'East Granby',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '6'
),
array(
'title' => 'East Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '7'
),
array(
'title' => 'Farmington',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '8'
),
array(
'title' => 'Granby',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '9'
),
array(
'title' => 'Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '10'
),
array(
'title' => 'New Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '11'
),
array(
'title' => 'North Granby',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '12'
),
array(
'title' => 'Simsbury',
'price' => -5.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '13'
),
array(
'title' => 'Torrington',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '14'
),
array(
'title' => 'West Hartford',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '15'
),
array(
'title' => 'West Simsbury',
'price' => -3.00,
'price_type' => 'fixed',
'sku' => $sku,
'sort_order' => '16'
)
);
}
Comments
Post a Comment