DataFeedWatch_Connector - Version 0.2.16

Version Notes

DataFeedWatch Release version 0.2.16

Download this release

Release Info

Developer DataFeedWatch
Extension DataFeedWatch_Connector
Version 0.2.16
Comparing to
See all releases


Code changes from version 0.2.12 to 0.2.16

app/code/community/DataFeedWatch/Connector/Block/Adminhtml/Connectorbackend.php CHANGED
@@ -2,6 +2,7 @@
2
 
3
  class DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend extends Mage_Adminhtml_Block_Template {
4
  protected $email = 'magento@datafeedwatch.com';
 
5
 
6
  public function __construct() {
7
  parent::__construct();
@@ -20,4 +21,12 @@ class DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend extends Mage_Admi
20
  public function getRedirectUrl() {
21
  return $this->getUrl('*/*/redirect');
22
  }
 
 
 
 
 
 
 
 
23
  }
2
 
3
  class DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend extends Mage_Adminhtml_Block_Template {
4
  protected $email = 'magento@datafeedwatch.com';
5
+ private static $instance = null;
6
 
7
  public function __construct() {
8
  parent::__construct();
21
  public function getRedirectUrl() {
22
  return $this->getUrl('*/*/redirect');
23
  }
24
+ public static function getInstance()
25
+ {
26
+ if (self::$instance == null) {
27
+ self::$instance = new self;
28
+ }
29
+
30
+ return self::$instance;
31
+ }
32
  }
app/code/community/DataFeedWatch/Connector/Block/Adminhtml/Settings/Edit.php ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DataFeedWatch_Connector_Block_Adminhtml_Settings_Edit extends Mage_Adminhtml_Block_Widget_Form_Container{
4
+
5
+ public function __construct()
6
+ {
7
+ parent::__construct();
8
+ $this->_objectId = 'id';
9
+ $this->_blockGroup = 'connector';
10
+ $this->_controller = 'adminhtml_settings';
11
+ $this->_mode = 'edit';
12
+
13
+ $user = Mage::getModel('api/user')->load('datafeedwatch','username');
14
+
15
+ if ($user->isObjectNew()) {
16
+ $linkUrl = DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend::getInstance()->getCreateUserUrl();
17
+ } else {
18
+ $linkUrl = DataFeedWatch_Connector_Block_Adminhtml_Connectorbackend::getInstance()->getRedirectUrl();
19
+ }
20
+
21
+ $this->removeButton('reset');
22
+ $this->removeButton('back');
23
+
24
+ $this->addButton('goToMyDataFeedWatch', array(
25
+ 'label' => $this->__('Go to my DataFeedWatch'),
26
+ 'onclick' => "setLocation('$linkUrl')",
27
+ ));
28
+ }
29
+ public function getHeaderText()
30
+ {
31
+ return Mage::helper('connector')->__('DataFeedWatch Settings');
32
+ }
33
+
34
+ }
app/code/community/DataFeedWatch/Connector/Block/Adminhtml/Settings/Edit/Form.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DataFeedWatch_Connector_Block_Adminhtml_Settings_Edit_Form extends Mage_Adminhtml_Block_Widget_Form{
4
+
5
+ protected function _prepareForm()
6
+ {
7
+
8
+ $form = new Varien_Data_Form(array(
9
+ 'id' => 'edit_form',
10
+ 'method' => 'post'
11
+ ));
12
+
13
+ $form->setUseContainer(true);
14
+
15
+ $this->setForm($form);
16
+
17
+ $fieldset = $form->addFieldset('attributes', array(
18
+ 'legend' =>Mage::helper('connector')->__('Select Attributes')
19
+ ));
20
+
21
+ $data = array();
22
+
23
+ $required = Mage::helper('connector')->getRequiredAttributes();
24
+ $additional = array();
25
+ if(Mage::getStoreConfig('datafeedwatch/settings/attributes')){
26
+ $additional = Zend_Serializer::unserialize(Mage::getStoreConfig('datafeedwatch/settings/attributes'));
27
+ }
28
+ $data["required_attributes"] = array_keys($required);
29
+ $data["additional_attributes"] = $additional;
30
+
31
+
32
+ $fieldset->addField('required_attributes', 'checkboxes',array(
33
+ "label" => Mage::helper('connector')->__("Required Attributes"),
34
+ "required" => false,
35
+ "options" => $required,
36
+ "name" => "required_attributes[]",
37
+ "disabled" => array_keys($required),
38
+ "ignore" => true
39
+ ));
40
+
41
+ $attributesList = array('0_all'=>'Select/Unselect all');
42
+
43
+ $attributesList = array_merge($attributesList,Mage::helper('connector')->getAttributesList());
44
+
45
+ $fieldset->addField('additional_attributes', 'checkboxes',array(
46
+ "label" => Mage::helper('connector')->__("Optional Attributes"),
47
+ "required" => false,
48
+ "options" => $attributesList,
49
+ "name" => "additional_attributes[]"
50
+ ));
51
+
52
+
53
+
54
+ $form->setValues($data);
55
+
56
+ return parent::_prepareForm();
57
+ }
58
+ }
app/code/community/DataFeedWatch/Connector/Helper/Data.php CHANGED
@@ -1,6 +1,120 @@
1
  <?php
2
  class DataFeedWatch_Connector_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  /**
5
  * Parse filters and format them to be applicable for collection filtration
6
  *
@@ -95,5 +209,287 @@ class DataFeedWatch_Connector_Helper_Data extends Mage_Core_Helper_Abstract
95
  $conditionValue = explode($delimiter, $conditionValue);
96
  }
97
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  }
99
 
1
  <?php
2
  class DataFeedWatch_Connector_Helper_Data extends Mage_Core_Helper_Abstract
3
  {
4
+
5
+ private $_categories;
6
+ private $_productCategories;
7
+
8
+ private $_required_attributes = array(
9
+ "product_id",
10
+ "sku",
11
+ "product_type",
12
+ "parent_id",
13
+ "parent_sku",
14
+ "parent_url",
15
+ "name",
16
+ "description",
17
+ "short_description",
18
+ "weight",
19
+ "status",
20
+ "visibility",
21
+ "country_of_manufacture",
22
+ "price",
23
+ "special_price",
24
+ "special_from_date",
25
+ "special_to_date",
26
+ "tax_class_id",
27
+ "meta_title",
28
+ "meta_keyword",
29
+ "meta_description",
30
+ "gift_wrapping_available",
31
+ "gift_wrapping_price",
32
+ "color",
33
+ "occasion",
34
+ "apparel_type",
35
+ "sleeve_length",
36
+ "fit",
37
+ "size",
38
+ "length",
39
+ "gender",
40
+ "product_url",
41
+ "image_url",
42
+ "price_with_tax",
43
+ "special_price_with_tax",
44
+ "additional_image_url1",
45
+ "additional_image_url2",
46
+ "quantity",
47
+ "is_in_stock",
48
+ 'msrp_enabled',
49
+ 'minimal_price',
50
+ 'msrp_display_actual_price_type',
51
+ 'msrp',
52
+ );
53
+
54
+ private $_excluded_attributes = array(
55
+ 'type' => 0,
56
+ 'type_id' => 0,
57
+ 'set' => 0,
58
+ 'categories' => 0,
59
+ 'websites' => 0,
60
+ 'old_id' => 0,
61
+ 'news_from_date' => 0,
62
+ 'news_to_date' => 0,
63
+ 'category_ids' => 0,
64
+ 'required_options' => 0,
65
+ 'has_options' => 0,
66
+ 'image_label' => 0,
67
+ 'small_image_label' => 0,
68
+ 'thumbnail_label' => 0,
69
+ 'created_at' => 0,
70
+ 'updated_at' => 0,
71
+ 'group_price' => 0,
72
+ 'tier_price' => 0,
73
+ 'enable_googlecheckout' => 0,
74
+ 'is_recurring' => 0,
75
+ 'recurring_profile' => 0,
76
+ 'custom_design' => 0,
77
+ 'custom_design_from' => 0,
78
+ 'custom_design_to' => 0,
79
+ 'custom_layout_update' => 0,
80
+ 'page_layout' => 0,
81
+ 'options_container' => 0,
82
+ 'gift_message_available' => 0,
83
+ 'url_key' => 0,
84
+ 'url_path' => 0,
85
+ 'image' => 0,
86
+ 'small_image' => 0,
87
+ 'thumbnail' => 0,
88
+ 'media_gallery' => 0,
89
+ 'gallery' => 0,
90
+ 'entity_type_id' => 0,
91
+ 'attribute_set_id' => 0,
92
+ 'entity_id' => 0
93
+ );
94
+
95
+ /* currency fields - to prevent multiple calls */
96
+ private $_bas_curncy_code = null;
97
+ private $_cur_curncy_code = null;
98
+ private $_allowedCurrencies = null;
99
+ private $_currencyRates = null;
100
+
101
+ public function getRequiredAttributes(){
102
+ return $this->_required_attributes;
103
+ }
104
+
105
+ public function getAttributesList(){
106
+ $attributesList = array();
107
+ $entityType = Mage::getModel('eav/config')->getEntityType(Mage_Catalog_Model_Product::ENTITY);
108
+ $attributesCollection = Mage::getModel('eav/entity_attribute')->getCollection()
109
+ ->addFieldToFilter('entity_type_id', array('eq' => $entityType->getEntityTypeId()));
110
+ foreach($attributesCollection as $attribute){
111
+ if(!in_array($attribute->getAttributeCode(),$this->_required_attributes)){
112
+ $attributesList[$attribute->getAttributeCode()] = $attribute->getAttributeCode();
113
+ }
114
+ }
115
+ return $attributesList;
116
+ }
117
+
118
  /**
119
  * Parse filters and format them to be applicable for collection filtration
120
  *
209
  $conditionValue = explode($delimiter, $conditionValue);
210
  }
211
  }
212
+
213
+ public function buildCategoryPath($category_id, &$path = array())
214
+ {
215
+ $this->_productCategories[] = $category_id;
216
+ $category = $this->_categories[$category_id];
217
+
218
+ if ($category['parent_id'] != '0') {
219
+ $this->buildCategoryPath($category['parent_id'], $path);
220
+ }
221
+
222
+ if ($category['is_active'] == '1') {
223
+ $path[] = $category['name'];
224
+ }
225
+
226
+ return $path;
227
+ }
228
+
229
+ public function loadCategories()
230
+ {
231
+ $parentId = 1;
232
+
233
+ /* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
234
+ $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
235
+ $root = $tree->getNodeById($parentId);
236
+
237
+ if ($root && $root->getId() == 1) {
238
+ $root->setName(Mage::helper('catalog')->__('Root'));
239
+ }
240
+
241
+ $collection = Mage::getModel('catalog/category')->getCollection()
242
+ ->addAttributeToSelect('name')
243
+ ->addAttributeToSelect('is_active');
244
+
245
+ $tree->addCollectionData($collection, true);
246
+
247
+ return $this->_nodeToArray($root);
248
+ }
249
+
250
+ /**
251
+ * Convert node to array
252
+ *
253
+ * @param Varien_Data_Tree_Node $node
254
+ * @return array
255
+ */
256
+ private function _nodeToArray(Varien_Data_Tree_Node $node)
257
+ {
258
+ $children = $node->getChildren();
259
+ if (!empty($children)) {
260
+ foreach ($children as $child) {
261
+ $this->_nodeToArray($child);
262
+ }
263
+ }
264
+
265
+ $this->_categories[$node->getId()] = array(
266
+ 'category_id' => $node->getId(),
267
+ 'parent_id' => $node->getParentId(),
268
+ 'name' => $node->getName(),
269
+ 'is_active' => $node->getIsActive()
270
+ );
271
+ }
272
+
273
+ public function getCategories(){
274
+ return $this->_categories;
275
+ }
276
+ public function getProductCategories(){
277
+ return $this->_productCategories;
278
+ }
279
+
280
+ public function getExcludedAttributes(){
281
+ return $this->_excluded_attributes;
282
+ }
283
+
284
+ public function getProductAttributes(Mage_Catalog_Model_Product $product)
285
+ {
286
+ $mageObject = new Mage;
287
+
288
+ $prices['description'] = $product->getDescription();
289
+ $prices['short_description'] = $product->getShortDescription();
290
+
291
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
292
+
293
+ if (method_exists($mageObject, 'getEdition') && Mage::getEdition() == Mage::EDITION_ENTERPRISE && Mage::getVersionInfo() >= $this->_supportedEnterprise) {
294
+ $prices['product_url'] = $product->getProductUrl();
295
+ } else {
296
+ $prices['product_url_rewritten'] = $baseUrl . $this->getRewrittenProductUrl($product,null,$this->storeId);
297
+ $prices['product_url'] = $baseUrl . $product->getUrlPath();
298
+ }
299
+
300
+ $prices = $this->addImageToResult($product,$prices);
301
+ $prices = $this->addPricesToResult($product,$prices);
302
+
303
+ // Getting Additional information
304
+ $attributes = $product->getAttributes();
305
+ foreach ($attributes as $attribute) {
306
+
307
+ //only fetch if this is not excluded field
308
+ if (!array_key_exists($attribute->getAttributeCode(), Mage::helper('connector')->getExcludedAttributes())) {
309
+ $value = $product->getData($attribute->getAttributeCode());
310
+
311
+ //only fetch if value is not emtpy
312
+ if (!empty($value)) {
313
+ $value = trim($attribute->getFrontend()->getValue($product));
314
+ }
315
+ $prices[$attribute->getAttributeCode()] = $value;
316
+ }
317
+ }
318
+
319
+ return $prices;
320
+ }
321
+
322
+ /**
323
+ * @param $product Mage_Catalog_Model_Product
324
+ * @param $product_result array
325
+ * @param $parent_product Mage_Catalog_Model_Product
326
+ * @return array
327
+ */
328
+ public function addProductDynamicAttributesToResult($product, $product_result, $parent_product = null, $categoriesData){
329
+ //categories
330
+ if ($parent_product != null) {
331
+ // inherit categories from parent
332
+ $product_result = $this->addProductCategoriesToResult($parent_product,$product_result, $categoriesData);
333
+ } else {
334
+ $product_result = $this->addProductCategoriesToResult($product,$product_result, $categoriesData);
335
+ }
336
+
337
+ //excluded images
338
+ $product_result = $this->addExcludedImagesToResult($product,$product_result);
339
+
340
+ //additional images
341
+ $product_result = $this->addAdditionalImagesToResult($product,$product_result);
342
+
343
+ return $product_result;
344
+ }
345
+
346
+ public function addProductCategoriesToResult($product,$product_result, $categoriesData){
347
+
348
+ $category_id = $product->getCategoryIds();
349
+ if (empty($category_id)) {
350
+ $product_result['category_name'] = '';
351
+ $product_result['category_parent_name'] = '';
352
+ $product_result['category_path'] = '';
353
+ } else {
354
+ rsort($category_id);
355
+ $this->productCategories = array();
356
+ $index = '';
357
+ foreach ($category_id as $key => $cate) {
358
+ if (!in_array($cate, $categoriesData['store_categories'])) {
359
+ continue;
360
+ }
361
+
362
+ $category = $categoriesData['categories'][$cate];
363
+ $product_result['category_name' . $index] = $category['name'];
364
+ $product_result['category_parent_name' . $index] = $categoriesData['categories'][$category['parent_id']]['name'];
365
+
366
+ $categoryPath = Mage::helper('connector')->buildCategoryPath($category['category_id']);
367
+ $product_result['category_path' . $index] = implode(' > ', $categoryPath);
368
+ if ($index == '') {
369
+ $index = 1;
370
+ } else {
371
+ $index++;
372
+ }
373
+ }
374
+ }
375
+
376
+ return $product_result;
377
+
378
+ }
379
+
380
+ public function addAdditionalImagesToResult($product,$product_result){
381
+ $additional_images = $product->getMediaGalleryImages();
382
+ if (count($additional_images) > 0) {
383
+ $i = 1;
384
+ foreach ($additional_images as $images) {
385
+ if ($images->getUrl() != $product_result['image_url']) {
386
+ $product_result['additional_image_url' . $i++] = $images->getUrl();
387
+ }
388
+ }
389
+ }
390
+ return $product_result;
391
+ }
392
+
393
+ public function addExcludedImagesToResult($product,$product_result)
394
+ {
395
+ $allImages = $product->getMediaGallery('images');
396
+
397
+ $i = 1;
398
+ foreach ($allImages as $image) {
399
+ if ($image['disabled']) {
400
+ $excludedUrl = (string)$product->getMediaConfig()->getMediaUrl($image['file']);
401
+ $product_result['image_url_excluded'.$i++] = $excludedUrl;
402
+ }
403
+ }
404
+
405
+ return $product_result;
406
+ }
407
+
408
+ private function prepareCurrencyRates(){
409
+ if($this->_currencyRates===null) {
410
+ $store_code = Mage::app()->getStore()->getCode();
411
+ // Get Currency Code
412
+ $this->_bas_curncy_code = Mage::app()->getStore()->getBaseCurrencyCode();
413
+ $this->_cur_curncy_code = Mage::app()->getStore($store_code)->getCurrentCurrencyCode();
414
+
415
+ $this->_allowedCurrencies = Mage::getModel('directory/currency')
416
+ ->getConfigAllowCurrencies();
417
+ $this->_currencyRates = Mage::getModel('directory/currency')
418
+ ->getCurrencyRates($this->_bas_curncy_code, array_values($this->_allowedCurrencies));
419
+ }
420
+ }
421
+
422
+ public function addPricesToResult($product,$prices){
423
+
424
+ $_taxHelper = Mage::helper('tax');
425
+
426
+ $this->prepareCurrencyRates();
427
+
428
+ $prices['price_with_tax'] = $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getPrice(), 2); //$product['price'];
429
+ $prices['price'] = $_taxHelper->getPrice($product, $product->getPrice(), NULL);
430
+ $prices['special_price'] = 0;
431
+ $prices['special_price_with_tax'] = 0;
432
+ $specialTmpPrice = $product->getSpecialPrice();
433
+
434
+ if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
435
+ || empty($product['special_to_date']))
436
+ ) {
437
+ $prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
438
+ $prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
439
+ $prices['special_from_date'] = $product['special_from_date'];
440
+ $prices['special_to_date'] = $product['special_to_date'];
441
+ }
442
+
443
+ if ($this->_bas_curncy_code != $this->_cur_curncy_code
444
+ && array_key_exists($this->_bas_curncy_code, $this->_currencyRates)
445
+ && array_key_exists($this->_cur_curncy_code, $this->_currencyRates)
446
+ ) {
447
+ if ($prices['special_price'] && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
448
+ || empty($product['special_to_date']))
449
+ ) {
450
+ $prices['special_price_with_tax'] = Mage::helper('directory')->currencyConvert($prices['special_price_with_tax'], $this->_bas_curncy_code, $this->_cur_curncy_code);
451
+ $prices['special_price'] = Mage::helper('directory')->currencyConvert($prices['special_price'], $this->_bas_curncy_code, $this->_cur_curncy_code);
452
+ }
453
+
454
+ $prices['price_with_tax'] = Mage::helper('directory')->currencyConvert($_finalPriceInclTax, $this->_bas_curncy_code, $this->_cur_curncy_code);
455
+ $prices['price'] = Mage::helper('directory')->currencyConvert($prices['price'], $this->_bas_curncy_code, $this->_cur_curncy_code);
456
+ }
457
+ return $prices;
458
+ }
459
+
460
+ public function addImageToResult($product,$prices){
461
+ $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
462
+ $imageTmpArr = explode('.', $imageUrl);
463
+ $countImgArr = count($imageTmpArr);
464
+ if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
465
+ $imageUrl = (string)Mage::helper('catalog/image')->init($product, 'image');
466
+ }
467
+ $prices['image_url'] = $imageUrl;
468
+
469
+ return $prices;
470
+ }
471
+
472
+ public function addStockInfoToResult($product,$product_result){
473
+ $inventoryStatus = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product);
474
+ if (!empty($inventoryStatus)) {
475
+ $product_result['quantity'] = (int)$inventoryStatus->getQty();
476
+ $product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
477
+ }
478
+ return $product_result;
479
+ }
480
+
481
+ public function getRewrittenProductUrl($productObject, $categoryId, $storeId)
482
+ {
483
+ $productId = $productObject->getId();
484
+ $rewrite = Mage::getSingleton('core/url_rewrite');
485
+ $idPath = sprintf('product/%d', $productId);
486
+ if ($categoryId) {
487
+ $idPath = sprintf('%s/%d', $idPath, $categoryId);
488
+ }
489
+ $rewrite->loadByIdPath($idPath);
490
+ return $rewrite->getRequestPath();
491
+ }
492
+
493
+
494
  }
