-
Notifications
You must be signed in to change notification settings - Fork 0
/
variationControl.php
81 lines (70 loc) · 2.45 KB
/
variationControl.php
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
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/init.php';
/*
if($_POST['type']=="modal")
{
// Fetching Values From URL
$vid = $_POST['vid'];
$sku = $_POST['sku'];
$enable = $_POST['enable'];
$downloadable = $_POST['donwloadable'];
$virtual = $_POST['virtual'];
$stock = $_POST['stock'];
$variation = $_POST['variation'];
$regularPrice = $_POST['regularPrice'];
$salePrice = $_POST['salePrice'];
$stockStatus = $_POST['stockStatus'];
$weight = $_POST['weight'];
$length = $_POST['length'];
$width = $_POST['width'];
$height = $_POST['height'];
$description = $_POST['description'];
require_once $_SERVER['DOCUMENT_ROOT'] . '/core/init.php';
$query = <<<EOF
UPDATE product_variations SET sku = '{$sku}', enabled = {$enable}, downloadable = {$downloadable}, virtual = {$virtual}, manage_stock = {$stock}, regular_price = {$regularPrice}, sale_price = {$salePrice]}, in_stock = {$stockStatus}, weight = {$weight}, height = {$height}, width = {$width}, length = {$length}, default_variation = '{$variation}', description = '{$description}' WHERE variation_id = {$vid};
EOF;
if($db->query($query)){
echo json_encode(['ok' => true]);
} else {
echo json_encode(['ok' => false, 'error' => $db->error_list, 'query' => $query]);
}
echo json_encode($vid);
echo "<h1>ajax: $sku</h1>";
}*/
if($_POST['type']=="save"){
foreach($_POST['varPackage'] as $key => $value)
{
$varID = $value['varID'];
$varName = json_encode($value['content']);
echo $varName."-".$varID." ";
if($varID=='add')
{
$prodID = $value['prodID'];
$query= <<<QUERY
INSERT INTO product_variations (product_id, variation_name) VALUES ({$prodID}, '{$varName}')
QUERY;
}else{
$query =<<<QUERY
UPDATE product_variations SET variation_name = '{$varName}' WHERE variation_id = {$varID}
QUERY;
}
if($db->query($query)){
//$data["id"] = $db->insert_id;
// echo json_encode($data);
} else {
echo "An error occured with query: </br>";
echo json_encode(['ok' => false, 'error' => $db->error_list, 'query' => $query]);
}
}
}elseif($_POST['type']=='remove'){
$query=<<<EOF
DELETE FROM `product_variations` WHERE `product_variations`.`variation_id` = {$_POST['id']}
EOF;
if($db->query($query)){
echo "Removed Attributes Successfully!";
} else {
echo "An error occured with query: </br>";
echo json_encode(['ok' => false, 'error' => $db->error_list, 'query' => $query]);
}
}
?>