equal($oname, $product['name'], 'old name is equal to product name'); equal(round($old_price, 2), round($product['price'], 2), 'old price should equal product price'); /* * Now let's look at creating a completely new product. */ //Step 1, let's find out what the supported attributes are: $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_supported_attributes', 'arguments' => array('token' => $token)); $result = curl_post($url, $data); $result = json_decode($result, true); equal($result['status'], true, 'Get supported attributes?'); $supported_attributes = $result['payload'][0]; keyExists('Product', $supported_attributes, 'Do we have attributes for Product?'); $r = rand(1, 9999999); $sr = rand(1, 5); $p = $sr * 1.25; // This is the minimum info to get a sellable product $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock'); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($new_product_data)); $result = curl_post($url, $data); $result = json_decode($result, true); equal($result['status'], true, 'Get supported attributes?'); $product = $result['payload'][0]; keyExists('id', $product, 'Was the id set?'); // Try uploading an image $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock', 'images' => array(array('name' => 'fractal.png')), 'featured_image' => array(array('name' => 'fractal3.png'))); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($new_product_data), 'images[0]' => "@" . dirname(__FILE__) . "/fractal.png", 'images[1]' => "@" . dirname(__FILE__) . "/fractal3.png"); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; keyExists('id', $product['images'][0], 'Was the id of the image set?');
<?php require_once "functions.php"; include "config.php"; $Header("Writing Product Images"); $r = rand(1, 9999999); $sr = rand(1, 5); $p = $sr * 1.25; // Try uploading an image $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock', 'images' => array(array('name' => 'fractal.png'), array('name' => 'fractal2.png')), 'featured_image' => array(array('name' => 'fractal3.png'))); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($new_product_data), 'images[0]' => "@" . dirname(__FILE__) . "/fractal.png", 'images[1]' => "@" . dirname(__FILE__) . "/fractal2.png", 'images[2]' => "@" . dirname(__FILE__) . "/fractal3.png", 'image_sizes' => array(array('name' => 'Catalog Thumbnail', 'width' => 300, 'height' => 300, 'crop' => false))); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; keyExists('id', $product['images'][0], 'Was the id of the image set?'); keyExists('Catalog Thumbnail', $product['images'][0]['metadata']['sizes'], 'Custom Image Created?');
<?php require_once "functions.php"; include "config.php"; $Header("Setting Product Variation"); $r = rand(1, 9999999); $sr = rand(1, 5); $p = $sr * 1.25; $master_product_data = array('name' => "An API Created Variable Product", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'variable', 'type' => 'product', 'status' => 'instock', 'attributes' => array('size' => array('name' => 'Size', 'value' => array('Small', 'Medium', 'Large'), 'is_variation' => 'yes', 'is_visible' => 'yes', 'is_taxonomy' => 'no'))); // Try uploading an image $new_product_data = array('name' => "An API Created Product 203 Variation #1", 'price' => $p, 'sku' => "API{$r}V1", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product_variation', 'status' => 'instock', 'size_attribute' => 'small'); $new_product_data2 = array('name' => "An API Created Product 203 Variation #2", 'price' => $p, 'sku' => "API{$r}V2", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product_variation', 'status' => 'instock', 'size_attribute' => 'medium'); $master_product_data['variations'] = array($new_product_data, $new_product_data2); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_products', 'arguments' => array('token' => $token), 'payload' => array($master_product_data), 'model_filters' => array('WCAPI_product_meta_attributes_table' => array('size_attribute' => array('name' => 'attribute_size', 'type' => 'string', 'values' => array('small', 'medium', 'large'), 'sizehint' => 2)))); $result = curl_post($url, $data); $result = json_decode($result, true); $product = $result['payload'][0]; keyExists('variations', $product, 'Is the variations key set?'); hasAtLeast($product['variations'], 1, "Has at least 1 variation?");
function addSettingValue($setType, $setName, $setField = "", $setValue = "", $setOption = "") { global $setInfoResult, $strShow, $strDelete, $DMC, $DBPrefix; //如果该值没有设定则增加到数据库 if ($setField != "") { if (!keyExists($setField, $setInfoResult)) { $DMC->query("insert into " . $DBPrefix . "setting(settName,settValue,settAuto) values('{$setField}','{$setValue}','0')"); $setInfoResult[$setField] = $setValue; } if ($setField == "ncalendar") { $setInfoResult[$setField] = str_replace("}{", "}\r\n{", dencode($setInfoResult[$setField])); } if ($setField == "gcalendar") { $setInfoResult[$setField] = str_replace("}{", "}\r\n{", dencode($setInfoResult[$setField])); } } //echo $setType."==".$setName."==".$setField."==".$setOption."<br />"; switch ($setType) { case 't': //text input if ($setField == "linklogo") { $changecode = "onchange=\"if ((/^http:\\/\\//i.test(this.value))){document.getElementById('linklogoimg').src=this.value}else{document.getElementById('linklogoimg').src='{$setInfoResult['blogUrl']}'+this.value}\""; } else { $changecode = ""; } $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle"> <input name="{$setField}" type="text" size="50" class="textbox" value="{$setInfoResult[$setField]}" {$changecode}/> {$setOption} </td> </tr> HTMLCODE; break; case 'ta': //textarea $setInfoResult[$setField] = str_replace("<br />", "", dencode($setInfoResult[$setField])); $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="top" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="top"> </td> <td width="75%" align="left"> <textarea name="{$setField}" cols="60" rows="6" class="blogeditbox">{$setInfoResult[$setField]}</textarea> {$setOption} </td> </tr> HTMLCODE; break; case 'tn': //text input $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle"> <input name="{$setField}" type="text" size="5" class="textbox" value="{$setInfoResult[$setField]}" onKeyPress="if (event.keyCode < 48 || event.keyCode > 57) event.returnValue = false; "/> {$setOption} </td> </tr> HTMLCODE; break; case 'f': //file input if ($setInfoResult[$setField] != "") { $show_images = " <a href='../attachments/{$setInfoResult[$setField]}' target='_blank'>{$strShow}</a>"; $show_images .= " <a href='setting.php?delete={$setField}'>{$strDelete}</a>"; } else { $show_images = ""; } $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle"> \t\t\t\t<input name="{$setField}" type="file" size="37" class="filebox" value=""/> \t\t\t\t{$show_images} {$setOption} </td> </tr> HTMLCODE; break; case 'r': //radio button $arr_radio = ""; $arrOption = explode("|", $setOption); for ($i = 0; $i < count($arrOption); $i++) { if (strpos($arrOption[$i], "=>")) { list($r_name, $r_value) = explode("=>", $arrOption[$i]); $checked = $setInfoResult[$setField] == $r_value ? " checked=\"checked\"" : ""; $arr_radio .= "<input type=\"radio\" name=\"{$setField}\" value=\"{$r_value}\"{$checked}> {$r_name} \n"; } else { $arr_radio .= $arrOption[$i]; } } $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle" style="padding-top:7px">{$arr_radio}</td> </tr> HTMLCODE; break; case 'c': //check button $arr_check = ""; $arrOption = explode("|", $setOption); for ($i = 0; $i < count($arrOption); $i++) { if (strpos($arrOption[$i], "=>")) { list($r_name, $r_value) = explode("=>", $arrOption[$i]); $checked = strpos(";{$setInfoResult[$setField]};", $r_value) > 0 ? " checked=\"checked\"" : ""; $arr_check .= "<input type=\"checkbox\" name=\"{$setField}[]\" value=\"{$r_value}\"{$checked}> {$r_name} \n"; } else { $arr_radio .= $arrOption[$i]; } } $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle" style="padding-top:7px">{$arr_check}</td> </tr> HTMLCODE; break; case 'sel': //check button $arr_select = ""; $arrOption = explode("|", $setOption); for ($i = 0; $i < count($arrOption); $i++) { if (strpos($arrOption[$i], "=>")) { list($r_name, $r_value) = explode("=>", $arrOption[$i]); if (strpos($r_name, ",") > 0) { $arr_name = explode(",", $r_name); $arr_value = explode(",", $r_value); for ($j = 0; $j < count($arr_name); $j++) { $selected = $setInfoResult[$setField] == $arr_value[$j] ? " selected" : ""; $arr_select .= "<option value='{$arr_value[$j]}' {$selected}>{$arr_name[$j]}</option> \n"; } } else { $selected = $setInfoResult[$setField] == $r_value ? " selected" : ""; $arr_select .= "<option value='{$r_value}' {$selected}>{$r_name}</option> \n"; } } else { $arr_select .= $arrOption[$i]; } } $output = <<<HTMLCODE <tr> <td width="25%" align="right" valign="middle" class="input-titleblue">{$setName}</td> <td width="4" align="left" valign="middle"> </td> <td width="75%" align="left" valign="middle" style="padding-top:7px"> \t\t\t\t<select name="{$setField}" class="blogeditbox"> \t\t\t\t{$arr_select} \t\t\t\t</select> \t\t\t </td> </tr> HTMLCODE; break; case 'sec': //A separator $output = <<<HTMLCODE <tr> <td width="100%" colspan="3"> \t\t\t\t<div class="settitle"> {$setName} </div>\t \t\t\t </td> </tr> HTMLCODE; break; } return $output; }
<?php require_once "functions.php"; include "config.php"; $Header("Writing Store Settings"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_store_settings', 'arguments' => array('token' => $token)); $result = curl_post($url, $data); verifySuccess("Get Store Settings", $result); $result = json_decode($result, true); $old_value = $result['payload']['force_ssl_checkout']; $new_value = $old_value == 'no' ? 'yes' : 'no'; notEqual($old_value, $new_value); $result['payload']['force_ssl_checkout'] = $new_value; $result['proc'] = 'set_store_settings'; $result = curl_post($url, $result); verifySuccess("Set Store Settings", $result); $result = json_decode($result, true); equal($result['payload']['force_ssl_checkout'], $new_value); $result['payload']['force_ssl_checkout'] = $old_value; $result = curl_post($url, $result); verifySuccess("Set Store Settings 2", $result); $result = json_decode($result, true); equal($result['payload']['force_ssl_checkout'], $old_value); // Test filtering $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_store_settings', 'arguments' => array('token' => $token, 'filter' => 'force')); $result = curl_post($url, $data); verifySuccess("Get Store Filtered Settings", $result); $result = json_decode($result, true); keyExists('force_ssl_checkout', $result['payload']);
if (isset($order['notes']) && is_array($order['notes']) && count($order['notes']) > 0) { $note_count2 += count($order['notes']); $has_notes = true; } if (isset($order['order_items']) && is_array($order['order_items']) && count($order['order_items']) > 0) { $has_ois = true; } } notEqual($note_count2, $note_count); $Header("Creating a new Order"); $data = array('action' => 'woocommerce_json_api', 'proc' => 'get_orders', 'arguments' => array('token' => $token, 'per_page' => 2, 'page' => 1)); $result = curl_post($url, $data); $result = json_decode($result, true); $new_order = $result['payload'][0]; unset($new_order['id']); unset($new_order['notes']); $relations = array('order_items', 'tax_items', 'coupon_items'); foreach ($relations as $relation) { foreach ($new_order[$relation] as &$item) { unset($item['id']); } } $new_order['name'] = "From the API"; $new_order['status'] = 'processing'; $result['payload'] = array($new_order); $result['proc'] = 'set_orders'; $new_result = curl_post($url, $result); $new_result = json_decode($new_result, true); equal($new_result['status'], true); keyExists('id', $new_result['payload'][0]);
<?php require_once "functions.php"; include "config.php"; $Header("Writing Product Images"); $r = rand(1, 9999999); $sr = rand(1, 5); $p = $sr * 1.25; // Try uploading an image $new_product_data = array('name' => "An API Created Product {$r}", 'price' => $p, 'sku' => "API{$r}", 'visibility' => 'visible', 'product_type' => 'simple', 'type' => 'product', 'status' => 'instock', 'images' => array(array('name' => 'fractal.png'), array('name' => 'fractal2.png')), 'featured_image' => array(array('name' => 'fractal3.png'))); $data = array('action' => 'woocommerce_json_api', 'proc' => 'set_images', 'arguments' => array('token' => $token), 'payload' => array(array('name' => 'fractal.png'), array('name' => 'fractal2.png')), 'images[0]' => "@" . dirname(__FILE__) . "/fractal.png", 'images[1]' => "@" . dirname(__FILE__) . "/fractal2.png", 'image_sizes' => array(array('name' => 'Catalog Thumbnail', 'width' => 300, 'height' => 300, 'crop' => false))); $result = curl_post($url, $data); $result = json_decode($result, true); print_r($result); $image = $result['payload'][0]; keyExists('id', $image, 'Was the id of the image set?');
session_start(); // Load config include '../../../config.php'; $good = isApiKeyValid($_GET['key']); $gameId = getGameIdFromApiKey($_GET['key']); // Load user info $userLogin = mysql_query("SELECT * FROM users WHERE (username = '******'username']) . "') and (application_password = '******'password']) . "')"); // Check game and user info if ($good) { if (mysql_num_rows($userLogin) == 1) { // Get data $row = mysql_fetch_array($userLogin); $userId = $row['id']; // Print info $key = createRandomKey(10); while (keyExists($key)) { $key = createRandomKey(10); } echo "true\n"; echo $key; echo "\n"; // Revoke previous sessions mysql_query("DELETE FROM sessions WHERE userid = '" . $userId . "'"); // Save session mysql_query("INSERT INTO sessions (userid, gameid, sessionkey) VALUES ('{$userId}','{$gameId}','{$key}')"); } else { echo "false"; echo "<br>"; echo "Invalid user\n"; } } else {