FarApp_Connector - Version 1.5.0

Version Notes

Added automatic partial reindexing of updated products.

Download this release

Release Info

Developer FarApp
Extension FarApp_Connector
Version 1.5.0
Comparing to
See all releases


Code changes from version 1.4.2 to 1.5.0

app/code/community/FarApp/Connector/Model/Import.php CHANGED
@@ -3,5 +3,9 @@
3
  */
4
  class FarApp_Connector_Model_Import extends Mage_ImportExport_Model_Import
5
  {
 
 
 
 
6
  }
7
 
3
  */
4
  class FarApp_Connector_Model_Import extends Mage_ImportExport_Model_Import
5
  {
6
+ public function getEntityAdapter()
7
+ {
8
+ return $this->_getEntityAdapter();
9
+ }
10
  }
11
 
app/code/community/FarApp/Connector/Model/Import/Entity/Product.php CHANGED
@@ -471,4 +471,132 @@ class FarApp_Connector_Model_Import_Entity_Product extends Mage_ImportExport_Mod
471
  $this->_isGroupPriceValid($rowData, $rowNum);
472
  $this->_isSuperProductsSkuValid($rowData, $rowNum);
473
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  }
471
  $this->_isGroupPriceValid($rowData, $rowNum);
472
  $this->_isSuperProductsSkuValid($rowData, $rowNum);
473
  }
