-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-option.php
More file actions
88 lines (74 loc) · 2.29 KB
/
custom-option.php
File metadata and controls
88 lines (74 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');
// If your database is having lots of data then use set_time_limit / ini_set
//set_time_limit(0);
//ini_set('memory_limit','1024M');
$option1 = array(
'title' => 'Customization',
'type' => 'checkbox', // could be drop_down ,checkbox , multiple
'is_require' => 0,
'sort_order' => 0,
'values' => getOption1()
);
$option2 = array(
'title' => 'Customization Details',
'type' => 'radio', // could be drop_down ,checkbox , multiple
'is_require' => 1,
'sort_order' => 0,
'values' => getOption2()
);
$sku ="";
$product_id = Mage::getModel('catalog/product')->getIdBySku($sku);
$product = Mage::getModel('catalog/product')->load($product_id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
//Do not forget to save the product
$product->save();
echo "Done";
/*
$collection = Mage::getModel('catalog/product')->getCollection();
foreach ($collection as $product_all) {
$sku = $product_all['sku'];
// retrieve product id using sku
$product_id = Mage::getModel('catalog/product')->getIdBySku($sku);
//In Case of creating a new product.
//$product = Mage::getModel('catalog/product');
//$product->setProductOptions(array($option));
//$product->setCanSaveCustomOptions(true);
//Or if we are adding the options to a already created product.
$product = Mage::getModel('catalog/product')->load($product_id);
$product->setProductOptions(array($option));
$product->setCanSaveCustomOptions(true);
//Do not forget to save the product
$product->save();
echo "Done";
} */
function getOption2(){
return array(
array(
'title' => 'Customization Text',
'price' =>0,
'price_type' => 'fixed',
'sku' => '',
'sort_order' => '1'
),
array(
'title' => 'Customization Detail',
'price' =>0,
'price_type' => 'fixed',
'sku' => '',
'sort_order' => '1'
);
}
function getOption1(){
return array(
array(
'title' => 'Need Customization',
'price' =>500,
'price_type' => 'fixed',
'sku' => '',
'sort_order' => '1'
);
}