-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproductos.php
142 lines (127 loc) · 5.17 KB
/
productos.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?php
include_once("includes/mysql_connect.php");
include_once("includes/shopify.php");
$shopify = new shopify();
$parameters = $_GET;
include_once("includes/check_token.php");
if($_SERVER['REQUEST_METHOD'] == 'POST'){
if (isset($_POST['product_title']) && isset($_POST['product_body_html']) && $_POST ['action_type'] == 'create_product')
{
$product_data = array(
"product" => array(
"title" =>$_POST['product_title'],
"body_html" => $_POST ['product_body_html'] )
);
$create_product = $shopify ->rest_api('/admin/api/2021-07/products.json', $product_data, 'POST');
$create_product = json_decode ($create_product['body'], true);
//echo print_r($create_product);
}
if (isset( $_POST['delete_id']) && $_POST['action_type'] == 'delete') {
$delete = $shopify ->rest_api('/admin/api/2021-07/products/' . $_POST['delete_id'] . '.json', array(), 'DELETE');
$delete = json_decode ($delete['body'], true);
}
if (isset($_POST['update_id']) && $_POST['action_type'] == 'update')
{
$getID = explode('/',$_POST['update_id']);
$update_data = array(
"product" => array(
"id" =>$_POST['update_id'],
"title" => $_POST ['update_name'] ) );
$update = $shopify ->rest_api('/admin/api/2021-07/products/' . end($getID) . '.json', $update_data, 'PUT');
$update = json_decode ($update['body'], true);
}
}
// $products = $shopify ->rest_api('/admin/api/2021-07/products.json', array(), 'GET');
// $products = json_decode ($products['body'], true); //echo print_r($products);
$gql_query = array("query" => "{
products (first:2){
edges{
node {
id
title
images (first: 1) {
edges {
node {
originalSrc
}
}
}
status
}
}
}
}
");
$products = $shopify->graphql($gql_query );
$products = json_decode($products['body'], true);
$products_edges= $products['data']['products'];
?>
<?php include_once ("headers.php");?>
<section>
<aside>
<h2>Nuevo Producto</h2>
<p>Llenar los datos</p>
</aside>
<article>
<div class="card">
<form action="" method="post">
<input type="hidden" name="action_type" value="create_product">
<div class="row">
<label for="productTitle"> Nombre</label>
<input type="text" name="product_title" id= "productTitle">
</div>
<div class="row">
<label for="productDescription" class=""> Descripcion</label>
<textarea name="product_body_html" id="productDescription" ></textarea>
<div class="row">
<button type="submit">Guardar</button>
</div>
</div>
</form>
</div>
</article>
</section>
<section>
<table>
<thead>
<tr>
<th colspan="2">Productos</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
foreach($products_edges as $edge){
foreach ($edge as $node) {
foreach ($node as $key => $value){
$image = count($value['images']['edges']) > 0 ? $value['images']['edges'][0]['node']['originalSrc'] :""; ?>
<tr>
<td><img width="35" height="35" src="<?php echo $image; ?>" /></td>
<td>
<form action="" method="post" class="row side-elements">
<input type="hidden" name="update_id" value="<?php echo $value ['id'];?>" />
<input type="text" name="update_name" value="<?php echo $value ['title'];?>" />
<input type="hidden" name="action_type" value="update" />
<button type="submit" class="secondary icon-checkmark"></button>
</form>
</td>
<td><?php echo $value ['status'] ?></td>
<td>
<form action="" method="POST">
<input type="hidden" name="delete_id" value="<?php echo $value ['id'];?>" />
<input type="hidden" name="action_type" value="delete" />
<button type="submit" class="secondary icon-trash"></button>
</form>
</td>
</tr>
<?php
}
}
}
?>
</tbody>
<tbody></tbody>
</table>
</section>
<?php include_once ("footer.php");?>