-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexamples.php
More file actions
63 lines (49 loc) · 1.79 KB
/
examples.php
File metadata and controls
63 lines (49 loc) · 1.79 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
<?php
require_once('includes/API.php');
$username = 'API user'; // todo, change per setup.
$password = 'API password'; // todo change per setup.
$url = 'http://magento.dev/'; // change URL to store URL.
$api = new API($username, $password, $url); // Initiate the API request.
// To get Qty.
$sku = 'sample-sku';
$qty = $api->getQty($sku);
echo $qty;
// To update Qty by Sku
$sku = 'sample-sku';
$newQty = $qty + 1;
if($api->updateQty($sku, $newQty)){
echo 'Successful';
}else{
echo 'Unsuccessful';
}
// Get products from Magento.
$_products = $api->getProducts();
foreach($_products as $_product){
// Do whatever you want with each product. All data is in plain array();
}
print_r($_products);
// Add new Product to Magento.
// Refer to for more possible options https://devdocs.magento.com/swagger/index.html#!/catalogProductRepositoryV1/catalogProductRepositoryV1SavePost
$newproduct = array("sku" => "some-sku",
"name": "Some name",
"attribute_set_id": 0, // Check ID from admin.
"price": 5, // change per need.
"status": 0, // change per need.
"visibility": 0, // change per need.
"type_id": "simple", // i.e. simple per need.
"weight": 0.5
"extension_attributes" = array(
"stock_item" = array(
"qty" => 10 // change per need.
)
),
"custom_attributes" => array(
array('description', 'some descriptions'),
array('some_custom_attributes', 'some values'),
array('dropdownvalue', $api->getDropdownValues('attribute_code','frontend-value')),
)
);
$api->postProduct($newproduct); // for single product.
// For multiple products
$newproducts = array($newproduct, $newproduct, $newproduct, $newproduct); // 2d Array of similar approach which was for new product case.
$api->postProduct($newproducts); // for multiple products.