shoppingfeeder - Version 1.3.11

Version Notes

Updated category fetch and UTC date format

Download this release

Release Info

Developer ShoppingFeeder
Extension shoppingfeeder
Version 1.3.11
Comparing to
See all releases


Code changes from version 1.3.10 to 1.3.11

app/code/community/ShoppingFeeder/Service/Model/Offers.php CHANGED
@@ -1,411 +1,445 @@
1
- <?php
2
-
3
- class ShoppingFeeder_Service_Model_Offers extends Mage_Core_Model_Abstract
4
- {
5
- public function __construct()
6
- {
7
- $this->_init('shoppingfeeder_service/offers');
8
- }
9
-
10
- private function hasParent($product)
11
- {
12
- $parents = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
13
- return !empty($parents);
14
- }
15
-
16
- private function getProductInfo(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product $parent = null, $variantOptions = null, $lastUpdate = null, $priceCurrency, $priceCurrencyRate)
17
- {
18
- /** @var Mage_Catalog_Model_Product_Type_Configurable $configModel */
19
- $configModel = Mage::getModel('catalog/product_type_configurable');
20
-
21
- $p = array();
22
-
23
- $isVariant = !is_null($parent);
24
-
25
- /**
26
- * We only want to pull variants (children of configurable products) that are children, not as standalone products
27
- */
28
- //if this product's parent is visible in catalog and search, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
29
- //we will find this product when we fetch all the children of this parent through a normal iteration, so return nothing
30
- if (!$isVariant && $this->hasParent($product))
31
- {
32
- return array();
33
- }
34
-
35
- if ($isVariant)
36
- {
37
- $variant = $product;
38
- $product = $parent;
39
- }
40
-
41
- $data = $product->getData();
42
-
43
- /* @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
44
- $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
45
-
46
- $attributes = $product->getAttributes();
47
- $manufacturer = '';
48
- $brand = '';
49
-
50
- $usefulAttributes = array();
51
-
52
- /**
53
- * @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute
54
- */
55
- // var_dump("");
56
- // var_dump("");
57
- // var_dump("");
58
- foreach ($attributes as $attribute)
59
- {
60
- $attributeCode = $attribute->getAttributeCode();
61
- $attributeLabel = $attribute->getData('frontend_label');
62
- $value = $attribute->getFrontend()->getValue($product);
63
-
64
- // var_dump($attributeCode. ' : '.print_r($value, true));
65
- // var_dump($attributeLabel. ' : '.print_r($value, true));
66
-
67
- if (preg_match('/^manufacturer$/i', $attributeCode) || preg_match('/^manufacturer$/i', $attributeLabel))
68
- {
69
- $manufacturer = $value;
70
- }
71
-
72
- if (preg_match('/^brand$/i', $attributeCode) || preg_match('/^brand$/i', $attributeLabel))
73
- {
74
- $brand = $value;
75
- }
76
-
77
- /*
78
- if (preg_match('/age/i', $attributeCode) || preg_match('/age/i', $attributeLabel))
79
- {
80
- $usefulAttributes['age'] = $value;
81
- }
82
- if (preg_match('/color|colour/i', $attributeCode) || preg_match('/color|colour/i', $attributeLabel))
83
- {
84
- $usefulAttributes['colour'] = $value;
85
- }
86
- if (preg_match('/size/i', $attributeCode) || preg_match('/size/i', $attributeLabel))
87
- {
88
- $usefulAttributes['size'] = $value;
89
- }
90
- if (preg_match('/gender|sex/i', $attributeCode) || preg_match('/gender|sex/i', $attributeLabel))
91
- {
92
- $usefulAttributes['gender'] = $value;
93
- }
94
- if (preg_match('/material/i', $attributeCode) || preg_match('/material/i', $attributeLabel))
95
- {
96
- $usefulAttributes['material'] = $value;
97
- }
98
- if (preg_match('/pattern/i', $attributeCode) || preg_match('/pattern/i', $attributeLabel))
99
- {
100
- $usefulAttributes['pattern'] = $value;
101
- }
102
- */
103
- if (!is_null($product->getData($attributeCode)) && ((string)$attribute->getFrontend()->getValue($product) != ''))
104
- {
105
- $usefulAttributes[$attributeCode] = $value;
106
- }
107
- }
108
- // exit();
109
-
110
- //category path
111
- $categories = $product->getCategoryIds();
112
-
113
- $categoryPathsToEvaluate = array();
114
- $maxDepth = 0;
115
- $categoryPathToUse = '';
116
-
117
- $storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
118
- $storeRootCategoryName = Mage::getModel('catalog/category')->load($storeRootCategoryId)->getName();
119
-
120
- if (!empty($categories))
121
- {
122
- //we will get all the category paths and then use the most refined, deepest one
123
- foreach ($categories as $rootCategoryId)
124
- {
125
- $depth = 0;
126
- $category_path = '';
127
-
128
- $mageCategoryPath = Mage::getModel('catalog/category')->load($rootCategoryId)->getPath();
129
- $allCategoryIds = explode('/', $mageCategoryPath);
130
- unset($allCategoryIds[0]);
131
-
132
- $categoryPath = '';
133
- /**
134
- * @var Mage_Catalog_Model_Category $category
135
- */
136
- foreach ($allCategoryIds as $categoryId)
137
- {
138
- $depth++;
139
- $category = Mage::getModel('catalog/category')->load($categoryId);
140
- $category_name = $category->getName();
141
- if ($category_name != $storeRootCategoryName)
142
- {
143
- if (!empty($categoryPath))
144
- {
145
- $categoryPath.= ' > ';
146
- }
147
- $categoryPath.= $category_name;
148
- }
149
- }
150
-
151
- $categoryPathsToEvaluate[$rootCategoryId]['path'] = $categoryPath;
152
- $categoryPathsToEvaluate[$rootCategoryId]['depth'] = $depth;
153
-
154
- if ($maxDepth < $depth)
155
- {
156
- $maxDepth = $depth;
157
- $categoryPathToUse = $categoryPath;
158
- }
159
- }
160
- }
161
-
162
- if ($isVariant && isset($variant))
163
- {
164
- $p['internal_variant_id'] = $variant->getId();
165
-
166
- $variantOptionsTitle = array();
167
- $variantPrice = $variantOptions['basePrice'];
168
-
169
- $urlHashParts = array();
170
-
171
- // Collect options applicable to the configurable product
172
- if (isset($variantOptions['refactoredOptions'][$variant->getId()]))
173
- {
174
- foreach ($variantOptions['refactoredOptions'][$variant->getId()] as $attributeCode => $option) {
175
- $variantOptionsTitle[] = $option['value'];
176
-
177
- //add these configured attributes to the set of parent's attributes
178
- $usefulAttributes[$attributeCode] = $option['value'];
179
-
180
- $variantPrice += $option['price'];
181
-
182
- $urlHashParts[] = $option['attributeId'].'='.$option['valueId'];
183
- }
184
- }
185
-
186
- $variantOptionsTitle = implode(' / ', $variantOptionsTitle);
187
- $title = $data['name'] . ' - ' . $variantOptionsTitle;
188
- $sku = $variant->getData('sku');
189
- $price = $variantPrice;
190
- $variantImage = $variant->getImage();
191
-
192
- if (!is_null($variantImage) && !empty($variantImage) && $variantImage!='no_selection')
193
- {
194
- $imageFile = $variant->getImage();
195
- // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
196
- // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
197
- $imageUrl = $p['image_url'] = $variant->getMediaConfig()->getMediaUrl($imageFile);
198
- $imageLocalPath = $variant->getMediaConfig()->getMediaPath($imageFile);
199
- }
200
- else
201
- {
202
- $imageFile = $product->getImage();
203
- // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
204
- // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
205
- $imageUrl = $p['image_url'] = $product->getMediaConfig()->getMediaUrl($imageFile);
206
- $imageLocalPath = $product->getMediaConfig()->getMediaPath($imageFile);
207
- }
208
- $productUrl = $product->getProductUrl().'#'.implode('&', $urlHashParts);
209
- }
210
- else
211
- {
212
- $p['internal_variant_id'] = '';
213
- $title = $data['name'];
214
- $sku = $data['sku'];
215
- $price = $product->getPrice();
216
- $imageFile = $product->getImage();
217
- // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
218
- // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
219
- $imageUrl = $p['image_url'] = $product->getMediaConfig()->getMediaUrl($imageFile);
220
- $imageLocalPath = $product->getMediaConfig()->getMediaPath($imageFile);
221
- $productUrl = $product->getProductUrl();
222
- }
223
-
224
- //if we have previously captured this product and it hasn't changed, don't send through full payload
225
- $wasPreviouslyCaptured = !is_null($lastUpdate) && isset($usefulAttributes['updated_at']) && strtotime($usefulAttributes['updated_at']) < $lastUpdate;
226
- if ($wasPreviouslyCaptured)
227
- {
228
- $p['internal_id'] = $product->getId();
229
- $p['internal_update_time'] = $usefulAttributes['updated_at'];
230
- }
231
- else
232
- {
233
- $p['category'] = $categoryPathToUse;
234
- $p['title'] = $title;
235
- $p['brand'] = ($brand=='No') ? (($manufacturer == 'No') ? '' : $manufacturer) : $brand;
236
- $p['manufacturer'] = ($manufacturer=='No') ? $brand : $manufacturer;
237
- $p['mpn'] = isset($data['model']) ? $data['model'] : $data['sku'];
238
- $p['internal_id'] = $product->getId();
239
- $p['description'] = $data['description'];
240
- $p['short_description'] = $data['short_description'];
241
- $p['weight'] = isset($data['weight']) ? $data['weight'] : 0.00;
242
- $p['sku'] = $sku;
243
- $p['gtin'] = '';
244
-
245
- //$priceModel = $product->getPriceModel();
246
-
247
- //do a currency conversion. if the currency is in base currency, it will be 1.0
248
- $price = $price * $priceCurrencyRate;
249
- $salePrice = $product->getSpecialPrice() * $priceCurrencyRate;
250
-
251
- $p['currency'] = $priceCurrency;
252
- $p['price'] = $price;// Mage::helper('checkout')->convertPrice($priceModel->getPrice($product), false);
253
- $p['sale_price'] = '';
254
- $p['sale_price_effective_date'] = '';
255
- if ($salePrice != $p['price'])
256
- {
257
- $p['sale_price'] = $salePrice;
258
- if ($product->getSpecialFromDate()!=null && $product->getSpecialToDate()!=null)
259
- {
260
- $p['sale_price_effective_date'] = date("c", strtotime($product->getSpecialFromDate())).'/'.date("c", strtotime($product->getSpecialToDate()));
261
- }
262
- }
263
-
264
- $p['delivery_cost'] = 0.00;
265
- $p['tax'] = 0.00;
266
- $p['url'] = $productUrl;
267
- $p['internal_update_time'] = isset($usefulAttributes['updated_at']) ? $usefulAttributes['updated_at'] : '';
268
-
269
- $p['image_url'] = $imageUrl;
270
- if (file_exists($imageLocalPath))
271
- {
272
- $p['image_modified_time'] = date("c", filemtime($imageLocalPath));
273
- }
274
- $p['availability'] = ($stockItem->getIsInStock())?'in stock':'out of stock';
275
- $p['quantity'] = $stockItem->getQty();
276
- $p['condition'] = '';
277
- $p['availability_date'] = '';
278
- $p['attributes'] = $usefulAttributes;
279
- $imageGallery = array();
280
- foreach ($product->getMediaGalleryImages() as $image)
281
- {
282
- $galleryImage = array();
283
- $galleryImage['url'] = $image['url'];
284
- if (file_exists($image['path']))
285
- {
286
- $galleryImage['image_modified_time'] = date("c", filemtime($image['path']));
287
- }
288
- $imageGallery[] = $galleryImage;
289
- }
290
- $p['extra_images'] = $imageGallery;
291
- }
292
-
293
- return $p;
294
- }
295
-
296
- public function getItems($page = null, $numPerPage = 1000, $lastUpdate = null, $store = null, $priceCurrency = null, $priceCurrencyRate = null, $allowVariants = true)
297
- {
298
- /* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection */
299
- $collection = Mage::getModel('catalog/product')->getCollection()
300
- ->addAttributeToSelect('*')
301
- ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
302
- ->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
303
-
304
- /**
305
- * For per-store system
306
- */
307
- if (!is_null($store))
308
- {
309
- $collection->addStoreFilter(Mage::app()->getStore($store)->getId());
310
- }
311
-
312
- if (!is_null($page))
313
- {
314
- $offset = ($page * $numPerPage) - $numPerPage;
315
- $productIds = $collection->getAllIds($numPerPage, $offset);
316
- }
317
- else
318
- {
319
- $productIds = $collection->getAllIds();
320
- }
321
-
322
- $products = array();
323
- foreach ($productIds as $productId)
324
- {
325
- Mage::getModel('catalog/product')->reset();
326
- /** @var Mage_Catalog_Model_Product $product */
327
- $product = Mage::getModel('catalog/product')->load($productId);
328
-
329
- /**
330
- * Get variants, if there are any
331
- * If there are variants that are visible in the catalog, we will skip them when we iterate normally
332
- */
333
-
334
- //if we have a configurable product, capture the variants
335
- if ($product->getTypeId() == 'configurable' && $allowVariants)
336
- {
337
- /** @var Mage_Catalog_Model_Product_Type_Configurable $configModel */
338
- $configModel = Mage::getModel('catalog/product_type_configurable');
339
-
340
- //$children = $configModel->getChildrenIds($product->getId());
341
- $children = $configModel->getUsedProducts(null,$product);
342
-
343
- if (count($children) > 0)
344
- {
345
- $parent = $product;
346
-
347
- //get variant options
348
- $layout = Mage::getSingleton('core/layout');
349
- $block = $layout->createBlock('catalog/product_view_type_configurable');
350
- $block->setProduct($parent);
351
- $variantOptions = Mage::helper('core')->jsonDecode($block->getJsonConfig());
352
-
353
- $variantAttributes = array();
354
- foreach ($variantOptions['attributes'] as $attributeId => $options)
355
- {
356
- $code = $options['code'];
357
- foreach ($options['options'] as $option)
358
- {
359
- $value = $option['label'];
360
- $price = $option['price'];
361
- $valueId = $option['id'];
362
- foreach ($option['products'] as $productId)
363
- {
364
- //$children[] = $productId;
365
- $variantAttributes[$productId][$code]['value'] = $value;
366
- $variantAttributes[$productId][$code]['price'] = $price;
367
- $variantAttributes[$productId][$code]['valueId'] = $valueId;
368
- $variantAttributes[$productId][$code]['attributeId'] = $attributeId;
369
- }
370
- }
371
- }
372
- $variantOptions['refactoredOptions'] = $variantAttributes;
373
-
374
-
375
- foreach ($children as $variant)
376
- {
377
- /** @var Mage_Catalog_Model_Product $variant */
378
- //$variant = Mage::getModel('catalog/product')->load($variantId);
379
-
380
- $productData = $this->getProductInfo($variant, $parent, $variantOptions, $lastUpdate, $priceCurrency, $priceCurrencyRate);
381
- if (!empty($productData))
382
- {
383
- $products[] = $productData;
384
- }
385
- }
386
- }
387
- }
388
- else
389
- {
390
- $productData = $this->getProductInfo($product, null, null, $lastUpdate, $priceCurrency, $priceCurrencyRate);
391
- if (!empty($productData))
392
- {
393
- $products[] = $productData;
394
- }
395
- }
396
- }
397
-
398
- return $products;
399
- }
400
-
401
- public function getItem($itemId, $store = null, $priceCurrency = null, $priceCurrencyRate = null)
402
- {
403
- $products = array();
404
-
405
- $product = Mage::getModel('catalog/product')->load($itemId);
406
-
407
- $products[] = $this->getProductInfo($product, null, null, null, $priceCurrency, $priceCurrencyRate);
408
-
409
- return $products;
410
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
411
  }
1
+ <?php
2
+
3
+ class ShoppingFeeder_Service_Model_Offers extends Mage_Core_Model_Abstract
4
+ {
5
+ public function __construct()
6
+ {
7
+ $this->_init('shoppingfeeder_service/offers');
8
+ }
9
+
10
+ private function hasParent($product)
11
+ {
12
+ $parents = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
13
+ return !empty($parents);
14
+ }
15
+
16
+ private function getProductInfo(Mage_Catalog_Model_Product $product, Mage_Catalog_Model_Product $parent = null, $variantOptions = null, $lastUpdate = null, $priceCurrency, $priceCurrencyRate)
17
+ {
18
+ /** @var Mage_Catalog_Model_Product_Type_Configurable $configModel */
19
+ $configModel = Mage::getModel('catalog/product_type_configurable');
20
+
21
+ $p = array();
22
+
23
+ $isVariant = !is_null($parent);
24
+
25
+ /**
26
+ * We only want to pull variants (children of configurable products) that are children, not as standalone products
27
+ */
28
+ //if this product's parent is visible in catalog and search, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
29
+ //we will find this product when we fetch all the children of this parent through a normal iteration, so return nothing
30
+ if (!$isVariant && $this->hasParent($product))
31
+ {
32
+ return array();
33
+ }
34
+
35
+ if ($isVariant)
36
+ {
37
+ $variant = $product;
38
+ $product = $parent;
39
+ }
40
+
41
+ $data = $product->getData();
42
+
43
+ /* @var Mage_CatalogInventory_Model_Stock_Item $stockItem */
44
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
45
+
46
+ $attributes = $product->getAttributes();
47
+ $manufacturer = '';
48
+ $brand = '';
49
+
50
+ $usefulAttributes = array();
51
+
52
+ /**
53
+ * @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute
54
+ */
55
+ // var_dump("");
56
+ // var_dump("");
57
+ // var_dump("");
58
+ foreach ($attributes as $attribute)
59
+ {
60
+ $attributeCode = $attribute->getAttributeCode();
61
+ $attributeLabel = $attribute->getData('frontend_label');
62
+ $value = $attribute->getFrontend()->getValue($product);
63
+
64
+ // var_dump($attributeCode. ' : '.print_r($value, true));
65
+ // var_dump($attributeLabel. ' : '.print_r($value, true));
66
+
67
+ if (preg_match('/^manufacturer$/i', $attributeCode) || preg_match('/^manufacturer$/i', $attributeLabel))
68
+ {
69
+ $manufacturer = $value;
70
+ }
71
+
72
+ if (preg_match('/^brand$/i', $attributeCode) || preg_match('/^brand$/i', $attributeLabel))
73
+ {
74
+ $brand = $value;
75
+ }
76
+
77
+ /*
78
+ if (preg_match('/age/i', $attributeCode) || preg_match('/age/i', $attributeLabel))
79
+ {
80
+ $usefulAttributes['age'] = $value;
81
+ }
82
+ if (preg_match('/color|colour/i', $attributeCode) || preg_match('/color|colour/i', $attributeLabel))
83
+ {
84
+ $usefulAttributes['colour'] = $value;
85
+ }
86
+ if (preg_match('/size/i', $attributeCode) || preg_match('/size/i', $attributeLabel))
87
+ {
88
+ $usefulAttributes['size'] = $value;
89
+ }
90
+ if (preg_match('/gender|sex/i', $attributeCode) || preg_match('/gender|sex/i', $attributeLabel))
91
+ {
92
+ $usefulAttributes['gender'] = $value;
93
+ }
94
+ if (preg_match('/material/i', $attributeCode) || preg_match('/material/i', $attributeLabel))
95
+ {
96
+ $usefulAttributes['material'] = $value;
97
+ }
98
+ if (preg_match('/pattern/i', $attributeCode) || preg_match('/pattern/i', $attributeLabel))
99
+ {
100
+ $usefulAttributes['pattern'] = $value;
101
+ }
102
+ */
103
+ if (!is_null($product->getData($attributeCode)) && ((string)$attribute->getFrontend()->getValue($product) != ''))
104
+ {
105
+ $usefulAttributes[$attributeCode] = $value;
106
+ }
107
+ }
108
+ // exit();
109
+
110
+ //category path
111
+ $categories = $product->getCategoryIds();
112
+
113
+ $categoryPathsToEvaluate = array();
114
+ $maxDepth = 0;
115
+ $categoryPathToUse = '';
116
+
117
+ $storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
118
+ $storeRootCategoryName = Mage::getModel('catalog/category')->load($storeRootCategoryId)->getName();
119
+
120
+ if (!empty($categories))
121
+ {
122
+
123
+
124
+ /** @var Mage_Catalog_Model_Resource_Category_Collection $categoryCollection */
125
+ $categoryCollection = $product->getCategoryCollection()->addAttributeToSelect('name');
126
+
127
+ $depth = 0;
128
+ foreach($categoryCollection as $cat1){
129
+ $pathIds = explode('/', $cat1->getPath());
130
+ unset($pathIds[0]);
131
+
132
+ $collection = Mage::getModel('catalog/category')->getCollection()
133
+ ->setStoreId(Mage::app()->getStore()->getId())
134
+ ->addAttributeToSelect('name')
135
+ ->addAttributeToSelect('is_active')
136
+ ->addFieldToFilter('entity_id', array('in' => $pathIds));
137
+
138
+ $pathByName = array();
139
+ /** @var Mage_Catalog_Model_Category $cat */
140
+ foreach($collection as $cat){
141
+ if ($cat->getName() != $storeRootCategoryName)
142
+ {
143
+ $pathByName[] = $cat->getName();
144
+ }
145
+ }
146
+
147
+ //take the longest (generally more detailed) path
148
+ $thisDepth = count($pathByName);
149
+ if ($thisDepth > $depth)
150
+ {
151
+ $depth = $thisDepth;
152
+ $categoryPathToUse = implode(' > ', $pathByName);
153
+ }
154
+ }
155
+
156
+ // //we will get all the category paths and then use the most refined, deepest one
157
+ // foreach ($categories as $rootCategoryId)
158
+ // {
159
+ // $depth = 0;
160
+ // $category_path = '';
161
+ //
162
+ // $mageCategoryPath = Mage::getModel('catalog/category')->load($rootCategoryId)->getPath();
163
+ // $allCategoryIds = explode('/', $mageCategoryPath);
164
+ // unset($allCategoryIds[0]);
165
+ //
166
+ // $categoryPath = '';
167
+ // /**
168
+ // * @var Mage_Catalog_Model_Category $category
169
+ // */
170
+ // foreach ($allCategoryIds as $categoryId)
171
+ // {
172
+ // $depth++;
173
+ // $category = Mage::getModel('catalog/category')->load($categoryId);
174
+ // $category_name = $category->getName();
175
+ // if ($category_name != $storeRootCategoryName)
176
+ // {
177
+ // if (!empty($categoryPath))
178
+ // {
179
+ // $categoryPath.= ' > ';
180
+ // }
181
+ // $categoryPath.= $category_name;
182
+ // }
183
+ // }
184
+ //
185
+ // $categoryPathsToEvaluate[$rootCategoryId]['path'] = $categoryPath;
186
+ // $categoryPathsToEvaluate[$rootCategoryId]['depth'] = $depth;
187
+ //
188
+ // if ($maxDepth < $depth)
189
+ // {
190
+ // $maxDepth = $depth;
191
+ // $categoryPathToUse = $categoryPath;
192
+ // }
193
+ // }
194
+ }
195
+
196
+ if ($isVariant && isset($variant))
197
+ {
198
+ $p['internal_variant_id'] = $variant->getId();
199
+
200
+ $variantOptionsTitle = array();
201
+ $variantPrice = $variantOptions['basePrice'];
202
+
203
+ $urlHashParts = array();
204
+
205
+ // Collect options applicable to the configurable product
206
+ if (isset($variantOptions['refactoredOptions'][$variant->getId()]))
207
+ {
208
+ foreach ($variantOptions['refactoredOptions'][$variant->getId()] as $attributeCode => $option) {
209
+ $variantOptionsTitle[] = $option['value'];
210
+
211
+ //add these configured attributes to the set of parent's attributes
212
+ $usefulAttributes[$attributeCode] = $option['value'];
213
+
214
+ $variantPrice += $option['price'];
215
+
216
+ $urlHashParts[] = $option['attributeId'].'='.$option['valueId'];
217
+ }
218
+ }
219
+
220
+ $variantOptionsTitle = implode(' / ', $variantOptionsTitle);
221
+ $title = $data['name'] . ' - ' . $variantOptionsTitle;
222
+ $sku = $variant->getData('sku');
223
+ $price = $variantPrice;
224
+ $variantImage = $variant->getImage();
225
+
226
+ if (!is_null($variantImage) && !empty($variantImage) && $variantImage!='no_selection')
227
+ {
228
+ $imageFile = $variant->getImage();
229
+ // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
230
+ // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
231
+ $imageUrl = $p['image_url'] = $variant->getMediaConfig()->getMediaUrl($imageFile);
232
+ $imageLocalPath = $variant->getMediaConfig()->getMediaPath($imageFile);
233
+ }
234
+ else
235
+ {
236
+ $imageFile = $product->getImage();
237
+ // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
238
+ // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
239
+ $imageUrl = $p['image_url'] = $product->getMediaConfig()->getMediaUrl($imageFile);
240
+ $imageLocalPath = $product->getMediaConfig()->getMediaPath($imageFile);
241
+ }
242
+ $productUrl = $product->getProductUrl().'#'.implode('&', $urlHashParts);
243
+ }
244
+ else
245
+ {
246
+ $p['internal_variant_id'] = '';
247
+ $title = $data['name'];
248
+ $sku = $data['sku'];
249
+ $price = $product->getPrice();
250
+ $imageFile = $product->getImage();
251
+ // $imageUrl = $p['image_url'] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).
252
+ // 'catalog/product/'.preg_replace('/^\//', '', $imageFile);
253
+ $imageUrl = $p['image_url'] = $product->getMediaConfig()->getMediaUrl($imageFile);
254
+ $imageLocalPath = $product->getMediaConfig()->getMediaPath($imageFile);
255
+ $productUrl = $product->getProductUrl();
256
+ }
257
+
258
+ //if we have previously captured this product and it hasn't changed, don't send through full payload
259
+ $wasPreviouslyCaptured = !is_null($lastUpdate) && isset($usefulAttributes['updated_at']) && strtotime($usefulAttributes['updated_at']) < $lastUpdate;
260
+ if ($wasPreviouslyCaptured)
261
+ {
262
+ $p['internal_id'] = $product->getId();
263
+ $p['internal_update_time'] = date("c", strtotime($usefulAttributes['updated_at']));
264
+ }
265
+ else
266
+ {
267
+ $p['category'] = $categoryPathToUse;
268
+ $p['title'] = $title;
269
+ $p['brand'] = ($brand=='No') ? (($manufacturer == 'No') ? '' : $manufacturer) : $brand;
270
+ $p['manufacturer'] = ($manufacturer=='No') ? $brand : $manufacturer;
271
+ $p['mpn'] = isset($data['model']) ? $data['model'] : $data['sku'];
272
+ $p['internal_id'] = $product->getId();
273
+ $p['description'] = $data['description'];
274
+ $p['short_description'] = $data['short_description'];
275
+ $p['weight'] = isset($data['weight']) ? $data['weight'] : 0.00;
276
+ $p['sku'] = $sku;
277
+ $p['gtin'] = '';
278
+
279
+ //$priceModel = $product->getPriceModel();
280
+
281
+ //do a currency conversion. if the currency is in base currency, it will be 1.0
282
+ $price = $price * $priceCurrencyRate;
283
+ $salePrice = $product->getSpecialPrice() * $priceCurrencyRate;
284
+
285
+ $p['currency'] = $priceCurrency;
286
+ $p['price'] = $price;// Mage::helper('checkout')->convertPrice($priceModel->getPrice($product), false);
287
+ $p['sale_price'] = '';
288
+ $p['sale_price_effective_date'] = '';
289
+ if ($salePrice != $p['price'])
290
+ {
291
+ $p['sale_price'] = $salePrice;
292
+ if ($product->getSpecialFromDate()!=null && $product->getSpecialToDate()!=null)
293
+ {
294
+ $p['sale_price_effective_date'] = date("c", strtotime($product->getSpecialFromDate())).'/'.date("c", strtotime($product->getSpecialToDate()));
295
+ }
296
+ }
297
+
298
+ $p['delivery_cost'] = 0.00;
299
+ $p['tax'] = 0.00;
300
+ $p['url'] = $productUrl;
301
+ $p['internal_update_time'] = isset($usefulAttributes['updated_at']) ? date("c", strtotime($usefulAttributes['updated_at'])) : '';
302
+
303
+ $p['image_url'] = $imageUrl;
304
+ if (file_exists($imageLocalPath))
305
+ {
306
+ $p['image_modified_time'] = date("c", filemtime($imageLocalPath));
307
+ }
308
+ $p['availability'] = ($stockItem->getIsInStock())?'in stock':'out of stock';
309
+ $p['quantity'] = $stockItem->getQty();
310
+ $p['condition'] = '';
311
+ $p['availability_date'] = '';
312
+ $p['attributes'] = $usefulAttributes;
313
+ $imageGallery = array();
314
+ foreach ($product->getMediaGalleryImages() as $image)
315
+ {
316
+ $galleryImage = array();
317
+ $galleryImage['url'] = $image['url'];
318
+ if (file_exists($image['path']))
319
+ {
320
+ $galleryImage['image_modified_time'] = date("c", filemtime($image['path']));
321
+ }
322
+ $imageGallery[] = $galleryImage;
323
+ }
324
+ $p['extra_images'] = $imageGallery;
325
+ }
326
+
327
+ return $p;
328
+ }
329
+
330
+ public function getItems($page = null, $numPerPage = 1000, $lastUpdate = null, $store = null, $priceCurrency = null, $priceCurrencyRate = null, $allowVariants = true)
331
+ {
332
+ /* @var Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection */
333
+ $collection = Mage::getModel('catalog/product')->getCollection()
334
+ ->addAttributeToSelect('*')
335
+ ->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
336
+ ->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
337
+
338
+ /**
339
+ * For per-store system
340
+ */
341
+ if (!is_null($store))
342
+ {
343
+ $collection->addStoreFilter(Mage::app()->getStore($store)->getId());
344
+ }
345
+
346
+ if (!is_null($page))
347
+ {
348
+ $offset = ($page * $numPerPage) - $numPerPage;
349
+ $productIds = $collection->getAllIds($numPerPage, $offset);
350
+ }
351
+ else
352
+ {
353
+ $productIds = $collection->getAllIds();
354
+ }
355
+
356
+ $products = array();
357
+ foreach ($productIds as $productId)
358
+ {
359
+ Mage::getModel('catalog/product')->reset();
360
+ /** @var Mage_Catalog_Model_Product $product */
361
+ $product = Mage::getModel('catalog/product')->load($productId);
362
+
363
+ /**
364
+ * Get variants, if there are any
365
+ * If there are variants that are visible in the catalog, we will skip them when we iterate normally
366
+ */
367
+
368
+ //if we have a configurable product, capture the variants
369
+ if ($product->getTypeId() == 'configurable' && $allowVariants)
370
+ {
371
+ /** @var Mage_Catalog_Model_Product_Type_Configurable $configModel */
372
+ $configModel = Mage::getModel('catalog/product_type_configurable');
373
+
374
+ //$children = $configModel->getChildrenIds($product->getId());
375
+ $children = $configModel->getUsedProducts(null,$product);
376
+
377
+ if (count($children) > 0)
378
+ {
379
+ $parent = $product;
380
+
381
+ //get variant options
382
+ $layout = Mage::getSingleton('core/layout');
383
+ $block = $layout->createBlock('catalog/product_view_type_configurable');
384
+ $block->setProduct($parent);
385
+ $variantOptions = Mage::helper('core')->jsonDecode($block->getJsonConfig());
386
+
387
+ $variantAttributes = array();
388
+ foreach ($variantOptions['attributes'] as $attributeId => $options)
389
+ {
390
+ $code = $options['code'];
391
+ foreach ($options['options'] as $option)
392
+ {
393
+ $value = $option['label'];
394
+ $price = $option['price'];
395
+ $valueId = $option['id'];
396
+ foreach ($option['products'] as $productId)
397
+ {
398
+ //$children[] = $productId;
399
+ $variantAttributes[$productId][$code]['value'] = $value;
400
+ $variantAttributes[$productId][$code]['price'] = $price;
401
+ $variantAttributes[$productId][$code]['valueId'] = $valueId;
402
+ $variantAttributes[$productId][$code]['attributeId'] = $attributeId;
403
+ }
404
+ }
405
+ }
406
+ $variantOptions['refactoredOptions'] = $variantAttributes;
407
+
408
+
409
+ foreach ($children as $variant)
410
+ {
411
+ /** @var Mage_Catalog_Model_Product $variant */
412
+ //$variant = Mage::getModel('catalog/product')->load($variantId);
413
+
414
+ $productData = $this->getProductInfo($variant, $parent, $variantOptions, $lastUpdate, $priceCurrency, $priceCurrencyRate);
415
+ if (!empty($productData))
416
+ {
417
+ $products[] = $productData;
418
+ }
419
+ }
420
+ }
421
+ }
422
+ else
423
+ {
424
+ $productData = $this->getProductInfo($product, null, null, $lastUpdate, $priceCurrency, $priceCurrencyRate);
425
+ if (!empty($productData))
426
+ {
427
+ $products[] = $productData;
428
+ }
429
+ }
430
+ }
431
+
432
+ return $products;
433
+ }
434
+
435
+ public function getItem($itemId, $store = null, $priceCurrency = null, $priceCurrencyRate = null)
436
+ {
437
+ $products = array();
438
+
439
+ $product = Mage::getModel('catalog/product')->load($itemId);
440
+
441
+ $products[] = $this->getProductInfo($product, null, null, null, $priceCurrency, $priceCurrencyRate);
442
+
443
+ return $products;
444
+ }
445
  }
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shoppingfeeder</name>
4
- <version>1.3.10</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
@@ -16,11 +16,11 @@ Use ShoppingFeeder to import your Shopify product catalogue, export it to numero
16
  Export to Google, Shopping.com, Nextag, kelkoo, PriceCheck, Shopmania, Fruugo and more!&#xD;
17
  &#xD;
18
  To set up your ShoppingFeeder account and install this extension seamlessly, create an account at: &lt;a href="http://www.shoppingfeeder.com/register"&gt;http://www.shoppingfeeder.com/register&lt;/a&gt;</description>
19
- <notes>Bug fix for product images in different format</notes>
20
  <authors><author><name>ShoppingFeeder</name><user>shoppingfeeder</user><email>support@shoppingfeeder.com</email></author></authors>
21
- <date>2015-07-23</date>
22
- <time>16:09:21</time>
23
- <contents><target name="mageetc"><dir name="modules"><file name="ShoppingFeeder_Service.xml" hash="90b374109c2d1281ddf527f24fa7d914"/></dir></target><target name="magecommunity"><dir name="ShoppingFeeder"><dir name="Service"><dir name="Block"><dir name="Adminhtml"><file name="Service.php" hash="e94d54bc342dc2941753ad635c0454a3"/></dir><file name="Service.php" hash="48874f0e80ce70686b81eb5380e9f498"/></dir><dir name="Controller"><file name="FrontAuth.php" hash="28ed32e1bf3250362911a26869f0e6d7"/></dir><dir name="Helper"><file name="Data.php" hash="17589bd08352e497806bef9884972300"/></dir><dir name="Model"><file name="Auth.php" hash="2cff17b0750ff70695b32524627b2aaf"/><file name="Observer.php" hash="fe8d86049e9fef786b13cec3b3a902ed"/><file name="Offers.php" hash="315155c1ada3e17b4f70cdb36a97e9aa"/><file name="Orders.php" hash="cc3c9f38ae41c11ab7dda0bcb8dd001f"/></dir><dir name="controllers"><file name="AttributesController.php" hash="e937c492f770bc8381a003a080cf878b"/><file name="FeedController.php" hash="92b70af3a048ece99d262480c51aa862"/><file name="OrdersController.php" hash="e0dcf407e15ca212b43ee0015c918675"/><file name="StoresController.php" hash="a29fa0e97299ce764fd66360cbf6632a"/><file name="TestController.php" hash="5138a844cb7cbc8e792df664057bdf9b"/><file name="VersionController.php" hash="47c29bda780633f5b444bc9ed8223861"/></dir><dir name="data"><file name="cacert.pem" hash="380df856e8f789c1af97d0da9a243769"/></dir><dir name="etc"><file name="config.xml" hash="8a1f626994555fbb56b405aa0a7eb081"/><file name="system.xml" hash="9681c74fa8886143197932690616e2dd"/></dir></dir></dir></target></contents>
24
  <compatible/>
25
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
26
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>shoppingfeeder</name>
4
+ <version>1.3.11</version>
5
  <stability>stable</stability>
6
  <license>GNU General Public License (GPL)</license>
7
  <channel>community</channel>
16
  Export to Google, Shopping.com, Nextag, kelkoo, PriceCheck, Shopmania, Fruugo and more!&#xD;
17
  &#xD;
18
  To set up your ShoppingFeeder account and install this extension seamlessly, create an account at: &lt;a href="http://www.shoppingfeeder.com/register"&gt;http://www.shoppingfeeder.com/register&lt;/a&gt;</description>
19
+ <notes>Updated category fetch and UTC date format</notes>
20
  <authors><author><name>ShoppingFeeder</name><user>shoppingfeeder</user><email>support@shoppingfeeder.com</email></author></authors>
21
+ <date>2015-10-10</date>
22
+ <time>18:52:15</time>
23
+ <contents><target name="mageetc"><dir name="modules"><file name="ShoppingFeeder_Service.xml" hash="90b374109c2d1281ddf527f24fa7d914"/></dir></target><target name="magecommunity"><dir name="ShoppingFeeder"><dir name="Service"><dir name="Block"><dir name="Adminhtml"><file name="Service.php" hash="e94d54bc342dc2941753ad635c0454a3"/></dir><file name="Service.php" hash="48874f0e80ce70686b81eb5380e9f498"/></dir><dir name="Controller"><file name="FrontAuth.php" hash="28ed32e1bf3250362911a26869f0e6d7"/></dir><dir name="Helper"><file name="Data.php" hash="17589bd08352e497806bef9884972300"/></dir><dir name="Model"><file name="Auth.php" hash="2cff17b0750ff70695b32524627b2aaf"/><file name="Observer.php" hash="fe8d86049e9fef786b13cec3b3a902ed"/><file name="Offers.php" hash="173b764ba70fd8fb86b6175b01b43717"/><file name="Orders.php" hash="cc3c9f38ae41c11ab7dda0bcb8dd001f"/></dir><dir name="controllers"><file name="AttributesController.php" hash="e937c492f770bc8381a003a080cf878b"/><file name="FeedController.php" hash="92b70af3a048ece99d262480c51aa862"/><file name="OrdersController.php" hash="e0dcf407e15ca212b43ee0015c918675"/><file name="StoresController.php" hash="a29fa0e97299ce764fd66360cbf6632a"/><file name="TestController.php" hash="5138a844cb7cbc8e792df664057bdf9b"/><file name="VersionController.php" hash="47c29bda780633f5b444bc9ed8223861"/></dir><dir name="data"><file name="cacert.pem" hash="380df856e8f789c1af97d0da9a243769"/></dir><dir name="etc"><file name="config.xml" hash="8a1f626994555fbb56b405aa0a7eb081"/><file name="system.xml" hash="9681c74fa8886143197932690616e2dd"/></dir></dir></dir></target></contents>
24
  <compatible/>
25
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
26
  </package>