Version Notes
DataFeedWatch Release version 0.2.5
Download this release
Release Info
Developer | DataFeedWatch |
Extension | DataFeedWatch_Connector |
Version | 0.2.5 |
Comparing to | |
See all releases |
Code changes from version 0.2.4 to 0.2.5
app/code/local/DataFeedWatch/Connector/Model/Datafeedwatch/Api.php
CHANGED
@@ -1,374 +1,401 @@
|
|
1 |
<?php
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
public function version() {
|
19 |
-
return "0.2.4"; // this needs to be updated in etc/config.xml as well
|
20 |
}
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
$collection->addStoreFilter($this->_getStoreId($options['store']));
|
28 |
-
}
|
29 |
-
|
30 |
-
$apiHelper = Mage::helper('api');
|
31 |
-
$filters = $apiHelper->parseFilters($options, $this->_filtersMap);
|
32 |
-
try {
|
33 |
-
foreach ($filters as $field => $value) {
|
34 |
-
$collection->addFieldToFilter($field, $value);
|
35 |
-
}
|
36 |
-
} catch (Mage_Core_Exception $e) {
|
37 |
-
$this->_fault('filters_invalid', $e->getMessage());
|
38 |
}
|
39 |
-
|
40 |
-
$
|
41 |
-
if (!empty($collection)) {
|
42 |
-
$numberOfProducts = $collection->getSize();
|
43 |
-
}
|
44 |
-
|
45 |
-
return round($numberOfProducts);
|
46 |
}
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
$
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
}
|
87 |
-
|
88 |
-
$
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
}
|
109 |
if (isset($parentIds[0])) {
|
110 |
-
$
|
111 |
}
|
112 |
}
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
|
|
|
|
|
|
125 |
}
|
126 |
-
$product_result[$attribute->getAttributeCode()] = $value;
|
127 |
}
|
|
|
128 |
}
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
|
|
137 |
// if(empty($imageUrl) || $imageUrl == '') {
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
}
|
151 |
-
|
152 |
-
$product_result['product_url'] = $baseUrl . $product->getUrlPath();
|
153 |
-
$product_result['image_url'] = $imageUrl;
|
154 |
-
|
155 |
-
$tmpPrices = array();
|
156 |
-
if($parent_id && $configrable && $product->getVisibility() == 1) {
|
157 |
-
$tmpPrices = $this->getDisplayPrice($parent_id);
|
158 |
-
|
159 |
-
} else {
|
160 |
-
$tmpPrices = $this->getDisplayPrice($product->getId());
|
161 |
-
}
|
162 |
-
if(count($tmpPrices)) {
|
163 |
-
foreach($tmpPrices as $key=>$value) {
|
164 |
-
$product_result[$key] = $value;
|
165 |
-
}
|
166 |
-
}
|
167 |
-
|
168 |
-
|
169 |
-
$inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
|
170 |
-
if (!empty($inventoryStatus)) {
|
171 |
-
$product_result['quantity'] = (int) $inventoryStatus->getQty();
|
172 |
-
$product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
|
173 |
-
}
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
$result[] = $product_result;
|
178 |
}
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
$
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
if ($root && $root->getId() == 1) {
|
190 |
-
$root->setName(Mage::helper('catalog')->__('Root'));
|
191 |
}
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
->addAttributeToSelect('name')
|
196 |
-
->addAttributeToSelect('is_active');
|
197 |
-
|
198 |
-
$tree->addCollectionData($collection, true);
|
199 |
-
|
200 |
-
return $this->_nodeToArray($root);
|
201 |
-
}
|
202 |
-
|
203 |
-
/**
|
204 |
-
* Convert node to array
|
205 |
-
*
|
206 |
-
* @param Varien_Data_Tree_Node $node
|
207 |
-
* @return array
|
208 |
-
*/
|
209 |
-
private function _nodeToArray(Varien_Data_Tree_Node $node) {
|
210 |
-
$children = $node->getChildren();
|
211 |
-
if (!empty($children)) {
|
212 |
-
foreach ($children as $child) {
|
213 |
-
$this->_nodeToArray($child);
|
214 |
}
|
215 |
}
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
);
|
223 |
-
}
|
224 |
-
|
225 |
-
private function _buildCategoryPath($category_id, &$path = array()) {
|
226 |
-
$category = $this->categories[$category_id];
|
227 |
-
|
228 |
-
if ($category['parent_id'] != '0') {
|
229 |
-
$this->_buildCategoryPath($category['parent_id'], $path);
|
230 |
-
}
|
231 |
-
|
232 |
-
if ($category['is_active'] == '1') {
|
233 |
-
$path[] = $category['name'];
|
234 |
}
|
235 |
-
|
236 |
-
|
|
|
|
|
237 |
}
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
'required_options' => 0,
|
251 |
-
'has_options' => 0,
|
252 |
-
'image_label' => 0,
|
253 |
-
'small_image_label' => 0,
|
254 |
-
'thumbnail_label' => 0,
|
255 |
-
'created_at' => 0,
|
256 |
-
'updated_at' => 0,
|
257 |
-
'group_price' => 0,
|
258 |
-
'tier_price' => 0,
|
259 |
-
'msrp_enabled' => 0,
|
260 |
-
'minimal_price' => 0,
|
261 |
-
'msrp_display_actual_price_type' => 0,
|
262 |
-
'msrp' => 0,
|
263 |
-
'enable_googlecheckout' => 0,
|
264 |
-
'is_recurring' => 0,
|
265 |
-
'recurring_profile' => 0,
|
266 |
-
'custom_design' => 0,
|
267 |
-
'custom_design_from' => 0,
|
268 |
-
'custom_design_to' => 0,
|
269 |
-
'custom_layout_update' => 0,
|
270 |
-
'page_layout' => 0,
|
271 |
-
'options_container' => 0,
|
272 |
-
'gift_message_available' => 0,
|
273 |
-
'url_key' => 0,
|
274 |
-
'url_path' => 0,
|
275 |
-
'conopy_diameter' => 0,
|
276 |
-
'image' => 0,
|
277 |
-
'small_image' => 0,
|
278 |
-
'thumbnail' => 0,
|
279 |
-
'media_gallery' => 0,
|
280 |
-
'gallery' => 0,
|
281 |
-
'entity_type_id' => 0,
|
282 |
-
'attribute_set_id' => 0,
|
283 |
-
'entity_id' => 0
|
284 |
-
);
|
285 |
}
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
$prices['special_price'] = 0;
|
309 |
-
$prices['special_price_with_tax'] = 0;
|
310 |
-
$prices['special_from_date'] = '';
|
311 |
-
$prices['special_to_date'] = '';
|
312 |
-
|
313 |
-
$prices['description'] = $product->getDescription();
|
314 |
-
$prices['short_description'] = $product->getShortDescription();
|
315 |
-
|
316 |
-
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
317 |
-
$prices['product_url'] = $baseUrl . $product->getUrlPath();
|
318 |
-
//Setting image
|
319 |
-
$imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
|
320 |
-
$imageTmpArr = explode('.', $imageUrl);
|
321 |
-
$countImgArr = count($imageTmpArr);
|
322 |
-
if(empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
|
323 |
-
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
|
324 |
-
}
|
325 |
-
|
326 |
-
$prices['image_url'] = $imageUrl;
|
327 |
-
|
328 |
-
$specialTmpPrice = $product->getSpecialPrice();
|
329 |
-
|
330 |
-
if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
|
331 |
-
|| empty($product['special_to_date']))) {
|
332 |
-
$prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
|
333 |
-
$prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
|
334 |
-
$prices['special_from_date'] = $product['special_from_date'];
|
335 |
-
$prices['special_to_date'] = $product['special_to_date'];
|
336 |
-
//round($product->getSpecialPrice(), 2);
|
337 |
}
|
338 |
-
|
339 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
340 |
&& array_key_exists($bas_curncy_code, $currencyRates)
|
341 |
&& array_key_exists($cur_curncy_code, $currencyRates)
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
347 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
-
$
|
350 |
-
$prices['
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
}
|
352 |
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
$prices['category_parent_name'] = '';
|
358 |
-
$prices['category_path'] = '';
|
359 |
-
} else {
|
360 |
-
rsort($category_id);
|
361 |
-
$category = $this->categories[$category_id[0]];
|
362 |
-
$prices['category_name'] = $category['name'];
|
363 |
-
$prices['category_parent_name'] = $this->categories[$category['parent_id']]['name'];
|
364 |
-
$prices['category_path'] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
|
365 |
-
}
|
366 |
-
|
367 |
-
return $prices;
|
368 |
}
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
}
|
|
|
|
1 |
<?php
|
2 |
+
|
3 |
+
class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model_Product_Api {
|
4 |
+
|
5 |
+
const STOCK_ITEM_MODEL = 'cataloginventory/stock_item';
|
6 |
+
const CATALOG_PRODUCT_MODEL = 'catalog/product';
|
7 |
+
|
8 |
+
// category
|
9 |
+
const CATALOG_CATEGORY_MODEL = 'catalog/category';
|
10 |
+
const CATEGORY_NAME_FIELD = 'name';
|
11 |
+
const CATEGORY_SEPARATOR = ' > ';
|
12 |
+
public $categories = array();
|
13 |
|
14 |
+
public function __construct() {
|
15 |
+
$this->productCategories = array();
|
16 |
+
ini_set('memory_limit', '1024M');
|
17 |
+
}
|
18 |
+
|
19 |
+
public function version() {
|
20 |
+
return "0.2.5"; // this needs to be updated in etc/config.xml as well
|
21 |
+
}
|
22 |
+
|
23 |
+
public function product_count($options = array()) {
|
24 |
+
$collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
|
25 |
+
->getCollection();
|
26 |
+
|
27 |
+
if (array_key_exists('store', $options)) {
|
28 |
+
$collection->addStoreFilter($this->_getStoreId($options['store']));
|
|
|
|
|
29 |
}
|
30 |
+
|
31 |
+
$apiHelper = Mage::helper('api');
|
32 |
+
$filters = $apiHelper->parseFilters($options, $this->_filtersMap);
|
33 |
+
try {
|
34 |
+
foreach ($filters as $field => $value) {
|
35 |
+
$collection->addFieldToFilter($field, $value);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
}
|
37 |
+
} catch (Mage_Core_Exception $e) {
|
38 |
+
$this->_fault('filters_invalid', $e->getMessage());
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
+
|
41 |
+
$numberOfProducts = 0;
|
42 |
+
if (!empty($collection)) {
|
43 |
+
$numberOfProducts = $collection->getSize();
|
44 |
+
}
|
45 |
+
|
46 |
+
return round($numberOfProducts);
|
47 |
+
}
|
48 |
+
|
49 |
+
public function products($options = array()) {
|
50 |
+
|
51 |
+
if (!array_key_exists('page', $options)) {
|
52 |
+
$options['page'] = 1;
|
53 |
+
}
|
54 |
+
|
55 |
+
if (!array_key_exists('per_page', $options)) {
|
56 |
+
$options['per_page'] = 100;
|
57 |
+
}
|
58 |
+
|
59 |
+
$collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
|
60 |
+
->getCollection()
|
61 |
+
->addAttributeToSelect('*')
|
62 |
+
->setPage($options['page'], $options['per_page']);
|
63 |
+
|
64 |
+
if (array_key_exists('store', $options)) {
|
65 |
+
$collection->addStoreFilter($this->_getStoreId($options['store']));
|
66 |
+
}
|
67 |
+
|
68 |
+
// clear options that are not filters
|
69 |
+
unset($options['page']);
|
70 |
+
unset($options['per_page']);
|
71 |
+
unset($options['store']);
|
72 |
+
|
73 |
+
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
74 |
+
$imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::CATALOG_PRODUCT_MODEL;
|
75 |
+
|
76 |
+
$this->_loadCategories();
|
77 |
+
|
78 |
+
/** @var $apiHelper Mage_Api_Helper_Data */
|
79 |
+
$apiHelper = Mage::helper('api');
|
80 |
+
$filters = $apiHelper->parseFilters($options, $this->_filtersMap);
|
81 |
+
try {
|
82 |
+
foreach ($filters as $field => $value) {
|
83 |
+
$collection->addFieldToFilter($field, $value);
|
84 |
}
|
85 |
+
} catch (Mage_Core_Exception $e) {
|
86 |
+
$this->_fault('filters_invalid', $e->getMessage());
|
87 |
+
}
|
88 |
+
|
89 |
+
$result = array();
|
90 |
+
$product_cache = array();
|
91 |
+
$price_keys = array('price', 'special_price');
|
92 |
+
|
93 |
+
foreach ($collection as $product) {
|
94 |
+
$product_result = array(// Basic product data
|
95 |
+
'product_id' => $product->getId(),
|
96 |
+
'sku' => $product->getSku()
|
97 |
+
);
|
98 |
+
|
99 |
+
$parent_id = '0';
|
100 |
+
$configrable = false;
|
101 |
+
|
102 |
+
if ($product->getTypeId() == "simple") {
|
103 |
+
$parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
|
104 |
+
if (!$parentIds) {
|
105 |
+
$parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
|
|
|
106 |
if (isset($parentIds[0])) {
|
107 |
+
$configrable = true;
|
108 |
}
|
109 |
}
|
110 |
+
if (isset($parentIds[0])) {
|
111 |
+
$parent_id = Mage::getModel('catalog/product')->load($parentIds[0])->getId();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
$product_result['parent_id'] = $parent_id;
|
116 |
+
|
117 |
+
foreach ($product->getAttributes() as $attribute) {
|
118 |
+
if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
|
119 |
+
$value = $product->getData($attribute->getAttributeCode());
|
120 |
+
if (!empty($value)) {
|
121 |
+
if (in_array($attribute->getAttributeCode(), $price_keys)) {
|
122 |
+
$value = sprintf("%.2f", round(trim($attribute->getFrontend()->getValue($product)), 2));
|
123 |
+
} else {
|
124 |
+
$value = trim($attribute->getFrontend()->getValue($product));
|
125 |
}
|
|
|
126 |
}
|
127 |
+
$product_result[$attribute->getAttributeCode()] = $value;
|
128 |
}
|
129 |
+
}
|
130 |
+
|
131 |
+
$product = Mage::getModel('catalog/product')->load($product->getId());
|
132 |
+
// $imageUrl = $product->getImage();
|
133 |
+
// if(empty($imageUrl)) {
|
134 |
+
// $product = Mage::getModel('catalog/product')->load($product->getId());
|
135 |
+
// $imageUrl = $product->getImage();
|
136 |
+
// }
|
137 |
+
//
|
138 |
// if(empty($imageUrl) || $imageUrl == '') {
|
139 |
+
// $imageUrl = $product->getMediaConfig()->getMediaUrl($product->getData('image'));
|
140 |
+
// if(empty($imageUrl) || $imageUrl == '') {
|
141 |
+
// $imageUrl = Mage::helper('catalog/image')->init($product, 'image');
|
142 |
+
// }
|
143 |
+
// } else {
|
144 |
+
// $imageUrl = $imageBaseURL . $imageUrl;
|
145 |
+
// }
|
146 |
+
$imageUrl = (string) $product->getMediaConfig()->getMediaUrl($product->getData('image'));
|
147 |
+
$imageTmpArr = explode('.', $imageUrl);
|
148 |
+
$countImgArr = count($imageTmpArr);
|
149 |
+
if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
|
150 |
+
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
151 |
}
|
152 |
+
|
153 |
+
$product_result['product_url'] = $baseUrl . $product->getUrlPath();
|
154 |
+
$product_result['image_url'] = $imageUrl;
|
155 |
+
|
156 |
+
$tmpPrices = array();
|
157 |
+
if ($parent_id && $configrable && $product->getVisibility() == 1) {
|
158 |
+
$tmpPrices = $this->getDisplayPrice($parent_id);
|
159 |
+
} else {
|
160 |
+
$tmpPrices = $this->getDisplayPrice($product->getId());
|
|
|
|
|
|
|
161 |
}
|
162 |
+
if (count($tmpPrices)) {
|
163 |
+
foreach ($tmpPrices as $key => $value) {
|
164 |
+
$product_result[$key] = $value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
}
|
166 |
}
|
167 |
+
|
168 |
+
|
169 |
+
$inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
|
170 |
+
if (!empty($inventoryStatus)) {
|
171 |
+
$product_result['quantity'] = (int) $inventoryStatus->getQty();
|
172 |
+
$product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
}
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
+
$result[] = $product_result;
|
178 |
}
|
179 |
+
return $result;
|
180 |
+
}
|
181 |
+
|
182 |
+
private function _loadCategories() {
|
183 |
+
$parentId = 1;
|
184 |
+
|
185 |
+
/* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
|
186 |
+
$tree = Mage::getResourceSingleton('catalog/category_tree')->load();
|
187 |
+
$root = $tree->getNodeById($parentId);
|
188 |
+
|
189 |
+
if ($root && $root->getId() == 1) {
|
190 |
+
$root->setName(Mage::helper('catalog')->__('Root'));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
192 |
+
|
193 |
+
$collection = Mage::getModel('catalog/category')->getCollection()
|
194 |
+
->setStoreId($this->_getStoreId(null))
|
195 |
+
->addAttributeToSelect('name')
|
196 |
+
->addAttributeToSelect('is_active');
|
197 |
+
|
198 |
+
$tree->addCollectionData($collection, true);
|
199 |
+
|
200 |
+
return $this->_nodeToArray($root);
|
201 |
+
}
|
202 |
+
|
203 |
+
/**
|
204 |
+
* Convert node to array
|
205 |
+
*
|
206 |
+
* @param Varien_Data_Tree_Node $node
|
207 |
+
* @return array
|
208 |
+
*/
|
209 |
+
private function _nodeToArray(Varien_Data_Tree_Node $node) {
|
210 |
+
$children = $node->getChildren();
|
211 |
+
if (!empty($children)) {
|
212 |
+
foreach ($children as $child) {
|
213 |
+
$this->_nodeToArray($child);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
}
|
215 |
+
}
|
216 |
+
|
217 |
+
$this->categories[$node->getId()] = array(
|
218 |
+
'category_id' => $node->getId(),
|
219 |
+
'parent_id' => $node->getParentId(),
|
220 |
+
'name' => $node->getName(),
|
221 |
+
'is_active' => $node->getIsActive()
|
222 |
+
);
|
223 |
+
}
|
224 |
+
|
225 |
+
private function _buildCategoryPath($category_id, &$path = array()) {
|
226 |
+
$this->productCategories[] = $category_id;
|
227 |
+
$category = $this->categories[$category_id];
|
228 |
+
|
229 |
+
if ($category['parent_id'] != '0') {
|
230 |
+
$this->_buildCategoryPath($category['parent_id'], $path);
|
231 |
+
}
|
232 |
+
|
233 |
+
if ($category['is_active'] == '1') {
|
234 |
+
$path[] = $category['name'];
|
235 |
+
}
|
236 |
+
|
237 |
+
return $path;
|
238 |
+
}
|
239 |
+
|
240 |
+
private function _notNeededFields() {
|
241 |
+
return array(
|
242 |
+
'type' => 0,
|
243 |
+
'type_id' => 0,
|
244 |
+
'set' => 0,
|
245 |
+
'categories' => 0,
|
246 |
+
'websites' => 0,
|
247 |
+
'old_id' => 0,
|
248 |
+
'news_from_date' => 0,
|
249 |
+
'news_to_date' => 0,
|
250 |
+
'category_ids' => 0,
|
251 |
+
'required_options' => 0,
|
252 |
+
'has_options' => 0,
|
253 |
+
'image_label' => 0,
|
254 |
+
'small_image_label' => 0,
|
255 |
+
'thumbnail_label' => 0,
|
256 |
+
'created_at' => 0,
|
257 |
+
'updated_at' => 0,
|
258 |
+
'group_price' => 0,
|
259 |
+
'tier_price' => 0,
|
260 |
+
'msrp_enabled' => 0,
|
261 |
+
'minimal_price' => 0,
|
262 |
+
'msrp_display_actual_price_type' => 0,
|
263 |
+
'msrp' => 0,
|
264 |
+
'enable_googlecheckout' => 0,
|
265 |
+
'is_recurring' => 0,
|
266 |
+
'recurring_profile' => 0,
|
267 |
+
'custom_design' => 0,
|
268 |
+
'custom_design_from' => 0,
|
269 |
+
'custom_design_to' => 0,
|
270 |
+
'custom_layout_update' => 0,
|
271 |
+
'page_layout' => 0,
|
272 |
+
'options_container' => 0,
|
273 |
+
'gift_message_available' => 0,
|
274 |
+
'url_key' => 0,
|
275 |
+
'url_path' => 0,
|
276 |
+
'image' => 0,
|
277 |
+
'small_image' => 0,
|
278 |
+
'thumbnail' => 0,
|
279 |
+
'media_gallery' => 0,
|
280 |
+
'gallery' => 0,
|
281 |
+
'entity_type_id' => 0,
|
282 |
+
'attribute_set_id' => 0,
|
283 |
+
'entity_id' => 0
|
284 |
+
);
|
285 |
+
}
|
286 |
+
|
287 |
+
private function getDisplayPrice($product_id = 0) {
|
288 |
+
|
289 |
+
if ($product_id < 1) {
|
290 |
+
return 0;
|
291 |
+
}
|
292 |
+
$prices = array();
|
293 |
+
|
294 |
+
$product = Mage::getModel('catalog/product')->load($product_id);
|
295 |
+
$store_code = Mage::app()->getStore()->getCode();
|
296 |
+
$_taxHelper = Mage::helper('tax');
|
297 |
+
// Get Currency Code
|
298 |
+
$bas_curncy_code = Mage::app()->getStore()->getBaseCurrencyCode();
|
299 |
+
$cur_curncy_code = Mage::app()->getStore($store_code)->getCurrentCurrencyCode();
|
300 |
+
|
301 |
+
$allowedCurrencies = Mage::getModel('directory/currency')
|
302 |
+
->getConfigAllowCurrencies();
|
303 |
+
$currencyRates = Mage::getModel('directory/currency')
|
304 |
+
->getCurrencyRates($bas_curncy_code, array_values($allowedCurrencies));
|
305 |
+
|
306 |
+
$prices['price_with_tax'] = $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getPrice(), 2); //$product['price'];
|
307 |
+
$prices['price'] = $_taxHelper->getPrice($product, $product->getPrice(), NULL);
|
308 |
+
$prices['special_price'] = 0;
|
309 |
+
$prices['special_price_with_tax'] = 0;
|
310 |
+
$prices['special_from_date'] = '';
|
311 |
+
$prices['special_to_date'] = '';
|
312 |
+
|
313 |
+
$prices['description'] = $product->getDescription();
|
314 |
+
$prices['short_description'] = $product->getShortDescription();
|
315 |
+
|
316 |
+
$baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
|
317 |
+
$prices['product_url'] = $baseUrl . $product->getUrlPath();
|
318 |
+
//Setting image
|
319 |
+
$imageUrl = (string) $product->getMediaConfig()->getMediaUrl($product->getData('image'));
|
320 |
+
$imageTmpArr = explode('.', $imageUrl);
|
321 |
+
$countImgArr = count($imageTmpArr);
|
322 |
+
if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
|
323 |
+
$imageUrl = (string) Mage::helper('catalog/image')->init($product, 'image');
|
324 |
+
}
|
325 |
+
|
326 |
+
$prices['image_url'] = $imageUrl;
|
327 |
+
|
328 |
+
$specialTmpPrice = $product->getSpecialPrice();
|
329 |
+
|
330 |
+
if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
|
331 |
+
|| empty($product['special_to_date']))) {
|
332 |
+
$prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
|
333 |
+
$prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
|
334 |
+
$prices['special_from_date'] = $product['special_from_date'];
|
335 |
+
$prices['special_to_date'] = $product['special_to_date'];
|
336 |
+
//round($product->getSpecialPrice(), 2);
|
337 |
+
}
|
338 |
+
|
339 |
+
if ($bas_curncy_code != $cur_curncy_code
|
340 |
&& array_key_exists($bas_curncy_code, $currencyRates)
|
341 |
&& array_key_exists($cur_curncy_code, $currencyRates)
|
342 |
+
) {
|
343 |
+
if ($prices['special_price'] && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
|
344 |
+
|| empty($product['special_to_date']))) {
|
345 |
+
$prices['special_price_with_tax'] = Mage::helper('directory')->currencyConvert($prices['special_price_with_tax'], $bas_curncy_code, $cur_curncy_code);
|
346 |
+
$prices['special_price'] = Mage::helper('directory')->currencyConvert($prices['special_price'], $bas_curncy_code, $cur_curncy_code);
|
347 |
+
}
|
348 |
+
|
349 |
+
$prices['price_with_tax'] = Mage::helper('directory')->currencyConvert($_finalPriceInclTax, $bas_curncy_code, $cur_curncy_code);
|
350 |
+
$prices['price'] = Mage::helper('directory')->currencyConvert($prices['price'], $bas_curncy_code, $cur_curncy_code);
|
351 |
+
}
|
352 |
+
|
353 |
+
// Getting Additional information
|
354 |
+
$attributes = $product->getAttributes();
|
355 |
+
//$attrs = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
356 |
+
foreach ($attributes as $attribute) {
|
357 |
+
if ($attribute->getIsUserDefined()) { //&& $attribute->getIsVisibleOnFront()
|
358 |
+
if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
|
359 |
+
$value = $product->getData($attribute->getAttributeCode());
|
360 |
+
if (!empty($value)) {
|
361 |
+
$value = trim($attribute->getFrontend()->getValue($product));
|
362 |
+
}
|
363 |
+
$prices[$attribute->getAttributeCode()] = $value;
|
364 |
}
|
365 |
+
}
|
366 |
+
}
|
367 |
+
|
368 |
+
// categories
|
369 |
+
$category_id = $product->getCategoryIds();
|
370 |
+
if (empty($category_id)) {
|
371 |
+
$prices['category_name'] = '';
|
372 |
+
$prices['category_parent_name'] = '';
|
373 |
+
$prices['category_path'] = '';
|
374 |
+
} else {
|
375 |
+
rsort($category_id);
|
376 |
+
$this->productCategories = array();
|
377 |
+
$index = '';
|
378 |
+
foreach ($category_id as $key => $cate) {
|
379 |
+
// if(in_array($cate, $this->productCategories))
|
380 |
+
// continue;
|
381 |
|
382 |
+
$category = $this->categories[$cate];
|
383 |
+
$prices['category_name'.$index] = $category['name'];
|
384 |
+
$prices['category_parent_name'.$index] = $this->categories[$category['parent_id']]['name'];
|
385 |
+
$prices['category_path'.$index] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
|
386 |
+
if($index == '')
|
387 |
+
$index = 1;
|
388 |
+
else
|
389 |
+
$index = $index+1;
|
390 |
}
|
391 |
|
392 |
+
// $category = $this->categories[$category_id[0]];
|
393 |
+
// $prices['category_name'] = $category['name'];
|
394 |
+
// $prices['category_parent_name'] = $this->categories[$category['parent_id']]['name'];
|
395 |
+
// $prices['category_path'] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
}
|
397 |
+
|
398 |
+
return $prices;
|
|
|
|
|
|
|
399 |
}
|
400 |
+
|
401 |
+
}
|
app/code/local/DataFeedWatch/Connector/controllers/TestController.php
CHANGED
@@ -1,28 +1,34 @@
|
|
1 |
<?php
|
|
|
2 |
class DataFeedWatch_Connector_TestController extends Mage_Core_Controller_Front_Action {
|
3 |
-
|
4 |
public function indexAction() {
|
5 |
-
|
6 |
$this->loadLayout();
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
$collection = Mage::getModel('catalog/product')
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
}
|
1 |
<?php
|
2 |
+
|
3 |
class DataFeedWatch_Connector_TestController extends Mage_Core_Controller_Front_Action {
|
4 |
+
|
5 |
public function indexAction() {
|
6 |
+
|
7 |
$this->loadLayout();
|
8 |
+
$this->_title($this->__("DataFeedWatch"));
|
9 |
+
$this->renderLayout();
|
10 |
+
|
11 |
$collection = Mage::getModel('catalog/product')
|
12 |
+
->getCollection()
|
13 |
+
->addAttributeToSelect('*')
|
14 |
+
->setPage(1, 20);
|
15 |
+
$productsAtts = array();
|
16 |
+
foreach ($collection as $product) {
|
17 |
+
$attributes = $product->getAttributes();
|
18 |
+
//$attrs = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
|
19 |
+
foreach ($attributes as $attribute) {
|
20 |
+
if ($attribute->getIsUserDefined()) { //&& $attribute->getIsUserDefined()
|
21 |
+
$value = $product->getData($attribute->getAttributeCode());
|
22 |
+
if (!empty($value)) {
|
23 |
+
$value = trim($attribute->getFrontend()->getValue($product));
|
24 |
+
}
|
25 |
+
$productsAtts[$product->getId()][$attribute->getAttributeCode()] = $value;
|
26 |
+
}
|
27 |
+
}
|
28 |
+
}
|
29 |
+
echo '<pre>';
|
30 |
+
print_r($productsAtts);
|
31 |
+
die('nothing found');
|
32 |
+
}
|
33 |
|
|
|
34 |
}
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>DataFeedWatch_Connector</name>
|
4 |
-
<version>0.2.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
@@ -9,11 +9,11 @@
|
|
9 |
<summary>DataFeedWatch extension for Magento</summary>
|
10 |
<description>DataFeedWatch enables Magento shops to optimize their product data
|
11 |
feed for Google Shopping and other channels</description>
|
12 |
-
<notes>DataFeedWatch Release version 0.2.
|
13 |
<authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
|
14 |
-
<date>2013-
|
15 |
-
<time>
|
16 |
-
<contents><target name="magelocal"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="afe5bd4888768229d5b668f466b770b5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="983d7ad023616b365dce180680e4f9f0"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="
|
17 |
<compatible/>
|
18 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
19 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>DataFeedWatch_Connector</name>
|
4 |
+
<version>0.2.5</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
|
7 |
<channel>community</channel>
|
9 |
<summary>DataFeedWatch extension for Magento</summary>
|
10 |
<description>DataFeedWatch enables Magento shops to optimize their product data
|
11 |
feed for Google Shopping and other channels</description>
|
12 |
+
<notes>DataFeedWatch Release version 0.2.5</notes>
|
13 |
<authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
|
14 |
+
<date>2013-12-10</date>
|
15 |
+
<time>15:04:35</time>
|
16 |
+
<contents><target name="magelocal"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="afe5bd4888768229d5b668f466b770b5"/></dir></dir><dir name="Helper"><file name="Data.php" hash="983d7ad023616b365dce180680e4f9f0"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="d69c88b5cbe3ec18e7ab1ca69dea94d3"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="dfa561302ef7eebe656b229fe275a2eb"/></dir><file name="TestController.php" hash="c90345d01f53e2a6c84eb29083c4263c"/></dir><dir name="etc"><file name="api.xml" hash="84e8b97ba0dc25154ff62126640de989"/><file name="config.xml" hash="a48f183854af578bfc8dfeb3f1648617"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="connector.xml" hash="14d59b8e9f66fba5d7c1f8d0f62dfc3c"/></dir><dir name="template"><dir name="connector"><file name="connectorbackend.phtml" hash="87fbcd16a96af52ce352bc45d9aeab4a"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="d4ef6cebcefd37d5f0546eca344941eb"/></dir></target></contents>
|
17 |
<compatible/>
|
18 |
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
19 |
</package>
|