Skip to content

Commit 35b5bf5

Browse files
Removed useless methods.
Updated composer dependency Update readme
1 parent f956062 commit 35b5bf5

File tree

3 files changed

+69
-78
lines changed

3 files changed

+69
-78
lines changed

README.md

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,71 @@ public function bar()
8686
}
8787
```
8888

89-
PS Underlying library usage
89+
Prestashop Underlying library usage
9090
---------------------------
9191

92-
You may find complete documentation and tutorials regarding Prestashop Web Service Library in the [Prestashop Documentation](http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service).
92+
You may find complete documentation and tutorials regarding Prestashop Web Service Library in the [Prestashop Documentation](http://doc.prestashop.com/display/PS16/Using+the+PrestaShop+Web+Service).
93+
94+
Helper methods
95+
--------------
96+
97+
I've added some helper methods to reduce development time:
98+
99+
### Retrieving resource schema and filling data for posting
100+
101+
You may call `getSchema()` method to retrieve the requested resource schema. You may then fill the schema with an associative array of data with `fillSchema()` method.
102+
103+
```php
104+
105+
$xmlSchema=Prestashop::getSchema('categories'); //returns a SimpleXMLElement instance with the desired schema
106+
107+
$data=[
108+
'name'=>'Clothes',
109+
'link_rewrite'=>'clothes',
110+
'active'=>true
111+
];
112+
113+
$postXml=Prestashop::fillSchema($xmlSchema,$data);
114+
115+
//The xml is now ready for being sent back to the web service to create a new category
116+
117+
$response=Prestashop::add(['resource'=>'categories','postXml'=>$postXml->asXml()]);
118+
119+
```
120+
121+
#### Note for language value handling
122+
123+
If the node has a language child you may use a simple string for the value if your shop has only one language installed.
124+
125+
```php
126+
/*
127+
xml node with one language child example
128+
...
129+
<name>
130+
<language id="1"/>
131+
</name>
132+
...
133+
*/
134+
$data= ['name'=>Clothes'];
135+
```
136+
137+
If your shops has more than one language installed you may pass the node value as an array where the key is the language ID.
138+
139+
```php
140+
/*
141+
xml node with n language children example
142+
...
143+
<name>
144+
<language id="1"/>
145+
<language id="2"/>
146+
</name>
147+
...
148+
*/
149+
$data= [
150+
'name'=>[
151+
1 => 'Clothes',
152+
2 => 'Abbigliamento
153+
]
154+
];
155+
```
156+
_Please note that if you don't provide an array of values keyed by the language ID all language values will have the same value._

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
}
1515
},
1616
"require": {
17-
"protechstudio/prestashop-webservice-lib": "1.*"
17+
"prestashop/prestashop-webservice-lib": "dev-master"
1818
}
1919
}

src/PrestashopWebService.php

Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,8 @@ class PrestashopWebService extends PSLibrary
99
{
1010

1111
/**
12-
* @param $options
13-
* @param bool $assoc
14-
* @return mixed
15-
* @throws \PrestaShopWebserviceException
16-
*/
17-
public function getJson($options, $assoc = false)
18-
{
19-
$options = $this->requestJsonOutput($options);
20-
21-
return json_decode($this->get($options), $assoc);
22-
}
23-
24-
/**
25-
* @param $options
26-
* @param bool $assoc
27-
* @return mixed
28-
* @throws \PrestaShopWebserviceException
29-
*/
30-
public function headJson($options, $assoc = false)
31-
{
32-
$options = $this->requestJsonOutput($options);
33-
34-
return json_decode($this->head($options), $assoc);
35-
}
36-
37-
/**
38-
* @param $options
39-
* @param bool $assoc
40-
* @return mixed
41-
* @throws \PrestaShopWebserviceException
42-
*/
43-
public function addJson($options, $assoc = false)
44-
{
45-
$options = $this->requestJsonOutput($options);
46-
47-
return json_decode($this->add($options), $assoc);
48-
}
49-
50-
/**
51-
* @param $options
52-
* @param bool $assoc
53-
* @return mixed
54-
* @throws \PrestaShopWebserviceException
55-
*/
56-
public function editJson($options, $assoc = false)
57-
{
58-
$options = $this->requestJsonOutput($options);
59-
60-
return json_decode($this->edit($options), $assoc);
61-
}
62-
63-
/**
64-
* @param $options
65-
* @param bool $assoc
66-
* @return mixed
67-
*/
68-
public function deleteJson($options, $assoc = false)
69-
{
70-
$options = $this->requestJsonOutput($options);
71-
72-
return json_decode($this->delete($options), $assoc);
73-
}
74-
75-
/**
76-
* @param $options
77-
* @return mixed
78-
*/
79-
private function requestJsonOutput($options)
80-
{
81-
$options['output_format'] = 'JSON';
82-
83-
return $options;
84-
}
85-
86-
/**
12+
* Retrieve the resource schema
13+
*
8714
* @param $resource
8815
* @return SimpleXMLElement
8916
* @throws \PrestaShopWebserviceException

0 commit comments

Comments
 (0)