495
 
app/code/community/DataFeedWatch/Connector/Model/Datafeedwatch/Api.php CHANGED
@@ -2,12 +2,7 @@
2
 
3
  class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model_Product_Api
4
  {
5
-
6
- const STOCK_ITEM_MODEL = 'cataloginventory/stock_item';
7
- const CATALOG_PRODUCT_MODEL = 'catalog/product';
8
-
9
  // category
10
- const CATALOG_CATEGORY_MODEL = 'catalog/category';
11
  const CATEGORY_NAME_FIELD = 'name';
12
  const CATEGORY_SEPARATOR = ' > ';
13
  public $categories = array();
@@ -16,6 +11,7 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
16
  public $storeRootCategoryId = 2;
17
  public $storeCategories = array();
18
 
 
19
  protected $_supportedEnterprise = array(
20
  'major' => '1',
21
  'minor' => '13',
@@ -31,36 +27,57 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
31
  ini_set('memory_limit', '1024M');
32
  }
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  public function version()
35
  {
36
  return (string)Mage::getConfig()->getNode('modules/DataFeedWatch_Connector')->version;
37
  }
38
 
 
39
  public function product_count($options = array())
40
  {
41
- $collection = Mage::getModel(self::CATALOG_PRODUCT_MODEL)
42
- ->getCollection();
43
 
44
- if (array_key_exists('store', $options)) {
45
- //convert store code to store id
46
- if (!is_numeric($options['store'])) {
47
- $options['store'] = Mage::app()->getStore($options['store'])->getId();
48
- }
49
-
50
- if ($options['store']) {
51
- $collection->addStoreFilter($options['store']);
52
- } else {
53
- //use default solution
54
- $collection->addStoreFilter($this->_getStoreId($options['store']));
55
- }
56
-
57
- unset($options['store']);
58
- }
59
 
60
  $apiHelper = Mage::helper('api');
61
  if (method_exists($apiHelper, 'parseFilters')) {
62
  $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
63
  } else {
 
64
  $dataFeedWatchHelper = Mage::helper('connector');
65
  $filters = $dataFeedWatchHelper->parseFiltersReplacement($options, $this->_filtersMap);
66
  }
@@ -68,9 +85,15 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
68
  try {
69
  foreach ($filters as $field => $value) {
70
  //ignore status when flat catalog is enabled
71
- if ($field == 'status' && Mage::getStoreConfig('catalog/frontend/flat_catalog_product') == 1) {
72
  continue;
73
  }
 
 
 
 
 
 
74
  $collection->addFieldToFilter($field, $value);
75
  }
76
  } catch (Mage_Core_Exception $e) {
@@ -85,12 +108,12 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
85
  return round($numberOfProducts);
86
  }
87
 
 
88
  public function products($options = array())
89
  {
90
  $mageObject = new Mage;
91
  $this->_versionInfo = Mage::getVersionInfo();
92
 
93
-
94
  if (!array_key_exists('page', $options)) {
95
  $options['page'] = 1;
96
  }
@@ -99,51 +122,35 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
99
  $options['per_page'] = 100;
100
  }
101
 
102
- $collection = Mage::getModel('catalog/product')->getCollection();
103
-
104
- if (array_key_exists('store', $options)) {
105
- //convert store code to store id
106
- if (!is_numeric($options['store'])) {
107
- $options['store'] = Mage::app()->getStore($options['store'])->getId();
108
- }
109
-
110
- if ($options['store']) {
111
- $this->storeId = $options['store'];
112
- Mage::app()->setCurrentStore($this->storeId);
113
-
114
- //reinitialize collection because flat catalog settings may have changed
115
- $collection = Mage::getModel('catalog/product')->getCollection();
116
- $collection->addStoreFilter($this->storeId);
117
- } else {
118
- //use default solution
119
- $collection->addStoreFilter($this->_getStoreId($options['store']));
120
- }
121
-
122
- }
123
 
124
  $collection->addAttributeToSelect('*')
 
125
  ->setPage($options['page'], $options['per_page']);
126
 
 
 
 
 
 
 
127
  /* set current store manually so we get specific store url returned in getBaseUrl */
128
- $this->storeRootCategoryId = Mage::app()->getStore()->getRootCategoryId();
129
- $storeCategoriesCollection = Mage::getModel('catalog/category')->getCollection()
130
- ->addAttributeToSelect('name')
131
  ->addAttributeToSelect('is_active')
132
  ->addPathsFilter('%/' . $this->storeRootCategoryId);
133
 
 
 
134
  foreach ($storeCategoriesCollection as $storeCategory) {
135
  $this->storeCategories[] = $storeCategory->getId();
136
  }
137
 
138
- // clear options that are not filters
139
- unset($options['page']);
140
- unset($options['per_page']);
141
- unset($options['store']);
142
-
143
- $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
144
- $imageBaseURL = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . self::CATALOG_PRODUCT_MODEL;
145
-
146
- $this->_loadCategories();
147
 
148
  /** @var $apiHelper Mage_Api_Helper_Data */
149
  $apiHelper = Mage::helper('api');
@@ -157,8 +164,8 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
157
 
158
  try {
159
  foreach ($filters as $field => $value) {
160
- //ignore status when flat catalog is enabled
161
- if ($field == 'status' && Mage::getStoreConfig('catalog/frontend/flat_catalog_product') == 1) {
162
  continue;
163
  }
164
  $collection->addFieldToFilter($field, $value);
@@ -168,35 +175,84 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
168
  }
169
 
170
  $result = array();
171
- $product_cache = array();
172
  $price_keys = array('price', 'special_price');
173
 
174
  foreach ($collection as $product) {
 
 
 
 
 
 
 
175
  if ($this->storeId) {
176
  $product = Mage::getModel('catalog/product')->setStoreId($this->storeId)->load($product->getId());
177
  } else {
178
  $product = Mage::getModel('catalog/product')->load($product->getId());
179
  }
180
- $parent_id = null;
181
- $parent_sku = null;
182
- $parent_url = null;
183
- $configrable = false;
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  if ($product->getTypeId() == "simple") {
186
  $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
187
  if (!$parentIds) {
188
  $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
189
  if (isset($parentIds[0])) {
190
- $configrable = true;
191
  }
192
  }
193
- if (isset($parentIds[0])) {
194
- //$parent_id = Mage::getModel('catalog/product')->load($parentIds[0])->getId();
195
 
 
196
  $parent_product = Mage::getModel('catalog/product')->load($parentIds[0]);
197
  while (!$parent_product->getId()) {
198
  if (count($parentIds) > 1) {
199
- //parent nt found, remove and rty wth next one
200
  array_shift($parentIds);
201
  $parent_product = Mage::getModel('catalog/product')->load($parentIds[0]);
202
  } else {
@@ -213,7 +269,10 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
213
  $parent_sku = $parent_product->getSku();
214
 
215
  //parent_url
216
- if (method_exists($mageObject, 'getEdition') && Mage::getEdition() == Mage::EDITION_ENTERPRISE && Mage::getVersionInfo() >= $this->_supportedEnterprise) {
 
 
 
217
  $parent_url = $parent_product->getProductUrl();
218
  } else {
219
  $parent_url = $baseUrl . $parent_product->getUrlPath();
@@ -222,61 +281,32 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
222
  }
223
  }
224
 
225
- $product_result = array( // Basic product data
226
- 'product_id' => $product->getId(),
227
- 'sku' => $product->getSku(),
228
- 'product_type' => $product->getTypeId()
229
- );
230
-
231
  $product_result['parent_id'] = $parent_id;
232
  $product_result['parent_sku'] = $parent_sku;
233
  $product_result['parent_url'] = $parent_url;
234
-
235
- foreach ($product->getAttributes() as $attribute) {
236
-
237
- if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
238
- $value = $product->getData($attribute->getAttributeCode());
239
- if (!empty($value)) {
240
- if (in_array($attribute->getAttributeCode(), $price_keys)) {
241
- $value = sprintf("%.2f", round(trim($attribute->getFrontend()->getValue($product)), 2));
242
- } else {
243
- $value = trim($attribute->getFrontend()->getValue($product));
244
- }
245
- }
246
- $product_result[$attribute->getAttributeCode()] = $value;
247
  }
248
- }
249
-
250
- $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
251
- $imageTmpArr = explode('.', $imageUrl);
252
- $countImgArr = count($imageTmpArr);
253
- if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
254
- $imageUrl = (string)Mage::helper('catalog/image')->init($product, 'image');
255
- }
256
-
257
-
258
- if (method_exists($mageObject, 'getEdition') && Mage::getEdition() == Mage::EDITION_ENTERPRISE && Mage::getVersionInfo() >= $this->_supportedEnterprise) {
259
- $product_result['product_url'] = $product->getProductUrl();
260
- } else {
261
- $product_result['product_url'] = $baseUrl . $product->getUrlPath();
262
- }
263
-
264
- $product_result['image_url'] = $imageUrl;
265
-
266
- $tmpPrices = array();
267
- if ($parent_id && $configrable && $product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE) {
268
- $tmpPrices = $this->getDisplayPrice($parent_id);
269
  } else {
270
- $tmpPrices = $this->getDisplayPrice($product);
271
  }
272
 
273
- if (count($tmpPrices)) {
274
- foreach ($tmpPrices as $key => $value) {
 
275
  /*
276
  use child values,
277
  except description, short_description, product_url
278
  and except when value (doesn't exist||is empty) in child
279
- also, use parent image_url if it's empty in child
280
  */
281
  if (!array_key_exists($key, $product_result) || !$product_result[$key] || in_array($key, array('description', 'short_description', 'product_url', 'image_url'))) {
282
  if ($key == 'image_url'
@@ -296,281 +326,169 @@ class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model
296
  }
297
  }
298
 
299
- $inventoryStatus = Mage::getModel(self::STOCK_ITEM_MODEL)->loadByProduct($product);
300
- if (!empty($inventoryStatus)) {
301
- $product_result['quantity'] = (int)$inventoryStatus->getQty();
302
- $product_result['is_in_stock'] = $inventoryStatus->getIsInStock() == '1' ? 1 : 0;
 
 
 
 
 
 
303
  }
304
- $result[] = $product_result;
305
 
306
- }
307
- return $result;
308
- }
 
 
 
 
309
 
310
- private function _loadCategories()
311
- {
312
-
313
- $parentId = 1;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
314
 
315
- /* @var $tree Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Tree */
316
- $tree = Mage::getResourceSingleton('catalog/category_tree')->load();
317
- $root = $tree->getNodeById($parentId);
 
 
 
 
 
 
 
 
318
 
319
- if ($root && $root->getId() == 1) {
320
- $root->setName(Mage::helper('catalog')->__('Root'));
321
- }
 
 
 
 
 
 
 
322
 
323
- $collection = Mage::getModel('catalog/category')->getCollection()
324
- ->addAttributeToSelect('name')
325
- ->addAttributeToSelect('is_active');
326
 
327
- $tree->addCollectionData($collection, true);
328
 
329
- return $this->_nodeToArray($root);
 
330
  }
331
 
332
- /**
333
- * Convert node to array
334
- *
335
- * @param Varien_Data_Tree_Node $node
336
- * @return array
337
- */
338
- private function _nodeToArray(Varien_Data_Tree_Node $node)
339
- {
340
- $children = $node->getChildren();
341
- if (!empty($children)) {
342
- foreach ($children as $child) {
343
- $this->_nodeToArray($child);
344
- }
345
- }
346
 
347
- $this->categories[$node->getId()] = array(
348
- 'category_id' => $node->getId(),
349
- 'parent_id' => $node->getParentId(),
350
- 'name' => $node->getName(),
351
- 'is_active' => $node->getIsActive()
352
- );
353
  }
354
 
355
- private function _buildCategoryPath($category_id, &$path = array())
356
- {
357
- $this->productCategories[] = $category_id;
358
- $category = $this->categories[$category_id];
359
 
360
- if ($category['parent_id'] != '0') {
361
- $this->_buildCategoryPath($category['parent_id'], $path);
362
- }
363
 
364
- if ($category['is_active'] == '1') {
365
- $path[] = $category['name'];
366
  }
367
 
368
- return $path;
369
- }
370
 
371
- private function _notNeededFields()
372
- {
373
- return array(
374
- 'type' => 0,
375
- 'type_id' => 0,
376
- 'set' => 0,
377
- 'categories' => 0,
378
- 'websites' => 0,
379
- 'old_id' => 0,
380
- 'news_from_date' => 0,
381
- 'news_to_date' => 0,
382
- 'category_ids' => 0,
383
- 'required_options' => 0,
384
- 'has_options' => 0,
385
- 'image_label' => 0,
386
- 'small_image_label' => 0,
387
- 'thumbnail_label' => 0,
388
- 'created_at' => 0,
389
- 'updated_at' => 0,
390
- 'group_price' => 0,
391
- 'tier_price' => 0,
392
- 'msrp_enabled' => 0,
393
- 'minimal_price' => 0,
394
- 'msrp_display_actual_price_type' => 0,
395
- 'msrp' => 0,
396
- 'enable_googlecheckout' => 0,
397
- 'is_recurring' => 0,
398
- 'recurring_profile' => 0,
399
- 'custom_design' => 0,
400
- 'custom_design_from' => 0,
401
- 'custom_design_to' => 0,
402
- 'custom_layout_update' => 0,
403
- 'page_layout' => 0,
404
- 'options_container' => 0,
405
- 'gift_message_available' => 0,
406
- 'url_key' => 0,
407
- 'url_path' => 0,
408
- 'image' => 0,
409
- 'small_image' => 0,
410
- 'thumbnail' => 0,
411
- 'media_gallery' => 0,
412
- 'gallery' => 0,
413
- 'entity_type_id' => 0,
414
- 'attribute_set_id' => 0,
415
- 'entity_id' => 0
416
- );
417
  }
418
 
419
- private function getDisplayPrice($product_id)
420
- {
421
- $mageObject = new Mage;
422
- if (!$product_id) {
423
- return 0;
424
- }
425
-
426
- $prices = array();
427
-
428
- if ($product_id instanceof Mage_Catalog_Model_Product) {
429
- $product = $product_id;
430
- } else {
431
- if ($product_id < 1) {
432
- return 0;
433
- }
434
- $product = Mage::getModel('catalog/product')->setStoreId($this->storeId)->load($product_id);
435
  }
436
 
437
- $store_code = Mage::app()->getStore()->getCode();
438
- $_taxHelper = Mage::helper('tax');
439
- // Get Currency Code
440
- $bas_curncy_code = Mage::app()->getStore()->getBaseCurrencyCode();
441
- $cur_curncy_code = Mage::app()->getStore($store_code)->getCurrentCurrencyCode();
442
-
443
- $allowedCurrencies = Mage::getModel('directory/currency')
444
- ->getConfigAllowCurrencies();
445
- $currencyRates = Mage::getModel('directory/currency')
446
- ->getCurrencyRates($bas_curncy_code, array_values($allowedCurrencies));
447
-
448
- $prices['price_with_tax'] = $_finalPriceInclTax = $_taxHelper->getPrice($product, $product->getPrice(), 2); //$product['price'];
449
- $prices['price'] = $_taxHelper->getPrice($product, $product->getPrice(), NULL);
450
- $prices['special_price'] = 0;
451
- $prices['special_price_with_tax'] = 0;
452
- $prices['special_from_date'] = '';
453
- $prices['special_to_date'] = '';
454
-
455
- $prices['description'] = $product->getDescription();
456
- $prices['short_description'] = $product->getShortDescription();
457
-
458
-
459
- $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
460
 
461
- if (method_exists($mageObject, 'getEdition') && Mage::getEdition() == Mage::EDITION_ENTERPRISE && Mage::getVersionInfo() >= $this->_supportedEnterprise) {
462
- $product_result['product_url'] = $product->getProductUrl();
 
 
 
 
 
 
 
 
 
 
 
 
463
  } else {
464
- $product_result['product_url'] = $baseUrl . $product->getUrlPath();
465
- }
466
-
467
- //Setting image
468
- $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
469
- $imageTmpArr = explode('.', $imageUrl);
470
- $countImgArr = count($imageTmpArr);
471
- if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
472
- $imageUrl = (string)Mage::helper('catalog/image')->init($product, 'image');
473
- }
474
- $prices['image_url'] = $imageUrl;
475
-
476
- $additional_images = $product->getMediaGalleryImages();
477
- if (count($additional_images) > 0) {
478
- $i = 1;
479
- foreach ($additional_images as $images) {
480
- if ($images->getUrl() != $prices['image_url'])
481
- $prices['additional_image_url' . $i++] = $images->getUrl();
482
- }
483
  }
484
 
485
- $specialTmpPrice = $product->getSpecialPrice();
486
 
487
- if ($specialTmpPrice && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
488
- || empty($product['special_to_date']))
489
- ) {
490
- $prices['special_price'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), NULL);
491
- $prices['special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
492
- $prices['special_from_date'] = $product['special_from_date'];
493
- $prices['special_to_date'] = $product['special_to_date'];
494
- //round($product->getSpecialPrice(), 2);
495
- }
496
 
497
- if ($bas_curncy_code != $cur_curncy_code
498
- && array_key_exists($bas_curncy_code, $currencyRates)
499
- && array_key_exists($cur_curncy_code, $currencyRates)
500
- ) {
501
- if ($prices['special_price'] && (strtotime(date('Y-m-d H:i:s')) < strtotime($product['special_to_date'])
502
- || empty($product['special_to_date']))
503
- ) {
504
- $prices['special_price_with_tax'] = Mage::helper('directory')->currencyConvert($prices['special_price_with_tax'], $bas_curncy_code, $cur_curncy_code);
505
- $prices['special_price'] = Mage::helper('directory')->currencyConvert($prices['special_price'], $bas_curncy_code, $cur_curncy_code);
506
  }
507
 
508
- $prices['price_with_tax'] = Mage::helper('directory')->currencyConvert($_finalPriceInclTax, $bas_curncy_code, $cur_curncy_code);
509
- $prices['price'] = Mage::helper('directory')->currencyConvert($prices['price'], $bas_curncy_code, $cur_curncy_code);
510
- }
511
 
512
- // Getting Additional information
513
- $attributes = $product->getAttributes();
514
- //$attrs = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
515
- foreach ($attributes as $attribute) {
516
- if ($attribute->getIsUserDefined()) { //&& $attribute->getIsVisibleOnFront()
517
- if (!array_key_exists($attribute->getAttributeCode(), $this->_notNeededFields())) {
518
- $value = $product->getData($attribute->getAttributeCode());
519
- if (!empty($value)) {
520
- $value = trim($attribute->getFrontend()->getValue($product));
521
- }
522
- $prices[$attribute->getAttributeCode()] = $value;
 
 
523
  }
524
- }
525
- }
526
 
527
- // categories
528
- $category_id = $product->getCategoryIds();
529
- if (empty($category_id)) {
530
- $prices['category_name'] = '';
531
- $prices['category_parent_name'] = '';
532
- $prices['category_path'] = '';
533
- } else {
534
- rsort($category_id);
535
- $this->productCategories = array();
536
- $index = '';
537
- foreach ($category_id as $key => $cate) {
538
- // if(in_array($cate, $this->productCategories))
539
- // continue;
540
-
541
- if (!in_array($cate, $this->storeCategories))
542
- continue;
543
 
544
- $category = $this->categories[$cate];
545
- $prices['category_name' . $index] = $category['name'];
546
- $prices['category_parent_name' . $index] = $this->categories[$category['parent_id']]['name'];
547
- $prices['category_path' . $index] = implode(' > ', $this->_buildCategoryPath($category['category_id']));
548
- if ($index == '')
549
- $index = 1;
550
- else
551
- $index = $index + 1;
552
  }
553
  }
554
 
555
- return $prices;
556
- }
557
-
558
- public function stores()
559
- {
560
- foreach (Mage::app()->getWebsites() as $website) {
561
- foreach ($website->getGroups() as $group) {
562
- $stores = $group->getStores();
563
- foreach ($stores as $store) {
564
- $returned[$store->getCode()] = array(
565
- 'Website' => $website->getName(),
566
- 'Store' => $group->getName(),
567
- 'Store View' => $store->getName(),
568
- );
569
- }
570
  }
571
  }
572
- return $returned;
573
- }
574
-
575
 
576
- }
 
 
2
 
3
  class DataFeedWatch_Connector_Model_Datafeedwatch_Api extends Mage_Catalog_Model_Product_Api
4
  {
 
 
 
 
5
  // category
 
6
  const CATEGORY_NAME_FIELD = 'name';
7
  const CATEGORY_SEPARATOR = ' > ';
8
  public $categories = array();
11
  public $storeRootCategoryId = 2;
12
  public $storeCategories = array();
13
 
14
+ /* has been tested with this EE version and works completely */
15
  protected $_supportedEnterprise = array(
16
  'major' => '1',
17
  'minor' => '13',
27
  ini_set('memory_limit', '1024M');
28
  }
29
 
30
+ /* API method */
31
+ public function stores()
32
+ {
33
+ foreach (Mage::app()->getWebsites() as $website) {
34
+ foreach ($website->getGroups() as $group) {
35
+ $stores = $group->getStores();
36
+ foreach ($stores as $store) {
37
+ $returned[$store->getCode()] = array(
38
+ 'Website' => $website->getName(),
39
+ 'Store' => $group->getName(),
40
+ 'Store View' => $store->getName(),
41
+ );
42
+ }
43
+ }
44
+ }
45
+ return $returned;
46
+ }
47
+
48
+ /* API method */
49
+ public function product_ids($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 = $this->_prepareCollection($options);
60
+
61
+ return $collection->getAllIds($options['per_page'], $options['page']);
62
+ }
63
+
64
+ /* API method */
65
  public function version()
66
  {
67
  return (string)Mage::getConfig()->getNode('modules/DataFeedWatch_Connector')->version;
68
  }
69
 
70
+ /* API method */
71
  public function product_count($options = array())
72
  {
 
 
73
 
74
+ $collection = $this->_prepareCollection($options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
  $apiHelper = Mage::helper('api');
77
  if (method_exists($apiHelper, 'parseFilters')) {
78
  $filters = $apiHelper->parseFilters($options, $this->_filtersMap);
79
  } else {
80
+ /* added to support older releases without parseFilters */
81
  $dataFeedWatchHelper = Mage::helper('connector');
82
  $filters = $dataFeedWatchHelper->parseFiltersReplacement($options, $this->_filtersMap);
83
  }
85
  try {
86
  foreach ($filters as $field => $value) {
87
  //ignore status when flat catalog is enabled
88
+ if ($field == 'status' && Mage::helper('catalog/product_flat')->isEnabled()) {
89
  continue;
90
  }
91
+ $fieldToIgnore = array('store', 'page', 'per_page');
92
+ //ignore fields when flat catalog is not enabled
93
+ if (in_array($field, $fieldToIgnore) && !Mage::helper('catalog/product_flat')->isEnabled()) {
94
+ continue;
95
+ }
96
+
97
  $collection->addFieldToFilter($field, $value);
98
  }
99
  } catch (Mage_Core_Exception $e) {
108
  return round($numberOfProducts);
109
  }
110
 
111
+ /* API method */
112
  public function products($options = array())
113
  {
114
  $mageObject = new Mage;
115
  $this->_versionInfo = Mage::getVersionInfo();
116
 
 
117
  if (!array_key_exists('page', $options)) {
118
  $options['page'] = 1;
119
  }
122
  $options['per_page'] = 100;
123
  }
124
 
125
+ $collection = $this->_prepareCollection($options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
  $collection->addAttributeToSelect('*')
128
+ ->joinAttribute('visibility', 'catalog_product/visibility', 'entity_id', null, 'inner', $this->storeId)
129
  ->setPage($options['page'], $options['per_page']);
130
 
131
+ // clear options that are not filters
132
+ unset($options['page']);
133
+ unset($options['per_page']);
134
+ unset($options['store']);
135
+
136
+
137
  /* set current store manually so we get specific store url returned in getBaseUrl */
138
+ $this->storeRootCategoryId = Mage::app()->getStore($this->storeId)->getRootCategoryId();
139
+ $storeCategoriesCollection = Mage::getResourceModel('catalog/category_collection');
140
+ $storeCategoriesCollection->addAttributeToSelect('name')
141
  ->addAttributeToSelect('is_active')
142
  ->addPathsFilter('%/' . $this->storeRootCategoryId);
143
 
144
+ $baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
145
+
146
  foreach ($storeCategoriesCollection as $storeCategory) {
147
  $this->storeCategories[] = $storeCategory->getId();
148
  }
149
 
150
+ /*@TODO: check if we still use this, or we can rely on storeCategories*/
151
+ Mage::helper('connector')->loadCategories();
152
+ $this->categories = Mage::helper('connector')->getCategories();
153
+ $this->productCategories = Mage::helper('connector')->getProductCategories();
 
 
 
 
 
154
 
155
  /** @var $apiHelper Mage_Api_Helper_Data */
156
  $apiHelper = Mage::helper('api');
164
 
165
  try {
166
  foreach ($filters as $field => $value) {
167
+ //ignore status when flat catalog is enabled, as flat catalog does not have status
168
+ if ($field == 'status' && Mage::helper('catalog/product_flat')->isEnabled()) {
169
  continue;
170
  }
171
  $collection->addFieldToFilter($field, $value);
175
  }
176
 
177
  $result = array();
 
178
  $price_keys = array('price', 'special_price');
179
 
180
  foreach ($collection as $product) {
181
+
182
+ //re-setters
183
+ $parent_id = null;
184
+ $parent_sku = null;
185
+ $parent_url = null;
186
+ $configurable = false;
187
+
188
  if ($this->storeId) {
189
  $product = Mage::getModel('catalog/product')->setStoreId($this->storeId)->load($product->getId());
190
  } else {
191
  $product = Mage::getModel('catalog/product')->load($product->getId());
192
  }
 
 
 
 
193
 
194
+ $product_result = array( // Basic product data
195
+ 'product_id' => $product->getId(),
196
+ 'sku' => $product->getSku(),
197
+ 'product_type' => $product->getTypeId()
198
+ );
199
+
200
+ $selected_attributes = $this->synced_fields();
201
+ foreach ($product->getAttributes() as $attribute) {
202
+
203
+ /* ignore excluded attributes */
204
+ if(array_key_exists($attribute->getAttributeCode(), Mage::helper('connector')->getExcludedAttributes())){
205
+ continue;
206
+ }
207
+
208
+ /* only use user-selected fields from DataFeedWatch -> Settings + required attributes */
209
+ if (in_array($attribute->getAttributeCode(),array_merge($selected_attributes,Mage::helper('connector')->getRequiredAttributes()))) {
210
+ $value = $product->getData($attribute->getAttributeCode());
211
+ if (!empty($value)) {
212
+ if (in_array($attribute->getAttributeCode(), $price_keys)) {
213
+ $value = sprintf("%.2f", round(trim($attribute->getFrontend()->getValue($product)), 2));
214
+ } else {
215
+ $value = trim($attribute->getFrontend()->getValue($product));
216
+ }
217
+ }
218
+ $product_result[$attribute->getAttributeCode()] = $value;
219
+ } else {
220
+ Mage::log('attr_code: '.$attribute->getAttributeCode().' was not synced',null,'datafeedwatch_connector.log');
221
+ }
222
+ }
223
+
224
+ /* get product main image file */
225
+ $imageUrl = (string)$product->getMediaConfig()->getMediaUrl($product->getData('image'));
226
+ $imageTmpArr = explode('.', $imageUrl);
227
+ $countImgArr = count($imageTmpArr);
228
+ if (empty($imageUrl) || $imageUrl == '' || !isset($imageUrl) || $countImgArr < 2) {
229
+ $imageUrl = (string)Mage::helper('catalog/image')->init($product, 'image');
230
+ }
231
+ $product_result['image_url'] = $imageUrl;
232
+
233
+ /* get product Url */
234
+ if (method_exists($mageObject, 'getEdition') && Mage::getEdition() == Mage::EDITION_ENTERPRISE && Mage::getVersionInfo() >= $this->_supportedEnterprise) {
235
+ $product_result['product_url'] = $product->getProductUrl();
236
+ } else {
237
+ $product_result['product_url_rewritten'] = $baseUrl . Mage::helper('connector')->getRewrittenProductUrl($product,null,$this->storeId);
238
+ $product_result['product_url'] = $baseUrl . $product->getUrlPath();
239
+ }
240
+
241
+ /* Parent product logic,rewrite attributes with parent values */
242
  if ($product->getTypeId() == "simple") {
243
  $parentIds = Mage::getModel('catalog/product_type_grouped')->getParentIdsByChild($product->getId());
244
  if (!$parentIds) {
245
  $parentIds = Mage::getModel('catalog/product_type_configurable')->getParentIdsByChild($product->getId());
246
  if (isset($parentIds[0])) {
247
+ $configurable = true;
248
  }
249
  }
 
 
250
 
251
+ if (isset($parentIds[0])) {
252
  $parent_product = Mage::getModel('catalog/product')->load($parentIds[0]);
253
  while (!$parent_product->getId()) {
254
  if (count($parentIds) > 1) {
255
+ //parent not found, remove and retry with next one
256
  array_shift($parentIds);
257
  $parent_product = Mage::getModel('catalog/product')->load($parentIds[0]);
258
  } else {
269
  $parent_sku = $parent_product->getSku();
270
 
271
  //parent_url
272
+ if (method_exists($mageObject, 'getEdition')
273
+ && Mage::getEdition() == Mage::EDITION_ENTERPRISE
274
+ && Mage::getVersionInfo() >= $this->_supportedEnterprise)
275
+ {
276
  $parent_url = $parent_product->getProductUrl();
277
  } else {
278
  $parent_url = $baseUrl . $parent_product->getUrlPath();
281
  }
282
  }
283
 
 
 
 
 
 
 
284
  $product_result['parent_id'] = $parent_id;
285
  $product_result['parent_sku'] = $parent_sku;
286
  $product_result['parent_url'] = $parent_url;
287
+ if ($parent_id && $configurable && $product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE) {
288
+ //rewrite to prepare array of fields to overwrite with parent values
289
+ $productAttributes = Mage::helper('connector')->getProductAttributes($parent_product);
290
+
291
+ // get child product visibility
292
+ $visibilityStatuses = Mage_Catalog_Model_Product_Visibility::getOptionArray();
293
+ if (isset($visibilityStatuses[$product->getVisibility()])) {
294
+ $productAttributes['visibility'] = $visibilityStatuses[$product->getVisibility()];
295
+ } else {
296
+ $productAttributes['visibility'] = null;
 
 
 
297
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
298
  } else {
299
+ $productAttributes = Mage::helper('connector')->getProductAttributes($product);
300
  }
301
 
302
+ /* TODO: simplify this */
303
+ if (count($productAttributes)) {
304
+ foreach ($productAttributes as $key => $value) {
305
  /*
306
  use child values,
307
  except description, short_description, product_url
308
  and except when value (doesn't exist||is empty) in child
309
+ also, use parent image_url if(only if) it's empty in child
310
  */
311
  if (!array_key_exists($key, $product_result) || !$product_result[$key] || in_array($key, array('description', 'short_description', 'product_url', 'image_url'))) {
312
  if ($key == 'image_url'
326
  }
327
  }
328
 
329
+ $product_result = Mage::helper('connector')->addStockInfoToResult($product,$product_result);
330
+ // add some parent attributes
331
+ $categoriesData = array(
332
+ 'store_categories' => $this->storeCategories,
333
+ 'categories' => $this->categories,
334
+ );
335
+ if ($parent_id && $configurable && ($product->getVisibility() == Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE)) {
336
+ $product_result = Mage::helper('connector')->addProductDynamicAttributesToResult($product,$product_result, $parent_product, $categoriesData);
337
+ } else {
338
+ $product_result = Mage::helper('connector')->addProductDynamicAttributesToResult($product,$product_result, null, $categoriesData);
339
  }
 
340
 
341
+ /* @TODO: move to helper*/
342
+ // get simple product price with Super Attributes Prices Values
343
+ if ( $product->getTypeId() == "simple" ) {
344
+ // which is child of some parent product
345
+ if ( ! empty( $parent_id ) && gettype( $parent_product ) == 'object') {
346
+ if($parent_product->getTypeInstance(true) instanceof Mage_Catalog_Model_Product_Type_Configurable) {
347
+ // get all configurable attributes
348
 
349
+ if ($parent_product) {
350
+ $attributes = $parent_product->getTypeInstance(true)->getConfigurableAttributes($parent_product);
351
+ }
352
+ // array to keep the price differences for each attribute value
353
+ $pricesByAttributeValues = array();
354
+ // base price of the configurable product
355
+ $basePrice = $parent_product->getFinalPrice();
356
+ // loop through the attributes and get the price adjustments specified in the configurable product admin page
357
+ foreach ($attributes as $attribute) {
358
+ $prices = $attribute->getPrices();
359
+ foreach ($prices as $price) {
360
+ if ($price['is_percent']) {
361
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'] * $basePrice / 100;
362
+ } else {
363
+ $pricesByAttributeValues[$price['value_index']] = (float)$price['pricing_value'];
364
+ }
365
+ }
366
+ }
367
 
368
+ $totalPrice = $basePrice;
369
+ // loop through the configurable attributes
370
+ foreach ($attributes as $attribute) {
371
+ // get the value for a specific attribute for a simple product
372
+ $value = $product->getData($attribute->getProductAttribute()->getAttributeCode());
373
+ // add the price adjustment to the total price of the simple product
374
+ if (isset($pricesByAttributeValues[$value])) {
375
+ $totalPrice += $pricesByAttributeValues[$value];
376
+ }
377
+ }
378
+ $_taxHelper = Mage::helper('tax');
379
 
380
+ $product_result['variant_name'] = $product->getName();
381
+ $product_result['variant_price'] = $totalPrice;
382
+ $product_result['variant_price_with_tax'] = $_taxHelper->getPrice($product, $product->getPrice(), 2);
383
+ $product_result['variant_special_price_with_tax'] = $_taxHelper->getPrice($product, $product->getSpecialPrice(), 2);
384
+ } else {
385
+ // item has a parent becaus it extends Mage_Catalog_Model_Product_Type_Grouped
386
+ // it has no effect on price modifiers, however, so we ignore it
387
+ }
388
+ }
389
+ }
390
 
391
+ $product_result = $this->updatePriceIncludingRules($product,$product_result);
 
 
392
 
393
+ $result[] = $product_result;
394
 
395
+ }
396
+ return $result;
397
  }
398
 
399
+ /* API method */
400
+ public function gmt_offset(){
401
+ // get timezone offset in GMT
402
+ $timeZone = new DateTimeZone(Mage::getStoreConfig('general/locale/timezone'));
403
+ $time = new DateTime('now', $timeZone);
404
+ $offset = (int)($timeZone->getOffset($time) / 3600);
 
 
 
 
 
 
 
 
405
 
406
+ return $offset;
 
 
 
 
 
407
  }
408
 
409
+ public function updatePriceIncludingRules($product,$product_result){
 
 
 
410
 
411
+ $finalPrice = Mage::getModel('catalogrule/rule')->calcProductPriceRule($product,$product->getPrice());
 
 
412
 
413
+ if($finalPrice){
414
+ $product_result['price'] = sprintf("%.2f", round($finalPrice, 2));
415
  }
416
 
 
 
417
 
418
+ return $product_result;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
419
  }
420
 
421
+ /* API Method */
422
+ public function synced_fields(){
423
+ $additional = array();
424
+ if(Mage::getStoreConfig('datafeedwatch/settings/attributes')){
425
+ $additional = Zend_Serializer::unserialize(Mage::getStoreConfig('datafeedwatch/settings/attributes'));
 
 
 
 
 
 
 
 
 
 
 
426
  }
427
 
428
+ return $additional;
429
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
430
 
431
+ private function _prepareCollection($options){
432
+ $attributeModel = Mage::getModel('eav/entity_attribute');
433
+ $attributeId = $attributeModel->getIdByCode('catalog_product', 'ignore_datafeedwatch');
434
+
435
+ if ($attributeId) {
436
+ $collection = Mage::getModel('catalog/product')->getCollection()
437
+ ->addAttributeToFilter(array(
438
+ array('attribute'=>'ignore_datafeedwatch', 'neq'=> 1),
439
+ array('attribute'=>'ignore_datafeedwatch', 'null'=> true),
440
+ ),
441
+ '',
442
+ 'left'
443
+ )
444
+ ;
445
  } else {
446
+ $collection = Mage::getModel('catalog/product')->getCollection();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  }
448
 
 
449
 
450
+ if (array_key_exists('store', $options)) {
 
 
 
 
 
 
 
 
451
 
452
+ //convert store code to store id
453
+ if (!is_numeric($options['store'])) {
454
+ $options['store'] = Mage::app()->getStore($options['store'])->getId();
 
 
 
 
 
 
455
  }
456
 
457
+ if ($options['store']) {
458
+ $this->storeId = $options['store'];
459
+ Mage::app()->setCurrentStore($this->storeId);
460
 
461
+ //reinitialize collection because flat catalog settings may have changed
462
+ if ($attributeId) {
463
+ $collection = Mage::getModel('catalog/product')->getCollection()
464
+ ->addAttributeToFilter(array(
465
+ array('attribute'=>'ignore_datafeedwatch', 'neq'=> 1),
466
+ array('attribute'=>'ignore_datafeedwatch', 'null'=> true),
467
+ ),
468
+ '',
469
+ 'left'
470
+ )
471
+ ;
472
+ } else {
473
+ $collection = Mage::getModel('catalog/product')->getCollection();
474
  }
 
 
475
 
476
+ $collection->addStoreFilter($this->storeId);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
477
 
478
+ } else {
479
+ //use default solution
480
+ $collection->addStoreFilter($this->_getStoreId($options['store']));
 
 
 
 
 
481
  }
482
  }
483
 
484
+ if (array_key_exists('status', $options)) {
485
+ if($options['status'] == Mage_Catalog_Model_Product_Status::STATUS_DISABLED) {
486
+ $collection->addAttributeToFilter('status', 0);
487
+ } elseif($options['status'] == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
488
+ $collection->addAttributeToFilter('status', 1);
 
 
 
 
 
 
 
 
 
 
489
  }
490
  }
 
 
 
491
 
492
+ return $collection;
493
+ }
494
+ }
app/code/community/DataFeedWatch/Connector/controllers/Adminhtml/ConnectorbackendController.php CHANGED
@@ -13,6 +13,15 @@ class DataFeedWatch_Connector_Adminhtml_ConnectorbackendController extends Mage_
13
  protected $redirect_url = 'https://my.datafeedwatch.com/';
14
 
15
  public function indexAction() {
 
 
 
 
 
 
 
 
 
16
  $this->loadLayout();
17
  $this->_title($this->__("DataFeedWatch"));
18
  $this->renderLayout();
@@ -29,8 +38,15 @@ class DataFeedWatch_Connector_Adminhtml_ConnectorbackendController extends Mage_
29
  //send the api key to DFW
30
  file_get_contents($this->_registerUrl($api_key));
31
 
32
- //Create Api User
33
- $user = $this->_createApiUser($api_key);
 
 
 
 
 
 
 
34
 
35
  //Assign Api User to the Api Role
36
  $user->setRoleId($role->getId())->setUserId($user->getId());
@@ -94,4 +110,26 @@ class DataFeedWatch_Connector_Adminhtml_ConnectorbackendController extends Mage_
94
  $user->save();
95
  return $user;
96
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  }
13
  protected $redirect_url = 'https://my.datafeedwatch.com/';
14
 
15
  public function indexAction() {
16
+ $ready = Mage::getStoreConfig('datafeedwatch/settings/ready');
17
+ if(!$ready){
18
+ Mage::getSingleton('adminhtml/session')
19
+ ->addError(Mage::helper('connector')
20
+ ->__('You need to pick your attributes and save your attribute settings before you can access My DataFeedWatch.'));
21
+
22
+ $this->_redirect('*/adminhtml_settings/index');
23
+ return;
24
+ }
25
  $this->loadLayout();
26
  $this->_title($this->__("DataFeedWatch"));
27
  $this->renderLayout();
38
  //send the api key to DFW
39
  file_get_contents($this->_registerUrl($api_key));
40
 
41
+ //Get Api User
42
+ $user = $this->getUser();
43
+ if ($user->getId()) {
44
+ //Update Api User
45
+ $user = $this->_updateApiUser($api_key, $user);
46
+ } else {
47
+ //Create Api User
48
+ $user = $this->_createApiUser($api_key);
49
+ }
50
 
51
  //Assign Api User to the Api Role
52
  $user->setRoleId($role->getId())->setUserId($user->getId());
110
  $user->save();
111
  return $user;
112
  }
113
+
114
+ /**
115
+ * @param $api_key string
116
+ * @param $user Mage_Api_Model_User
117
+ *
118
+ * @return Mage_Api_Model_User
119
+ */
120
+
121
+ private function _updateApiUser($api_key, $user) {
122
+ $data = array(
123
+ 'username' => $this->username,
124
+ 'firstname' => $this->firstname,
125
+ 'lastname' => $this->lastname,
126
+ 'is_active' => 1,
127
+ 'api_key' => $api_key,
128
+ 'api_key_confirmation' => $api_key,
129
+ );
130
+
131
+ $user->setData($data);
132
+ $user->save();
133
+ return $user;
134
+ }
135
  }
app/code/community/DataFeedWatch/Connector/controllers/Adminhtml/SettingsController.php ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class DataFeedWatch_Connector_Adminhtml_SettingsController extends Mage_Adminhtml_Controller_Action{
4
+
5
+ public function indexAction(){
6
+
7
+ if($this->_request->isPost()) {
8
+ $additional_attributes = $this->_request->getParam('additional_attributes');
9
+ if ($additional_attributes) {
10
+ Mage::getModel('core/config')->saveConfig('datafeedwatch/settings/attributes', Zend_Serializer::serialize($additional_attributes));
11
+ }
12
+
13
+ Mage::getModel('core/config')->saveConfig('datafeedwatch/settings/ready', 1);
14
+
15
+ //also clean config cache
16
+ $cacheType = 'config';
17
+ Mage::app()->getCacheInstance()->cleanType($cacheType);
18
+ Mage::dispatchEvent('adminhtml_cache_refresh_type', array('type' => $cacheType));
19
+
20
+ Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('connector')->__('Settings were successfully saved.'));
21
+ $this->_redirect('*/*/*');
22
+ return;
23
+ }
24
+ $this->loadLayout();
25
+ $this->renderLayout();
26
+ }
27
+
28
+ protected $username = 'datafeedwatch';
29
+ protected $firstname = 'Api Access';
30
+ protected $lastname = 'DataFeedWatch';
31
+ protected $email = 'magento@datafeedwatch.com';
32
+ protected $register_url = 'https://my.datafeedwatch.com/platforms/magento/sessions/finalize';
33
+
34
+ /**
35
+ * currently the same as $register_url
36
+ * @var string
37
+ */
38
+ protected $redirect_url = 'https://my.datafeedwatch.com/';
39
+
40
+ public function createuserAction() {
41
+
42
+ //Create Api Role for datafeedwatch user
43
+ $role = $this->_createApiRole();
44
+
45
+ //Prepare Api Key
46
+ $api_key = $this->_generateApiKey();
47
+
48
+ //send the api key to DFW
49
+ file_get_contents($this->_registerUrl($api_key));
50
+
51
+ //Get Api User
52
+ $user = $this->getUser();
53
+ if ($user->getId()) {
54
+ //Update Api User
55
+ $user = $this->_updateApiUser($api_key, $user);
56
+ } else {
57
+ //Create Api User
58
+ $user = $this->_createApiUser($api_key);
59
+ }
60
+
61
+ //Assign Api User to the Api Role
62
+ $user->setRoleId($role->getId())->setUserId($user->getId());
63
+ $user->add();
64
+
65
+ //redirect to register token url in DFW
66
+ $this->getResponse()->setRedirect($this->_registerUrl($api_key));
67
+ return;
68
+ }
69
+
70
+ public function redirectAction(){
71
+ $this->getResponse()->setRedirect($this->redirect_url);
72
+ return;
73
+ }
74
+
75
+ public function getUser() {
76
+ $model = Mage::getModel('api/user');
77
+ return $model->load($this->email, 'email');
78
+ }
79
+
80
+ private function _generateApiKey() {
81
+ return sha1(time()+substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 32));
82
+ }
83
+
84
+ private function _registerUrl($api_key) {
85
+ return $this->register_url.'?shop='.Mage::getBaseUrl().'&token='.$api_key;
86
+ }
87
+
88
+ private function _createApiRole(){
89
+ $role = Mage::getModel('api/roles')->load($this->lastname, 'role_name');
90
+ if ($role->isObjectNew()) {
91
+ $role = $role
92
+ ->setName($this->lastname)
93
+ ->setPid(false)
94
+ ->setRoleType('G')
95
+ ->save();
96
+
97
+ $resource = array("all");
98
+
99
+ Mage::getModel("api/rules")
100
+ ->setRoleId($role->getId())
101
+ ->setResources($resource)
102
+ ->saveRel();
103
+ }
104
+ return $role;
105
+ }
106
+
107
+ private function _createApiUser($api_key){
108
+ $data = array(
109
+ 'username' => $this->username,
110
+ 'firstname' => $this->firstname,
111
+ 'lastname' => $this->lastname,
112
+ 'email' => $this->email,
113
+ 'is_active' => 1,
114
+ 'api_key' => $api_key,
115
+ 'api_key_confirmation' => $api_key,
116
+ );
117
+
118
+ $user = Mage::getModel('api/user');
119
+ $user->setData($data);
120
+ $user->save();
121
+ return $user;
122
+ }
123
+
124
+ /**
125
+ * @param $api_key string
126
+ * @param $user Mage_Api_Model_User
127
+ *
128
+ * @return Mage_Api_Model_User
129
+ */
130
+
131
+ private function _updateApiUser($api_key, $user) {
132
+ $data = array(
133
+ 'username' => $this->username,
134
+ 'firstname' => $this->firstname,
135
+ 'lastname' => $this->lastname,
136
+ 'is_active' => 1,
137
+ 'api_key' => $api_key,
138
+ 'api_key_confirmation' => $api_key,
139
+ );
140
+
141
+ $user->setData($data);
142
+ $user->save();
143
+ return $user;
144
+ }
145
+ }
app/code/community/DataFeedWatch/Connector/controllers/TokenController.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
- class DataFeedWatch_Connector_TokenController extends Mage_Core_Controller_Front_Action {
3
-
4
- /**
5
- * @deprecated - turned out to prevent problems, to remove with next revision
6
- * reachable by
7
- * http://magentostore.com/datafeedwatch/token/confirm/hash/b271ecf10045d888245202b3268a72fb/new_api_key/yournewkey
8
- */
9
- public function confirmAction()
10
- {
11
- return true;
12
- /*$request = $this->getRequest();
13
- if(!$request->isPost()){
14
- Mage::log(__METHOD__.' - not sent through POST');
15
- } else {
16
- $params = $request->getParams();
17
- if(array_key_exists('hash',$params) && array_key_exists('new_api_key',$params)){
18
- $matchingUser = Mage::getModel('api/user')->load($params['hash'],'dfw_connect_hash');
19
- if(is_object($matchingUser) && $matchingUser->getId()>0){
20
- $matchingUser->setApiKey($params['new_api_key']);
21
- $matchingUser->save();
22
- } else {
23
- Mage::log(__METHOD__.' - no matching user found');
24
- }
25
- } else {
26
- Mage::log(__METHOD__.' - params are missing');
27
- }
28
- }*/
29
- }
30
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
app/code/community/DataFeedWatch/Connector/etc/api.xml CHANGED
@@ -1,25 +1,34 @@
1
  <?xml version="1.0"?>
2
  <config>
3
- <api>
4
- <resources>
5
- <datafeedwatch translate="title" module="connector">
6
- <title>DataFeedWatch API</title>
7
- <model>connector/datafeedwatch_api</model>
8
- <methods>
9
- <version translate="title" module="connector">
10
- <title>Retrieve extension version</title>
11
- </version>
12
- <products translate="title" module="connector">
13
- <title>Retrieve products</title>
14
- </products>
15
- <product_count translate="title" module="connector">
16
- <title>Retrieve product count</title>
17
- </product_count>
18
  <stores translate="title" module="connector">
19
  <title>Retrieve stores</title>
20
  </stores>
21
- </methods>
22
- </datafeedwatch>
23
- </resources>
24
- </api>
 
 
 
 
 
 
 
 
 
25
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
+ <api>
4
+ <resources>
5
+ <datafeedwatch translate="title" module="connector">
6
+ <title>DataFeedWatch API</title>
7
+ <model>connector/datafeedwatch_api</model>
8
+ <methods>
9
+ <version translate="title" module="connector">
10
+ <title>Retrieve extension version</title>
11
+ </version>
12
+ <products translate="title" module="connector">
13
+ <title>Retrieve products</title>
14
+ </products>
15
+ <product_count translate="title" module="connector">
16
+ <title>Retrieve product count</title>
17
+ </product_count>
18
  <stores translate="title" module="connector">
19
  <title>Retrieve stores</title>
20
  </stores>
21
+ <product_ids translate="title" module="connector">
22
+ <title>Retrieve Product Ids</title>
23
+ </product_ids>
24
+ <synced_fields translate="title" module="connector">
25
+ <title>Retrieve selected attributes</title>
26
+ </synced_fields>
27
+ <gmt_offset translate="title" module="connector">
28
+ <title>Retrieve datetime in GMT</title>
29
+ </gmt_offset>
30
+ </methods>
31
+ </datafeedwatch>
32
+ </resources>
33
+ </api>
34
  </config>
app/code/community/DataFeedWatch/Connector/etc/config.xml CHANGED
@@ -2,7 +2,7 @@
2
  <config>
3
  <modules>
4
  <DataFeedWatch_Connector>
5
- <version>0.2.12</version>
6
  </DataFeedWatch_Connector>
7
  </modules>
8
  <admin>
@@ -22,7 +22,7 @@
22
  <children>
23
  <connectorbackend translate="title" module="connector">
24
  <title>DataFeedWatch</title>
25
- <action>connector/adminhtml_connectorbackend</action>
26
  </connectorbackend>
27
  </children>
28
  </catalog>
2
  <config>
3
  <modules>
4
  <DataFeedWatch_Connector>
5
+ <version>0.2.16</version>
6
  </DataFeedWatch_Connector>
7
  </modules>
8
  <admin>
22
  <children>
23
  <connectorbackend translate="title" module="connector">
24
  <title>DataFeedWatch</title>
25
+ <action>connector/adminhtml_settings</action>
26
  </connectorbackend>
27
  </children>
28
  </catalog>
app/design/adminhtml/default/default/layout/connector.xml CHANGED
@@ -1,8 +1,18 @@
1
  <?xml version="1.0"?>
2
  <layout version="0.1.0">
3
- <connector_adminhtml_connectorbackend_index>
4
- <reference name="content">
5
- <block type="connector/adminhtml_connectorbackend" name="connectorbackend" template="connector/connectorbackend.phtml"/>
6
- </reference>
7
- </connector_adminhtml_connectorbackend_index>
 
 
 
 
 
 
 
 
 
 
8
  </layout>
1
  <?xml version="1.0"?>
2
  <layout version="0.1.0">
3
+ <connector_adminhtml_settings_index>
4
+ <reference name="head">
5
+ <action method="addItem">
6
+ <type>skin_js</type>
7
+ <name>js/connector/connector.js</name>
8
+ </action>
9
+ <action method="addItem">
10
+ <type>skin_css</type>
11
+ <name>connector.css</name>
12
+ </action>
13
+ </reference>
14
+ <reference name="content">
15
+ <block type="connector/adminhtml_settings_edit" name="settings"/>
16
+ </reference>
17
+ </connector_adminhtml_settings_index>
18
  </layout>
app/design/adminhtml/default/default/template/connector/connectorbackend.phtml DELETED
@@ -1,11 +0,0 @@
1
- <h1>DataFeedWatch</h1>
2
- <br/>
3
- <br/>
4
- <?php if ($user->isObjectNew()) {
5
- $linkUrl = $this->getCreateUserUrl();
6
- } else {
7
- $linkUrl = $this->getRedirectUrl();
8
- } ?>
9
-
10
- <button onclick="setLocation('<?php echo $linkUrl; ?>')" type="button" class="scalable">Go to my DataFeedWatch</button>
11
-
 
 
 
 
 
 
 
 
 
 
 
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>DataFeedWatch_Connector</name>
4
- <version>0.2.12</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,11 +9,11 @@
9
  <summary>DataFeedWatch extension for Magento</summary>
10
  <description>DataFeedWatch enables Magento shops to optimize their product datafeed for Google Shopping and other channels&#xD;
11
  </description>
12
- <notes>DataFeedWatch Release version 0.2.12</notes>
13
  <authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
14
- <date>2014-07-25</date>
15
- <time>13:44:20</time>
16
- <contents><target name="magecommunity"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="7d6af1cb6dd7df3799928fe073f5576b"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="2da89bd06938584f9eafeac98e4a99ef"/></dir><dir><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="2da89bd06938584f9eafeac98e4a99ef"/></dir></dir><file name="TokenController.php" hash="573ca81b110e79bc3893ac298b2aa02b"/></dir><dir name="etc"><file name="api.xml" hash="eb6eecef3f0922b809f2701aed29325d"/><file name="config.xml" hash="cef1812ea3d02e61a9085dedcb6e9133"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir><dir name="Helper"><file name="Data.php" hash="85269d06206056aeff2fb2c25938ff9c"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="270bdbae10b846664914d29090d8da50"/></dir></dir><dir name="sql"><dir><dir name="datafeedwatch_connector_setup"><file name="install-0.2.9.php" hash="326a2968b7af5a987604f880ed7c4a3c"/><file name="upgrade-0.2.10-0.2.11.php" hash="9dcefa5cafd7efd8f192af4d9c1f0c2e"/><file name="upgrade-0.2.9-0.2.10.php" hash="c9e575e9925df8440eca5aa817c1d5e4"/></dir></dir></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="43e0e0c8ee28090aa098b7d7c7a979ad"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="658a7b36ae7eb5915f40993a191aaa13"/></dir></target></contents>
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.16</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 datafeed for Google Shopping and other channels&#xD;
11
  </description>
12
+ <notes>DataFeedWatch Release version 0.2.16</notes>
13
  <authors><author><name>DataFeedWatch</name><user>Adeel</user><email>adeel.developer@gmail.com</email></author></authors>
14
+ <date>2015-04-29</date>
15
+ <time>06:18:11</time>
16
+ <contents><target name="magecommunity"><dir name="DataFeedWatch"><dir name="Connector"><dir name="Block"><dir name="Adminhtml"><file name="Connectorbackend.php" hash="e5b1e0824f6f8a0131cb9df7c43ed1e6"/><dir name="Settings"><dir name="Edit"><file name="Form.php" hash="970acf34c30399506e7e24ec1a285355"/></dir><file name="Edit.php" hash="06a86343380547f2da83e610d4494d12"/></dir></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="ConnectorbackendController.php" hash="caeb3c3ec3d335eaf72a1d06b7acee1e"/><file name="SettingsController.php" hash="d1179e9fbbbf0b5b6020808cac736647"/><file name="ConnectorbackendController.php" hash="caeb3c3ec3d335eaf72a1d06b7acee1e"/><file name="SettingsController.php" hash="d1179e9fbbbf0b5b6020808cac736647"/></dir></dir><dir name="etc"><file name="api.xml" hash="8918f2d5536f342c365ad77087c79466"/><file name="config.xml" hash="72ee99101b6955ee47efa43d0160d7a4"/><file name="system.xml" hash="ab5e8d56d032ba69c930ab7879484212"/></dir><dir name="Helper"><file name="Data.php" hash="d925b73635ac5bc58b7953486935c367"/></dir><dir name="Model"><dir name="Datafeedwatch"><file name="Api.php" hash="e53d77f281c19c98c6780d723c50d7bc"/></dir></dir><dir name="sql"><dir name="datafeedwatch_connector_setup"><file name="install-0.2.9.php" hash="326a2968b7af5a987604f880ed7c4a3c"/><file name="upgrade-0.2.10-0.2.11.php" hash="9dcefa5cafd7efd8f192af4d9c1f0c2e"/><file name="upgrade-0.2.9-0.2.10.php" hash="c9e575e9925df8440eca5aa817c1d5e4"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="connector.xml" hash="a78684e832776166222ac3f1ce889566"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="DataFeedWatch_Connector.xml" hash="658a7b36ae7eb5915f40993a191aaa13"/></dir></target><target name="mageskin"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="js"><dir name="connector"><file name="connector.js" hash="a4018ca934e589a6cc6014463b3fa24a"/></dir></dir><file name="connector.css" hash="15d63fea8a6b3bd0befcd326ecda3642"/></dir></dir></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
skin/adminhtml/default/default/connector.css ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ input#additional_attributes_0_all {
2
+ margin-left: -30px;
3
+ }
skin/adminhtml/default/default/js/connector/connector.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ document.observe('dom:loaded', function(){
2
+
3
+ $('additional_attributes_0_all').observe('click', function toggleChkBox(){
4
+
5
+ var attrValue = $('additional_attributes_0_all').checked;
6
+ // toggle Check Boxes using Prototype Library
7
+ var form=$('edit_form');
8
+ var i=form.getElements('checkbox');
9
+ i.each(function(item)
10
+ {
11
+ if(item.id.indexOf('additional_attributes')>-1 && item.id!='additional_attributes_0_all'){
12
+ item.checked = attrValue;
13
+ }
14
+ }
15
+ );
16
+ });
17
+ });