474
+
475
+ public function prepareDeletedProductsReindex()
476
+ {
477
+ if ($this->getBehavior() != Mage_ImportExport_Model_Import::BEHAVIOR_DELETE) {
478
+ return $this;
479
+ }
480
+ $skus = $this->_getProcessedProductSkus();
481
+ $productCollection = Mage::getModel('catalog/product')
482
+ ->getCollection()
483
+ ->addAttributeToFilter('sku', array('in' => $skus));
484
+ foreach ($productCollection as $product) {
485
+ /** @var $product Mage_Catalog_Model_Product */
486
+ $this->_logDeleteEvent($product);
487
+ }
488
+ return $this;
489
+ }
490
+
491
+ protected function _getProcessedProductSkus()
492
+ {
493
+ $skus = array();
494
+ $source = $this->getSource();
495
+ $source->rewind();
496
+ while ($source->valid()) {
497
+ $current = $source->current();
498
+ $key = $source->key();
499
+ if (! empty($current[self::COL_SKU]) && $this->_validatedRows[$key]) {
500
+ $skus[] = $current[self::COL_SKU];
501
+ }
502
+ $source->next();
503
+ }
504
+ return $skus;
505
+ }
506
+
507
+ public function reindexImportedProducts()
508
+ {
509
+ switch ($this->getBehavior()) {
510
+ case Mage_ImportExport_Model_Import::BEHAVIOR_DELETE:
511
+ $this->_indexDeleteEvents();
512
+ break;
513
+ case Mage_ImportExport_Model_Import::BEHAVIOR_REPLACE:
514
+ case Mage_ImportExport_Model_Import::BEHAVIOR_APPEND:
515
+ $this->_reindexUpdatedProducts();
516
+ break;
517
+ }
518
+ }
519
+
520
+ protected function _reindexUpdatedProducts()
521
+ {
522
+ if (Mage::helper('core')->isModuleEnabled('Enterprise_Index')) {
523
+ Mage::getSingleton('enterprise_index/observer')->refreshIndex(Mage::getModel('cron/schedule'));
524
+ } else {
525
+ $entityIds = $this->_getProcessedProductIds();
526
+ /*
527
+ * Generate a fake mass update event that we pass to our indexers.
528
+ */
529
+ $event = Mage::getModel('index/event');
530
+ $event->setNewData(array(
531
+ 'reindex_price_product_ids' => &$entityIds, // for product_indexer_price
532
+ 'reindex_stock_product_ids' => &$entityIds, // for indexer_stock
533
+ 'product_ids' => &$entityIds, // for category_indexer_product
534
+ 'reindex_eav_product_ids' => &$entityIds // for product_indexer_eav
535
+ ));
536
+ // Index our product entities.
537
+ Mage::getResourceSingleton('cataloginventory/indexer_stock')->catalogProductMassAction($event);
538
+ Mage::getResourceSingleton('catalog/product_indexer_price')->catalogProductMassAction($event);
539
+ Mage::getResourceSingleton('catalog/category_indexer_product')->catalogProductMassAction($event);
540
+ Mage::getResourceSingleton('catalog/product_indexer_eav')->catalogProductMassAction($event);
541
+ Mage::getResourceSingleton('catalogsearch/fulltext')->rebuildIndex(null, $entityIds);
542
+ if (Mage::getResourceModel('ecomdev_urlrewrite/indexer')) {
543
+ Mage::getResourceSingleton('ecomdev_urlrewrite/indexer')->updateProductRewrites($entityIds);
544
+ } else {
545
+ /* @var $urlModel Mage_Catalog_Model_Url */
546
+ $urlModel = Mage::getSingleton('catalog/url');
547
+ $urlModel->clearStoreInvalidRewrites(); // Maybe some products were moved or removed from website
548
+ foreach ($entityIds as $productId) {
549
+ $urlModel->refreshProductRewrite($productId);
550
+ }
551
+ }
552
+ if (Mage::helper('catalog/product_flat')->isEnabled()) {
553
+ Mage::getSingleton('catalog/product_flat_indexer')->saveProduct($entityIds);
554
+ }
555
+ }
556
+ return $this;
557
+ }
558
+
559
+ protected function _getProcessedProductIds()
560
+ {
561
+ $productIds = array();
562
+ $source = $this->getSource();
563
+ $source->rewind();
564
+ while ($source->valid()) {
565
+ $current = $source->current();
566
+ if (! empty($current['sku']) && isset($this->_oldSku[$current[self::COL_SKU]])) {
567
+ $productIds[] = $this->_oldSku[$current[self::COL_SKU]]['entity_id'];
568
+ } elseif (! empty($current['sku']) && isset($this->_newSku[$current[self::COL_SKU]])) {
569
+ $productIds[] = $this->_newSku[$current[self::COL_SKU]]['entity_id'];
570
+ }
571
+ $source->next();
572
+ }
573
+ return $productIds;
574
+ }
575
+
576
+ protected function _logDeleteEvent($product)
577
+ {
578
+ /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
579
+ $stockItem = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product->getId());
580
+ $stockItem->setForceReindexRequired(true);
581
+ Mage::getSingleton('index/indexer')->logEvent(
582
+ $stockItem,
583
+ Mage_CatalogInventory_Model_Stock_Item::ENTITY,
584
+ Mage_Index_Model_Event::TYPE_DELETE
585
+ );
586
+ Mage::getSingleton('index/indexer')->logEvent(
587
+ $product,
588
+ Mage_Catalog_Model_Product::ENTITY,
589
+ Mage_Index_Model_Event::TYPE_DELETE
590
+ );
591
+ }
592
+
593
+ protected function _indexDeleteEvents()
594
+ {
595
+ Mage::getSingleton('index/indexer')->indexEvents(
596
+ Mage_CatalogInventory_Model_Stock_Item::ENTITY, Mage_Index_Model_Event::TYPE_DELETE
597
+ );
598
+ Mage::getSingleton('index/indexer')->indexEvents(
599
+ Mage_Catalog_Model_Product::ENTITY, Mage_Index_Model_Event::TYPE_DELETE
600
+ );
601
+ }
602
  }
app/code/community/FarApp/Connector/Model/Product/Api.php CHANGED
@@ -35,6 +35,7 @@ class FarApp_Connector_Model_Product_Api extends Mage_Catalog_Model_Product_Api
35
  );
36
  }
37
  else {
 
38
  $productDetails = $this->info($product->getId(), null, null, null, true);
39
  $mediaApi = new Mage_Catalog_Model_Product_Attribute_Media_Api();
40
  $mediaList = $mediaApi->items($product->getId());
35
  );
36
  }
