[quote name=‘TexasGuy’]I have a curl script that can automatically insert options into products. You can loop it with this kind of function:
add_option($product_id,$option_id,$times_to_insert,$is_global=‘N’);
(you can mod the function for global to be implicitly ‘Y’)
With a matched product->has options array you can run my curl script:
(for this you would need already global options created and have and array that matches what products get what options. Then it is automatic insert through admin.php that emulates a user…
```php
function add_option($item,$option,$times=1,$g=‘N’){
$post_data=“product_id=$item&selected_section=options&global_option%5Bid%5D=$option&global_option%5Blink%5D=$g&dispatch%5Bproducts.apply_global_option%5D=Apply”;
$url=‘https://website.com/admin.php’;
$cookie=‘my.c’;
$useragent=“Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1”;
$referrer=‘https://website.com/admin.php?dispatch=products.update&product_id=’.$item;
for($i=0;$i<$times;$i++){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie);
$out = curl_exec($ch);
unset($ch);
sleep(1);
}
}
```
Before using this function, find another curl script in my posts for admin, you need to run the “login” part first so the cookies would have you marked as logged in.
Also, you need to change some URLs in the function to match your website and admin.php name.
This is what I have to play with demo website (note that demo login is not HTTPS and you would need to edit to HTTPS if you are editing that function to match your needs):
```php
function login_demo(){
$url=‘Instant Demo - CS-Cart Multi-Vendor Demo Try Free for 15 days’;
$post_data=‘return_url=admin.php&user_login=admin&password=admin&dispatch%5Bauth.login%5D=Sign+in’;
$cookie=‘my.c’;
$useragent=“Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1”;
$referrer=‘Instant Demo - CS-Cart Multi-Vendor Demo Try Free for 15 days’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie);
$out = curl_exec($ch);
echo $out;
}
function add_option_demo($item,$option,$times=1,$g=‘N’){
$post_data=“product_id=$item&selected_section=options&global_option%5Bid%5D=$option&global_option%5Blink%5D=$g&dispatch%5Bproducts.apply_global_option%5D=Apply”;
$url=‘Instant Demo - CS-Cart Multi-Vendor Demo Try Free for 15 days’;
$cookie=‘my.c’;
$useragent=“Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1”;
$referrer=‘Instant Demo - CS-Cart Multi-Vendor Demo Try Free for 15 days’.$item;
for($i=0;$i<$times;$i++){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_REFERER, $referrer);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_HEADER,0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie);
$out = curl_exec($ch);
unset($ch);
}
}
```
If you are to enter admin of demo cs-cart, you will see 2 global options:
Color with id 734 (hoover over edit to see the link in the status bar, last digit is the id)
and
Size with id 735
The id of a product can be found from admin in a similar manner without going into DB, but just looking at the link. With product id and option id you can start inserts in no time.
Then you would run login once then add_option as many times as you need.
My latest script (with my admin info that I don’t want to show here) has a last part that detects if the login was successful is:
```php
if(stripos(‘Sign out’,$out)===false) return false;
return true
```
This returns true/false on login rather than echoing the output… You can apply your own logic.[/QUOTE]
Sounds nice… any idea on adding combinations and or exceptions ?
basically i need to figure HOW to use IMPORT format to add options with inventory…
BOOT
color = red,brown,blue
size= small,large
combos… (color/size/invent)
red/small/1
red/large/4
blue/small/32
etc…
options is ok for import…size and color can be passed… how can the system know about inventory ? if inventory is checked and track with options… does it ASSUME that when you send ITEM with option and inventory that is what it needs ?
example…
ITEM1, "Color: S[Black]; Size: S[Small];100
ITEM1, "Color: S[Black]; Size: S[Medium];50
ITEM1, "Color: S[Black]; Size: S[Large];30
it this it ?