| 1 |
lars |
1 |
<?PHP
|
|
|
2 |
/**
|
|
|
3 |
* Model for an eBay item
|
|
|
4 |
*
|
|
|
5 |
* $Id: Item.php,v 1.6 2005/01/04 23:01:33 schst Exp $
|
|
|
6 |
*
|
|
|
7 |
* @package Services_Ebay
|
|
|
8 |
* @author Stephan Schmidt <schst@php.net>
|
|
|
9 |
*/
|
|
|
10 |
class Services_Ebay_Model_Item extends Services_Ebay_Model
|
|
|
11 |
{
|
|
|
12 |
/**
|
|
|
13 |
* model type
|
|
|
14 |
*
|
|
|
15 |
* @var string
|
|
|
16 |
*/
|
|
|
17 |
protected $type = 'Item';
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* property that stores the unique identifier (=pk) of the model
|
|
|
21 |
*
|
|
|
22 |
* @var string
|
|
|
23 |
*/
|
|
|
24 |
protected $primaryKey = 'Id';
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* create new item
|
|
|
28 |
*
|
|
|
29 |
* @param array properties
|
|
|
30 |
*/
|
|
|
31 |
public function __construct($props, $session = null)
|
|
|
32 |
{
|
|
|
33 |
if (is_array($props) && isset($props['Seller'])) {
|
|
|
34 |
if (isset($props['Seller']['User']) && is_array($props['Seller']['User'])) {
|
|
|
35 |
$props['Seller'] = Services_Ebay::loadModel('User', $props['Seller']['User'], $session);
|
|
|
36 |
}
|
|
|
37 |
}
|
|
|
38 |
parent::__construct($props, $session);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* set the locations you will ship the item to
|
|
|
43 |
*
|
|
|
44 |
* @param array
|
|
|
45 |
*/
|
|
|
46 |
public function setShipToLocations($ShipToLocations)
|
|
|
47 |
{
|
|
|
48 |
$this->properties['ShipToLocations'] = array(
|
|
|
49 |
'ShipToLocation' => $ShipToLocations
|
|
|
50 |
);
|
|
|
51 |
return true;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* add a shipping service option
|
|
|
56 |
*
|
|
|
57 |
* @param integer shipping service, {@link http://developer.ebay.com/DevZone/docs/API_Doc/Appendixes/AppendixN.htm#shippingservices}
|
|
|
58 |
* @param integer priority (1-3)
|
|
|
59 |
* @param float cost for the item
|
|
|
60 |
* @param float cost for an additional item
|
|
|
61 |
* @return boolean
|
|
|
62 |
*/
|
|
|
63 |
public function addShippingServiceOption($ShippingService, $ShippingServicePriority, $ShippingServiceCost, $ShippingServiceAdditionalCost)
|
|
|
64 |
{
|
|
|
65 |
$option = array(
|
|
|
66 |
'ShippingService' => $ShippingService,
|
|
|
67 |
'ShippingServicePriority' => $ShippingServicePriority,
|
|
|
68 |
'ShippingServiceCost' => $ShippingServiceCost,
|
|
|
69 |
'ShippingServiceAdditionalCost' => $ShippingServiceAdditionalCost,
|
|
|
70 |
);
|
|
|
71 |
if (!isset($this->properties['ShippingServiceOptions'])) {
|
|
|
72 |
$this->properties['ShippingServiceOptions'] = array(
|
|
|
73 |
'ShippingServiceOption' => array()
|
|
|
74 |
);
|
|
|
75 |
}
|
|
|
76 |
array_push($this->properties['ShippingServiceOptions']['ShippingServiceOption'], $option);
|
|
|
77 |
return true;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* add an international shipping service option
|
|
|
82 |
*
|
|
|
83 |
* @param integer shipping service, {@link http://developer.ebay.com/DevZone/docs/API_Doc/Appendixes/AppendixN.htm#shippingservices}
|
|
|
84 |
* @param integer priority (1-3)
|
|
|
85 |
* @param float cost for the item
|
|
|
86 |
* @param float cost for an additional item
|
|
|
87 |
* @param array locations for this shipping service options
|
|
|
88 |
* @return boolean
|
|
|
89 |
*/
|
|
|
90 |
public function addInternationalShippingServiceOption($ShippingService, $ShippingServicePriority, $ShippingServiceCost, $ShippingServiceAdditionalCost, $ShipToLocations)
|
|
|
91 |
{
|
|
|
92 |
$option = array(
|
|
|
93 |
'ShippingService' => $ShippingService,
|
|
|
94 |
'ShippingServicePriority' => $ShippingServicePriority,
|
|
|
95 |
'ShippingServiceCost' => $ShippingServiceCost,
|
|
|
96 |
'ShippingServiceAdditionalCost' => $ShippingServiceAdditionalCost,
|
|
|
97 |
'ShipToLocations' => array(
|
|
|
98 |
'ShipToLocation' => $ShipToLocations
|
|
|
99 |
)
|
|
|
100 |
);
|
|
|
101 |
if (!isset($this->properties['InternationalShippingServiceOptions'])) {
|
|
|
102 |
$this->properties['InternationalShippingServiceOptions'] = array(
|
|
|
103 |
'ShippingServiceOption' => array()
|
|
|
104 |
);
|
|
|
105 |
}
|
|
|
106 |
array_push($this->properties['InternationalShippingServiceOptions']['ShippingServiceOption'], $option);
|
|
|
107 |
return true;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* create a string representation of the item
|
|
|
112 |
*
|
|
|
113 |
* @return string
|
|
|
114 |
*/
|
|
|
115 |
public function __toString()
|
|
|
116 |
{
|
|
|
117 |
if (isset($this->properties['Title'])) {
|
|
|
118 |
return $this->properties['Title'] . ' (# '.$this->properties['Id'].')';
|
|
|
119 |
}
|
|
|
120 |
return '# '.$this->properties['Id'];
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* get the item from eBay
|
|
|
125 |
*
|
|
|
126 |
* Use this to query by a previously set itemId.
|
|
|
127 |
*
|
|
|
128 |
* <code>
|
|
|
129 |
* $item = Services_Ebay::loadModel('Item', null, $session);
|
|
|
130 |
* $item->Id = 4501296414;
|
|
|
131 |
* $item->Get();
|
|
|
132 |
* </code>
|
|
|
133 |
*
|
|
|
134 |
* @param int DetailLevel
|
|
|
135 |
* @param int DescFormat
|
|
|
136 |
* @see Services_Ebay_Call_GetItem
|
|
|
137 |
*/
|
|
|
138 |
public function Get($DetailLevel = null, $DescFormat = 0)
|
|
|
139 |
{
|
|
|
140 |
$args = array(
|
|
|
141 |
'Id' => $this->properties['Id'],
|
|
|
142 |
'DescFormat' => $DescFormat
|
|
|
143 |
);
|
|
|
144 |
if (!is_null($DetailLevel)) {
|
|
|
145 |
$args['DetailLevel'] = $DetailLevel;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$call = Services_Ebay::loadAPICall('GetItem');
|
|
|
149 |
$call->setArgs($args);
|
|
|
150 |
|
|
|
151 |
$tmp = $call->call($this->session);
|
|
|
152 |
$this->properties = $tmp->toArray();
|
|
|
153 |
$this->eBayProperties = $this->properties;
|
|
|
154 |
unset($tmp);
|
|
|
155 |
return true;
|
|
|
156 |
}
|
|
|
157 |
|
|
|
158 |
/**
|
|
|
159 |
* get cross promotions
|
|
|
160 |
*
|
|
|
161 |
* @param int DetailLevel
|
|
|
162 |
* @param int DescFormat
|
|
|
163 |
* @see Services_Ebay_Call_GetCrossPromotions
|
|
|
164 |
*/
|
|
|
165 |
public function GetCrossPromotions($PromotionMethod = 'CrossSell', $PromotionViewMode = null)
|
|
|
166 |
{
|
|
|
167 |
$args = array(
|
|
|
168 |
'ItemId' => $this->properties['Id'],
|
|
|
169 |
'PromotionMethod' => $PromotionMethod
|
|
|
170 |
);
|
|
|
171 |
if (!is_null($PromotionViewMode)) {
|
|
|
172 |
$args['PromotionViewMode'] = $PromotionViewMode;
|
|
|
173 |
}
|
|
|
174 |
|
|
|
175 |
$call = Services_Ebay::loadAPICall('GetCrossPromotions');
|
|
|
176 |
$call->setArgs($args);
|
|
|
177 |
|
|
|
178 |
return $call->call($this->session);
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
/**
|
|
|
182 |
* add text to the item description
|
|
|
183 |
*
|
|
|
184 |
* @param string
|
|
|
185 |
* @return boolean
|
|
|
186 |
* @see Services_Ebay_Call_AddToItemDescription
|
|
|
187 |
*/
|
|
|
188 |
public function AddToDescription($Description)
|
|
|
189 |
{
|
|
|
190 |
$args = array(
|
|
|
191 |
'ItemId' => $this->properties['Id'],
|
|
|
192 |
'Description' => $Description
|
|
|
193 |
);
|
|
|
194 |
$call = Services_Ebay::loadAPICall('AddToItemDescription');
|
|
|
195 |
$call->setArgs($args);
|
|
|
196 |
|
|
|
197 |
return $call->call($this->session);
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
/**
|
|
|
201 |
* and an auction
|
|
|
202 |
*
|
|
|
203 |
* @param integer
|
|
|
204 |
* @return array
|
|
|
205 |
* @see Services_Ebay_Call_EndItem
|
|
|
206 |
*/
|
|
|
207 |
public function End($EndCode)
|
|
|
208 |
{
|
|
|
209 |
$args = array(
|
|
|
210 |
'ItemId' => $this->properties['Id'],
|
|
|
211 |
'EndCode' => $EndCode
|
|
|
212 |
);
|
|
|
213 |
$call = Services_Ebay::loadAPICall('EndItem');
|
|
|
214 |
$call->setArgs($args);
|
|
|
215 |
|
|
|
216 |
return $call->call($this->session);
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
/**
|
|
|
220 |
* Add the item to eBay
|
|
|
221 |
*
|
|
|
222 |
* This starts a new auction
|
|
|
223 |
*
|
|
|
224 |
* @see Services_Ebay_Call_RelistItem
|
|
|
225 |
*/
|
|
|
226 |
public function Add()
|
|
|
227 |
{
|
|
|
228 |
if (isset($this->properties['ItemId']) && !is_null($this->properties['ItemId'])) {
|
|
|
229 |
throw new Services_Ebay_Exception('This item already has an ItemId and thus cannot be added.');
|
|
|
230 |
}
|
|
|
231 |
$call = Services_Ebay::loadAPICall('AddItem', array($this));
|
|
|
232 |
|
|
|
233 |
return $call->call($this->session);
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
/**
|
|
|
237 |
* Re-list the item
|
|
|
238 |
*
|
|
|
239 |
* This adds a new auction with exactly the same item data
|
|
|
240 |
*
|
|
|
241 |
* @todo check return value
|
|
|
242 |
* @see Services_Ebay_Call_RelistItem
|
|
|
243 |
*/
|
|
|
244 |
public function Relist()
|
|
|
245 |
{
|
|
|
246 |
$args = array(
|
|
|
247 |
'ItemId' => $this->properties['Id']
|
|
|
248 |
);
|
|
|
249 |
$call = Services_Ebay::loadAPICall('RelistItem');
|
|
|
250 |
$call->setArgs($args);
|
|
|
251 |
|
|
|
252 |
return $call->call($this->session);
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
/**
|
|
|
256 |
* Revise the item
|
|
|
257 |
*
|
|
|
258 |
* @return boolean
|
|
|
259 |
* @see Services_Ebay_Call_ReviseItem
|
|
|
260 |
*/
|
|
|
261 |
public function Revise()
|
|
|
262 |
{
|
|
|
263 |
$call = Services_Ebay::loadAPICall('ReviseItem', array($this));
|
|
|
264 |
return $call->call($this->session);
|
|
|
265 |
}
|
|
|
266 |
|
|
|
267 |
/**
|
|
|
268 |
* Add a second chance offer
|
|
|
269 |
*
|
|
|
270 |
* This adds a new auction with exactly the same item data
|
|
|
271 |
*
|
|
|
272 |
* @return object Services_Ebay_Model_Item
|
|
|
273 |
* @see Services_Ebay_Call_AddSecondChanceItem
|
|
|
274 |
*/
|
|
|
275 |
public function AddSecondChance($RecipientBidderUserId, $Duration = 3, $CopyEmailToSeller = 0, $BuyItNowPrice = null)
|
|
|
276 |
{
|
|
|
277 |
$args = array(
|
|
|
278 |
'OriginalItemId' => $this->properties['Id'],
|
|
|
279 |
'RecipientBidderUserId' => $RecipientBidderUserId,
|
|
|
280 |
'Duration' => $Duration,
|
|
|
281 |
'CopyEmailToSeller' => $CopyEmailToSeller
|
|
|
282 |
);
|
|
|
283 |
if ($BuyItNowPrice !== null) {
|
|
|
284 |
$args['BuyItNowPrice'] = $BuyItNowPrice;
|
|
|
285 |
}
|
|
|
286 |
$call = Services_Ebay::loadAPICall('AddSecondChanceItem');
|
|
|
287 |
$call->setArgs($args);
|
|
|
288 |
|
|
|
289 |
return $call->call($this->session);
|
|
|
290 |
}
|
|
|
291 |
}
|
|
|
292 |
?>
|