1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright (c) 2013-2014 eBay Enterprise, Inc. |
4
|
|
|
* |
5
|
|
|
* NOTICE OF LICENSE |
6
|
|
|
* |
7
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
8
|
|
|
* that is bundled with this package in the file LICENSE.md. |
9
|
|
|
* It is also available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* @copyright Copyright (c) 2013-2014 eBay Enterprise, Inc. (http://www.ebayenterprise.com/) |
13
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
class EbayEnterprise_Catalog_Helper_Pim |
17
|
|
|
{ |
18
|
|
|
const DEFAULT_OPERATION_TYPE = 'Change'; |
19
|
|
|
const NEW_PRODUCT_OPERATION_TYPE = 'Add'; |
20
|
|
|
const MAX_SKU_LENGTH = 15; |
21
|
|
|
const STRING_LIMIT = 4000; |
22
|
|
|
// Config XML path for gift wrapping availability flag |
23
|
|
|
const XML_PATH_ALLOW_GIFT_WRAPPING = 'sales/gift_options/wrapping_allow_items'; |
24
|
|
|
/** |
25
|
|
|
* return a cdata node from a given string value. |
26
|
|
|
* @param string $attrValue |
27
|
|
|
* @param string $attribute |
28
|
|
|
* @param Mage_Catalog_Model_Product $product |
29
|
|
|
* @param DOMDocument $doc |
30
|
|
|
* @return DOMNode|null |
|
|
|
|
31
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
32
|
|
|
*/ |
33
|
|
|
public function getValueAsDefault($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
34
|
|
|
{ |
35
|
|
|
if ($attrValue) { |
36
|
|
|
$frag = $doc->createDocumentFragment(); |
37
|
|
|
$frag->appendChild($doc->createElement('Value')) |
38
|
|
|
->appendChild($this->passString($attrValue, $attribute, $product, $doc)); |
39
|
|
|
return $frag; |
40
|
|
|
} |
41
|
|
|
return null; |
42
|
|
|
} |
43
|
|
|
/** |
44
|
|
|
* call self::createStringNode passing it string truncate to on self::STRING_LIMIT and pass the given DOMDocument |
45
|
|
|
* which will either return DOMNode object or a null value. |
46
|
|
|
* @param string $attrValue |
47
|
|
|
* @param string $attribute |
48
|
|
|
* @param Mage_Catalog_Model_Product $product |
49
|
|
|
* @param DOMDocument $doc |
50
|
|
|
* @return DOMNode|null |
|
|
|
|
51
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
52
|
|
|
*/ |
53
|
|
|
public function passString($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
54
|
|
|
{ |
55
|
|
|
return $this->createStringNode(substr($attrValue, 0, self::STRING_LIMIT), $doc); |
56
|
|
|
} |
57
|
|
|
/** |
58
|
|
|
* De-normalized a given sku by calling EbayEnterprise_Catalog_Helper_Data::denormalizeSku method and then calling |
59
|
|
|
* the self::createStringNode method given the de-normalize sku and the given DOMDocument object in which |
60
|
|
|
* will return a DOMNode object |
61
|
|
|
* @param string $attrValue |
62
|
|
|
* @param string $attribute |
63
|
|
|
* @param Mage_Catalog_Model_Product $product |
64
|
|
|
* @param DOMDocument $doc |
65
|
|
|
* @throws EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception |
66
|
|
|
* @return DOMNode|null |
|
|
|
|
67
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
68
|
|
|
*/ |
69
|
|
|
public function passSKU($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$catalogId = Mage::helper('eb2ccore')->getConfigModel($product->getStoreId())->catalogId; |
72
|
|
|
$sku = Mage::helper('ebayenterprise_catalog')->denormalizeSku($attrValue, $catalogId); |
73
|
|
|
if (strlen($sku) > self::MAX_SKU_LENGTH) { |
74
|
|
|
throw new EbayEnterprise_Catalog_Model_Pim_Product_Validation_Exception( |
75
|
|
|
sprintf('%s SKU \'%s\' Exceeds max length.', __FUNCTION__, $sku) |
76
|
|
|
); |
77
|
|
|
} |
78
|
|
|
return $this->createStringNode($sku, $doc); |
79
|
|
|
} |
80
|
|
|
/** |
81
|
|
|
* Pass the string IF it has a value. |
82
|
|
|
* which will either return DOMNode object or a null value. |
83
|
|
|
* @param string $attrValue |
84
|
|
|
* @param string $attribute |
85
|
|
|
* @param Mage_Catalog_Model_Product $product |
86
|
|
|
* @param DOMDocument $doc |
87
|
|
|
* @return DOMNode|null |
|
|
|
|
88
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
89
|
|
|
*/ |
90
|
|
|
public function passStringIf($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
91
|
|
|
{ |
92
|
|
|
if (!empty($attrValue)) { |
93
|
|
|
return $this->passString($attrValue, $attribute, $product, $doc); |
94
|
|
|
} |
95
|
|
|
return null; |
96
|
|
|
} |
97
|
|
|
/** |
98
|
|
|
* round the attrValue to two decimal point by calling the method Mage_Core_Model_Store::roundPrice given the attrValue |
99
|
|
|
* which will return a rounded attrValue, than pass this attrValue to the method self::createTextNode as first parameter |
100
|
|
|
* and the given DOMDocument object as second parameter which will return a DOMNode object |
101
|
|
|
* @param string $attrValue |
102
|
|
|
* @param string $attribute |
103
|
|
|
* @param Mage_Catalog_Model_Product $product |
104
|
|
|
* @param DOMDocument $doc |
105
|
|
|
* @return DOMNode|null |
|
|
|
|
106
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
107
|
|
|
*/ |
108
|
|
|
public function passPrice($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
109
|
|
|
{ |
110
|
|
|
return $this->createTextNode(Mage::getModel('core/store')->roundPrice($attrValue), $doc); |
111
|
|
|
} |
112
|
|
|
/** |
113
|
|
|
* Call the Self::createDecimal method given the attrValue which will return a decimal value if the attriValue is numeric |
114
|
|
|
* otherwise will return null if it null pass it to self::createTextNode will also return node but if return an actual |
115
|
|
|
* decimal value a DOMNode object will be returned |
116
|
|
|
* @param string $attrValue |
117
|
|
|
* @param string $attribute |
118
|
|
|
* @param Mage_Catalog_Model_Product $product |
119
|
|
|
* @param DOMDocument $doc |
120
|
|
|
* @return DOMNode|null |
|
|
|
|
121
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
122
|
|
|
*/ |
123
|
|
|
public function passDecimal($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
return $this->createTextNode($this->createDecimal($attrValue), $doc); |
126
|
|
|
} |
127
|
|
|
/** |
128
|
|
|
* the self::createDateTime method is called given the attrValue if it return a valid date time value then the method |
129
|
|
|
* self::createTextNode will return a DOMNode object when invoked with the attrValue and DOMDocument object, however |
130
|
|
|
* if self::createDateTime method return null than the self::createTextNode will return null |
131
|
|
|
* @param string $attrValue |
132
|
|
|
* @param string $attribute |
133
|
|
|
* @param Mage_Catalog_Model_Product $product |
134
|
|
|
* @param DOMDocument $doc |
135
|
|
|
* @return DOMNode|null |
|
|
|
|
136
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
137
|
|
|
*/ |
138
|
|
|
public function passDate($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
139
|
|
|
{ |
140
|
|
|
return $this->createTextNode($this->createDateTime($attrValue), $doc); |
141
|
|
|
} |
142
|
|
|
/** |
143
|
|
|
* the method self::createInteger will be called given an attrValue it will return an integer value if the attrValue string |
144
|
|
|
* is numeric other null. when it return an integer value this value is then pass to the method self::createTextNode method |
145
|
|
|
* along with the given DOMDocument object in which will return a DOMNode object, but if a null is given to the method |
146
|
|
|
* self:createTextNode it will return null |
147
|
|
|
* @param string $attrValue |
148
|
|
|
* @param string $attribute |
149
|
|
|
* @param Mage_Catalog_Model_Product $product |
150
|
|
|
* @param DOMDocument $doc |
151
|
|
|
* @return DOMNode|null |
|
|
|
|
152
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
153
|
|
|
*/ |
154
|
|
|
public function passInteger($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
155
|
|
|
{ |
156
|
|
|
return $this->createTextNode($this->createInteger($attrValue), $doc); |
157
|
|
|
} |
158
|
|
|
/** |
159
|
|
|
* The Yes/No selector control passes 1 or 0 to represent Yes or No respectively. |
160
|
|
|
* the method self::createBool will be invoked in this method given attrValue if the attribute value is the value |
161
|
|
|
* '1' the return value will be 'true' otherwise the return value will be 'false', this value will then passed to |
162
|
|
|
* the method self::createTextNode then return a DOMNode object given the attrValue and DOMDocument object |
163
|
|
|
* @param string $attrValue |
164
|
|
|
* @param string $attribute |
165
|
|
|
* @param Mage_Catalog_Model_Product $product |
166
|
|
|
* @param DOMDocument $doc |
167
|
|
|
* @return DOMNode|null |
|
|
|
|
168
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
169
|
|
|
*/ |
170
|
|
|
public function passYesNoToBool($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
171
|
|
|
{ |
172
|
|
|
return $this->createTextNode($this->createBool($attrValue), $doc); |
173
|
|
|
} |
174
|
|
|
/** |
175
|
|
|
* return a DOMAttr object containing the client id value |
176
|
|
|
* @param string $attrValue |
177
|
|
|
* @param string $attribute |
178
|
|
|
* @param Mage_Catalog_Model_Product $product |
179
|
|
|
* @param DOMDocument $doc |
180
|
|
|
* @return DOMAttr |
181
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
182
|
|
|
*/ |
183
|
|
|
public function passGsiClientId($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
184
|
|
|
{ |
185
|
|
|
$domAttribute = $this->_getDomAttr($doc, $attribute); |
186
|
|
|
$domAttribute->value = Mage::helper('ebayenterprise_catalog/feed')->getClientId(); |
187
|
|
|
return $domAttribute; |
188
|
|
|
} |
189
|
|
|
/** |
190
|
|
|
* return DOMAttr object containing the operation type for the product. |
191
|
|
|
* Any products created after the last export run should use the new product |
192
|
|
|
* operation type ("Add"). All other products being exported should use |
193
|
|
|
* the default operation type ("Change"). |
194
|
|
|
* @param string $attrValue |
195
|
|
|
* @param string $attribute |
196
|
|
|
* @param Mage_Catalog_Model_Product $product |
197
|
|
|
* @param DOMDocument $doc |
198
|
|
|
* @return DOMAttr |
199
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
200
|
|
|
*/ |
201
|
|
|
public function passOperationType($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
202
|
|
|
{ |
203
|
|
|
$domAttribute = $this->_getDomAttr($doc, $attribute); |
204
|
|
|
$lastRunTime = Mage::helper('ebayenterprise_catalog')->getConfigModel()->pimExportFeedCutoffDate; |
205
|
|
|
$domAttribute->value = strtotime($product->getCreatedAt()) > strtotime($lastRunTime) ? |
206
|
|
|
static::NEW_PRODUCT_OPERATION_TYPE : |
207
|
|
|
static::DEFAULT_OPERATION_TYPE; |
208
|
|
|
return $domAttribute; |
209
|
|
|
} |
210
|
|
|
/** |
211
|
|
|
* return a DOMAttr object containing catalog id value |
212
|
|
|
* @param string $attrValue |
213
|
|
|
* @param string $attribute |
214
|
|
|
* @param Mage_Catalog_Model_Product $product |
215
|
|
|
* @param DOMDocument $doc |
216
|
|
|
* @return DOMAttr |
217
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
218
|
|
|
*/ |
219
|
|
|
public function passCatalogId($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
220
|
|
|
{ |
221
|
|
|
$domAttribute = $this->_getDomAttr($doc, $attribute); |
222
|
|
|
$domAttribute->value = Mage::helper('ebayenterprise_catalog/feed')->getCatalogId(); |
223
|
|
|
return $domAttribute; |
224
|
|
|
} |
225
|
|
|
/** |
226
|
|
|
* return a DOMAttr object containing store id value |
227
|
|
|
* @param string $attrValue |
228
|
|
|
* @param string $attribute |
229
|
|
|
* @param Mage_Catalog_Model_Product $product |
230
|
|
|
* @param DOMDocument $doc |
231
|
|
|
* @return DOMAttr |
232
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
233
|
|
|
*/ |
234
|
|
|
public function passStoreId($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
235
|
|
|
{ |
236
|
|
|
$domAttribute = $this->_getDomAttr($doc, $attribute); |
237
|
|
|
// get the rom store id based on the product's store view. |
238
|
|
|
$domAttribute->value = Mage::helper('ebayenterprise_catalog/feed')->getStoreId($product->getStoreId()); |
239
|
|
|
return $domAttribute; |
240
|
|
|
} |
241
|
|
|
/** |
242
|
|
|
* given a DOMDocument and attribute name normalize the attribute create a DONAttr |
243
|
|
|
* @param DOMDocument $doc |
244
|
|
|
* @param string $nodeAttribute |
245
|
|
|
* @return DOMAttr |
246
|
|
|
*/ |
247
|
|
|
protected function _getDomAttr(DOMDocument $doc, $nodeAttribute) |
248
|
|
|
{ |
249
|
|
|
return $doc->createAttribute(implode('_', array_filter(explode('_', $nodeAttribute)))); |
250
|
|
|
} |
251
|
|
|
|
252
|
|
|
/** |
253
|
|
|
* given a value if it is null return null otherwise a DOMNode |
254
|
|
|
* |
255
|
|
|
* @param string $value |
256
|
|
|
* @param DOMDocument $doc |
257
|
|
|
* @return DOMNode | null |
|
|
|
|
258
|
|
|
*/ |
259
|
|
|
public function createStringNode($value, DOMDocument $doc) |
260
|
|
|
{ |
261
|
|
|
return is_null($value) ? null : $doc->createCDataSection($value); |
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* given a value if it is null return null otherwise a DOMNode |
266
|
|
|
* @param string $value |
267
|
|
|
* @param DOMDocument $doc |
268
|
|
|
* @return DOMNode | null |
|
|
|
|
269
|
|
|
*/ |
270
|
|
|
public function createTextNode($value, DOMDocument $doc) |
271
|
|
|
{ |
272
|
|
|
return is_null($value) ? null : $doc->createTextNode($value); |
273
|
|
|
} |
274
|
|
|
/** |
275
|
|
|
* given a string representing date time if the string is not is not empty return and integer date time |
276
|
|
|
* @param string $value |
277
|
|
|
* @return string | null |
|
|
|
|
278
|
|
|
*/ |
279
|
|
|
public function createDateTime($value) |
280
|
|
|
{ |
281
|
|
|
return !empty($value)? date('c', strtotime($value)) : null; |
282
|
|
|
} |
283
|
|
|
/** |
284
|
|
|
* given a string representing integer value if the string is a numeric value cast it as integer otherwise return null |
285
|
|
|
* @param string $value |
286
|
|
|
* @return int | null |
|
|
|
|
287
|
|
|
*/ |
288
|
|
|
public function createInteger($value) |
289
|
|
|
{ |
290
|
|
|
return is_numeric($value)? (int) $value : null; |
291
|
|
|
} |
292
|
|
|
/** |
293
|
|
|
* given a string representing decimal value if the string is a numeric value cast it as float otherwise return null |
294
|
|
|
* @param string $value |
295
|
|
|
* @return int | null |
|
|
|
|
296
|
|
|
*/ |
297
|
|
|
public function createDecimal($value) |
298
|
|
|
{ |
299
|
|
|
return is_numeric($value)? (float) $value : null; |
300
|
|
|
} |
301
|
|
|
/** |
302
|
|
|
* given a string if it is '1' return 'true' otherwise 'false' |
303
|
|
|
* @param string $value |
304
|
|
|
* @return string |
305
|
|
|
*/ |
306
|
|
|
public function createBool($value) |
307
|
|
|
{ |
308
|
|
|
return ($value === '1')? 'true' : 'false'; |
309
|
|
|
} |
310
|
|
|
/** |
311
|
|
|
* For a given product, look for a configurable product using that product. |
312
|
|
|
* If a product is used by multiple configurable products, only the first |
313
|
|
|
* configurable product will be returned. |
314
|
|
|
* @param Mage_Catalog_Model_Product $product |
315
|
|
|
* @return Mage_Catalog_Model_Product|null Parent configurable product or null of no product is found |
316
|
|
|
*/ |
317
|
|
|
protected function _getParentConfigurableProduct(Mage_Catalog_Model_Product $product) |
318
|
|
|
{ |
319
|
|
|
$parentIds = Mage::getResourceSingleton('catalog/product_type_configurable') |
320
|
|
|
->getParentIdsByChild($product->getId()); |
321
|
|
|
return isset($parentIds[0]) ? Mage::getModel('catalog/product')->load($parentIds[0]) : null; |
322
|
|
|
} |
323
|
|
|
/** |
324
|
|
|
* Get the product to use as the source for style data. The selection of the |
325
|
|
|
* source product will follow these rules: |
326
|
|
|
* - Products used by a configurable product that exists will use the |
327
|
|
|
* configurable product. |
328
|
|
|
* - Products used by a configurable product that does not exist, will have |
329
|
|
|
* no source - return null. This scenario is almost guaranteed to never |
330
|
|
|
* occur by the DB schema and the way the parent product lookup is |
331
|
|
|
* implemented. As it is still technically possible, however, for the |
332
|
|
|
* product to have not been loaded (customization on the load events or |
333
|
|
|
* similar), failing to cover the scenario would cause a catastrophic |
334
|
|
|
* failure of the export and there is minimal logic to cover the scenario, |
335
|
|
|
* handling is included. |
336
|
|
|
* - All other products will get the data from itself. |
337
|
|
|
* @param Mage_Catalog_Model_Product $product Product being exported |
338
|
|
|
* @return Mage_Catalog_Model_Product|null Product to use as source for style data, null of no such product exists |
339
|
|
|
*/ |
340
|
|
|
protected function _getStyleSourceProduct(Mage_Catalog_Model_Product $product) |
341
|
|
|
{ |
342
|
|
|
// only simple products can be used by configurable products so only look |
343
|
|
|
// for the relationships if dealing with a simple product |
344
|
|
|
if ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) { |
345
|
|
|
$parentProduct = $this->_getParentConfigurableProduct($product); |
346
|
|
|
// if a parent product was found, it should be the style source |
347
|
|
|
if ($parentProduct) { |
348
|
|
|
// if the product doesn't exist (no id), there should be no style source |
349
|
|
|
return $parentProduct->getId() ? $parentProduct : null; |
350
|
|
|
} |
351
|
|
|
} |
352
|
|
|
return $product; |
353
|
|
|
} |
354
|
|
|
/** |
355
|
|
|
* if $product is configurable return the result of passSKU |
356
|
|
|
* @param string $attrValue |
357
|
|
|
* @param string $attribute |
358
|
|
|
* @param Mage_Catalog_Model_Product $product |
359
|
|
|
* @param DOMDocument $doc |
360
|
|
|
* @return mixed |
|
|
|
|
361
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
362
|
|
|
*/ |
363
|
|
|
public function passStyleId($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
364
|
|
|
{ |
365
|
|
|
$sourceProduct = $this->_getStyleSourceProduct($product); |
366
|
|
|
return $sourceProduct ? $this->passSKU($sourceProduct->getSku(), 'sku', $sourceProduct, $doc) : null; |
367
|
|
|
} |
368
|
|
|
/** |
369
|
|
|
* if $product is a giftcard, return fragment with the child nodes |
370
|
|
|
* of the GiftCard Element |
371
|
|
|
* @param string $attrValue |
372
|
|
|
* @param string $attribute |
373
|
|
|
* @param Mage_Catalog_Model_Product $product |
374
|
|
|
* @param DOMDocument $doc |
375
|
|
|
* @return mixed |
|
|
|
|
376
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
377
|
|
|
*/ |
378
|
|
|
public function passGiftCard($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
379
|
|
|
{ |
380
|
|
|
if ($product->getTypeId() !== Enterprise_GiftCard_Model_Catalog_Product_Type_Giftcard::TYPE_GIFTCARD) { |
381
|
|
|
return null; |
382
|
|
|
} |
383
|
|
|
$cfg = Mage::helper('ebayenterprise_catalog')->getConfigModel(); |
384
|
|
|
$allowMessage = $product->getUseConfigAllowMessage() ? |
385
|
|
|
$cfg->getConfigData(Enterprise_GiftCard_Model_Giftcard::XML_PATH_ALLOW_MESSAGE) : |
386
|
|
|
$product->getAllowMessage(); |
387
|
|
|
$MessageMaxLength = $allowMessage ? |
388
|
|
|
(int) $cfg->getConfigData(Enterprise_GiftCard_Model_Giftcard::XML_PATH_MESSAGE_MAX_LENGTH) : |
389
|
|
|
0; |
390
|
|
|
$isDigital = $product->getGiftCardType() === Enterprise_GiftCard_Model_Giftcard::TYPE_VIRTUAL ? 'true' : 'false'; |
391
|
|
|
$namespaceUri = $doc->documentElement->namespaceURI; |
392
|
|
|
$frag = $doc->createDocumentFragment(); |
393
|
|
|
$frag->appendChild($doc->createElement('Digital', $isDigital, $namespaceUri)); |
394
|
|
|
$frag->appendChild($doc->createElement('MessageMaxLength', $MessageMaxLength, $namespaceUri)); |
395
|
|
|
$frag->appendChild($doc->createElement('CardFacingDisplayName', (string) $product->getName(), $namespaceUri)); |
396
|
|
|
return $frag; |
397
|
|
|
} |
398
|
|
|
/** |
399
|
|
|
* return a fragment containing a product link element for each |
400
|
|
|
* linked product. |
401
|
|
|
* @param string $attrValue |
402
|
|
|
* @param string $attribute |
403
|
|
|
* @param Mage_Catalog_Model_Product $product |
404
|
|
|
* @param DOMDocument $doc |
405
|
|
|
* @return mixed |
|
|
|
|
406
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
407
|
|
|
*/ |
408
|
|
|
public function passProductLinks($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
409
|
|
|
{ |
410
|
|
|
$frag = $doc->createDocumentFragment(); |
411
|
|
|
$products = $product->getRelatedProducts(); |
412
|
|
|
$index = 0; |
413
|
|
View Code Duplication |
foreach ($products as $rProduct) { |
|
|
|
|
414
|
|
|
$index++; |
415
|
|
|
$this->_addProductLink($frag, 'ES_Accessory', $index, $this->passSKU($rProduct->getSku(), '', $rProduct, $doc)); |
416
|
|
|
} |
417
|
|
|
$products = $product->getUpSellProducts(); |
418
|
|
|
$index = 0; |
419
|
|
View Code Duplication |
foreach ($products as $rProduct) { |
|
|
|
|
420
|
|
|
$index++; |
421
|
|
|
$this->_addProductLink($frag, 'ES_UpSelling', $index, $this->passSKU($rProduct->getSku(), '', $rProduct, $doc)); |
422
|
|
|
} |
423
|
|
|
$products = $product->getCrossSellProducts(); |
424
|
|
|
$index = 0; |
425
|
|
View Code Duplication |
foreach ($products as $rProduct) { |
|
|
|
|
426
|
|
|
$index++; |
427
|
|
|
$this->_addProductLink($frag, 'ES_CrossSelling', $index, $this->passSKU($rProduct->getSku(), '', $rProduct, $doc)); |
428
|
|
|
} |
429
|
|
|
return $frag->hasChildNodes() ? $frag : null; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* build out a product link subtree |
434
|
|
|
* |
435
|
|
|
* @param DOMDocumentFragment $frag |
436
|
|
|
* @param string $type |
437
|
|
|
* @param int $position |
438
|
|
|
* @param DOMNode $value |
439
|
|
|
* @return DOMDocumentFragment |
440
|
|
|
*/ |
441
|
|
|
protected function _addProductLink(DOMDocumentFragment $frag, $type, $position, DOMNode $value) |
442
|
|
|
{ |
443
|
|
|
$frag->appendChild($frag->ownerDocument->createElement('ProductLink')) |
444
|
|
|
->addAttributes(array( |
445
|
|
|
'link_type' => $type, |
446
|
|
|
'operation_type' => 'Add', |
447
|
|
|
'position' => $position, |
448
|
|
|
)) |
449
|
|
|
->createChild('LinkToUniqueID') |
450
|
|
|
->appendChild($value); |
451
|
|
|
return $frag; |
452
|
|
|
} |
453
|
|
|
/** |
454
|
|
|
* return a fragment containing the nodes for the product's category links |
455
|
|
|
* or null if there are none. |
456
|
|
|
* @param string $attrValue |
457
|
|
|
* @param string $attribute |
458
|
|
|
* @param Mage_Catalog_Model_Product $product |
459
|
|
|
* @param DOMDocument $doc |
460
|
|
|
* @return mixed |
|
|
|
|
461
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
462
|
|
|
*/ |
463
|
|
|
public function passCategoryLinks($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
464
|
|
|
{ |
465
|
|
|
$frag = $doc->createDocumentFragment(); |
466
|
|
|
$categories = $product->getCategoryCollection(); |
467
|
|
|
$all = Mage::getResourceModel('catalog/category_collection') |
468
|
|
|
->addAttributeToSelect('name'); |
469
|
|
|
foreach ($categories as $category) { |
470
|
|
|
$pathArr = explode('/', $category->getPath()); |
471
|
|
|
array_walk($pathArr, function (&$val) use ($all) { |
472
|
|
|
$part = $all->getItemById((int) $val); |
473
|
|
|
$val = $part ? $part->getName() : null; |
474
|
|
|
}); |
475
|
|
|
$catString = implode('-', array_filter($pathArr)); |
476
|
|
|
if ($catString) { |
477
|
|
|
$frag->appendChild($doc->createElement('CategoryLink')) |
478
|
|
|
->addAttributes(array('import_mode' => 'Replace')) |
479
|
|
|
->addChild('Name', $catString); |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
return $frag->hasChildNodes() ? $frag : null; |
483
|
|
|
} |
484
|
|
|
/** |
485
|
|
|
* return Y/N when the value evaluates to true/false respectively. |
486
|
|
|
* @param string $attrValue |
487
|
|
|
* @param string $attribute |
488
|
|
|
* @param Mage_Catalog_Model_Product $product |
489
|
|
|
* @param DOMDocument $doc |
490
|
|
|
* @return mixed |
|
|
|
|
491
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
492
|
|
|
*/ |
493
|
|
|
public function passGiftWrap($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
|
|
|
|
494
|
|
|
{ |
495
|
|
|
// when the attribute value is not set, fall back to the configured gift wrap avail flag |
496
|
|
|
if (is_null($attrValue)) { |
497
|
|
|
$attrValue = Mage::getStoreConfigFlag(self::XML_PATH_ALLOW_GIFT_WRAPPING, $product->getStoreId()); |
498
|
|
|
} |
499
|
|
|
return $this->createStringNode($attrValue ? 'Y' : 'N', $doc); |
500
|
|
|
} |
501
|
|
|
/** |
502
|
|
|
* Pass string as an ISO Country code otherwise null. |
503
|
|
|
* @param string $attrValue |
504
|
|
|
* @param string $attribute |
505
|
|
|
* @param Mage_Catalog_Model_Product $product |
506
|
|
|
* @param DOMDocument $doc |
507
|
|
|
* @return DOMNode|null |
|
|
|
|
508
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
509
|
|
|
*/ |
510
|
|
|
public function passIsoCountryCode($attrValue, $attribute, Mage_Catalog_Model_Product $product, DOMDocument $doc) |
511
|
|
|
{ |
512
|
|
|
return Mage::helper('ebayenterprise_catalog')->isValidIsoCountryCode($attrValue) ? |
513
|
|
|
$this->passString($attrValue, $attribute, $product, $doc): null; |
514
|
|
|
} |
515
|
|
|
} |
516
|
|
|
|
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.