37
  else {
38
+ Mage::log('HI1 '.$product->getId());
39
  $productDetails = $this->info($product->getId(), null, null, null, true);
40
  $mediaApi = new Mage_Catalog_Model_Product_Attribute_Media_Api();
41
  $mediaList = $mediaApi->items($product->getId());
app/code/community/FarApp/Connector/controllers/ImportController.php CHANGED
@@ -107,8 +107,10 @@ class FarApp_Connector_ImportController extends Mage_Core_Controller_Front_Actio
107
  }
108
 
109
  try {
 
110
  $importModel->importSource();
111
- $importModel->invalidateIndex();
 
112
  } catch (Exception $e) {
113
  echo $e->getMessage();
114
  return;
107
  }
108
 
109
  try {
110
+ $importModel->getEntityAdapter()->prepareDeletedProductsReindex();
111
  $importModel->importSource();
112
+ $importModel->getEntityAdapter()->reindexImportedProducts();
113
+ //$importModel->invalidateIndex();
114
  } catch (Exception $e) {
115
  echo $e->getMessage();
116
  return;
app/code/community/FarApp/Connector/etc/config.xml CHANGED
@@ -9,7 +9,7 @@
9
  <config>
10
  <modules>
11
  <FarApp_Connector>
12
- <version>1.4.2</version>
13
  </FarApp_Connector>
14
  </modules>
15
  <global>
9
  <config>
10
  <modules>
11
  <FarApp_Connector>
12
+ <version>1.5.0</version>
13
  </FarApp_Connector>
14
  </modules>
15
  <global>
package.xml CHANGED
@@ -1,18 +1,18 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>FarApp_Connector</name>
4
- <version>1.4.2</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.farapp.com/signup/">Commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connector to sync product data from FarApp to Magento. FarApp currently supports NetSuite and other backends.</summary>
10
  <description>FarApp is a cloud-based solution for posting product data to storefronts, retrieving orders from storefront and posting fulfillments to storefronts. We support various backends including NetSuite, X-Cart, 3D-Cart, and more. This connector allows full product data posting to Magento from FarApp. It has the the extra benefits of allowing FarApp to dynamically push new product data, automatically creating new attribute options and importing external images (features not provided by Magento).</description>
11
- <notes>Support for reading configurable item data for export</notes>
12
  <authors><author><name>FarApp</name><user>FarApp</user><email>support@farapp.com</email></author></authors>
13
- <date>2016-07-06</date>
14
- <time>06:26:27</time>
15
- <contents><target name="magecommunity"><dir name="FarApp"><dir name="Connector"><dir name="Helper"><file name="Data.php" hash="60ea63e7acbcdd006c05d3f8528d6b91"/></dir><dir name="Model"><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="765dc8fbab996f17b9f049cc8aa906a0"/><file name="Array.php" hash="6ca62c702dcb9512ec429563ac1ce1a2"/></dir><dir name="Entity"><file name="Order.php" hash="14a2f735cf8fc5e8f2bcd6682a1e56b1"/></dir></dir><file name="Export.php" hash="01643ef101731c6d98bbc523642f95a0"/><dir name="Import"><dir name="Entity"><file name="Customer.php" hash="376978f635c73605d428037cca8cf594"/><file name="Order.php" hash="38579396825a1bd3ad59de84278085f6"/><file name="Product.php" hash="038143e12f77df56ae844ff6879ca575"/><file name="minVersion2.php" hash="8df670fd68516ba1629304ae8ab6c812"/></dir></dir><file name="Import.php" hash="5f226d5505bf8e258a4e61f43b09b25a"/><file name="Observer.php" hash="855bf20a8667fc0e70b0ec75fd230a50"/><dir name="Order"><dir name="Creditmemo"><file name="Api.php" hash="edb85d34679eab92e8990a0dd065632e"/></dir><dir name="Invoice"><file name="Api.php" hash="f133255dae51ab9c44c71ca9cc702d0a"/></dir></dir><dir name="Product"><file name="Api.php" hash="5cec4ac4a6b5bd43b88b7a13c96bcfa1"/></dir></dir><dir name="controllers"><file name="ExportController.php" hash="83a48feea4dc3d601b2cef7df2d27110"/><file name="ImportController.php" hash="ec66abaf46073b9491889a199d665992"/><file name="IndexController.php" hash="93918848d3ce7f6ad05688f89a730e75"/></dir><dir name="etc"><file name="api.xml" hash="6178269d7dc6cb7aa1188f059e75a4fc"/><file name="config.xml" hash="734333b5b648767fc00f3fe6e23b483a"/><file name="system.xml" hash="395c2670f5132a4e617310345185c200"/><file name="wsdl.xml" hash="53aac63b4e1503137d9280b374d51b03"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FarApp_Connector.xml" hash="ff3fe315c70239229cb5ff3a49d40967"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>5.7.0</max></php></required></dependencies>
18
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>FarApp_Connector</name>
4
+ <version>1.5.0</version>
5
  <stability>stable</stability>
6
  <license uri="https://www.farapp.com/signup/">Commercial</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Connector to sync product data from FarApp to Magento. FarApp currently supports NetSuite and other backends.</summary>
10
  <description>FarApp is a cloud-based solution for posting product data to storefronts, retrieving orders from storefront and posting fulfillments to storefronts. We support various backends including NetSuite, X-Cart, 3D-Cart, and more. This connector allows full product data posting to Magento from FarApp. It has the the extra benefits of allowing FarApp to dynamically push new product data, automatically creating new attribute options and importing external images (features not provided by Magento).</description>
11
+ <notes>Added automatic partial reindexing of updated products.</notes>
12
  <authors><author><name>FarApp</name><user>FarApp</user><email>support@farapp.com</email></author></authors>
13
+ <date>2016-08-21</date>
14
+ <time>00:17:17</time>
15
+ <contents><target name="magecommunity"><dir name="FarApp"><dir name="Connector"><dir name="Helper"><file name="Data.php" hash="60ea63e7acbcdd006c05d3f8528d6b91"/></dir><dir name="Model"><dir name="Export"><dir name="Adapter"><file name="Abstract.php" hash="765dc8fbab996f17b9f049cc8aa906a0"/><file name="Array.php" hash="6ca62c702dcb9512ec429563ac1ce1a2"/></dir><dir name="Entity"><file name="Order.php" hash="14a2f735cf8fc5e8f2bcd6682a1e56b1"/></dir></dir><file name="Export.php" hash="01643ef101731c6d98bbc523642f95a0"/><dir name="Import"><dir name="Entity"><file name="Customer.php" hash="376978f635c73605d428037cca8cf594"/><file name="Order.php" hash="38579396825a1bd3ad59de84278085f6"/><file name="Product.php" hash="61fb4cfe7c47ba3f99dec526cc534ada"/><file name="minVersion2.php" hash="8df670fd68516ba1629304ae8ab6c812"/></dir></dir><file name="Import.php" hash="deb96f4867780788413d96be1c2b9ff9"/><file name="Observer.php" hash="855bf20a8667fc0e70b0ec75fd230a50"/><dir name="Order"><dir name="Creditmemo"><file name="Api.php" hash="edb85d34679eab92e8990a0dd065632e"/></dir><dir name="Invoice"><file name="Api.php" hash="f133255dae51ab9c44c71ca9cc702d0a"/></dir></dir><dir name="Product"><file name="Api.php" hash="0b1885b8bca1c858eadb4eab90dcbe17"/></dir></dir><dir name="controllers"><file name="ExportController.php" hash="83a48feea4dc3d601b2cef7df2d27110"/><file name="ImportController.php" hash="7a12bac2eb701f3664c5b542778342cc"/><file name="IndexController.php" hash="93918848d3ce7f6ad05688f89a730e75"/></dir><dir name="etc"><file name="api.xml" hash="6178269d7dc6cb7aa1188f059e75a4fc"/><file name="config.xml" hash="53168ebc2a2e6e10e59a8d6e564fbf04"/><file name="system.xml" hash="395c2670f5132a4e617310345185c200"/><file name="wsdl.xml" hash="53aac63b4e1503137d9280b374d51b03"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="FarApp_Connector.xml" hash="ff3fe315c70239229cb5ff3a49d40967"/></dir></target></contents>
16
  <compatible/>
17
  <dependencies><required><php><min>5.0.0</min><max>5.7.0</max></php></required></dependencies>
18
  </package>