@@ -98,7 +98,7 @@ class AvS_FastSimpleImport_Model_Import_Entity_Product extends AvS_FastSimpleImp
9898 protected $ _mediaValueTableName ;
9999 /** @var string */
100100 protected $ _downloadableLinksTableName ;
101-
101+
102102 /**
103103 * Attributes with index (not label) value.
104104 *
@@ -1394,18 +1394,26 @@ protected function _saveProducts()
13941394 $ mediaGallery [$ rowSku ][] = $ mediaImageData ;
13951395 }
13961396
1397- // 4. Downloadable files phase
1398- if (!empty ($ rowData ['downloadable_links_file ' ]) &&
1399- !empty ($ rowData ['downloadable_links_title ' ]) &&
1397+ // 4. Downloadable links phase
1398+ if (!empty ($ rowData ['downloadable_links_title ' ]) &&
14001399 !empty ($ rowData ['downloadable_links_nod ' ]) &&
14011400 $ rowData ['_type ' ] === 'downloadable ' ) {
14021401
1403- $ downloadableLinkData = array (
1402+ $ downloadableLinkData = [
14041403 'title ' => $ rowData ['downloadable_links_title ' ],
14051404 'number_of_downloads ' => $ rowData ['downloadable_links_nod ' ],
1406- 'file ' => $ rowData ['downloadable_links_file ' ],
14071405 'store_id ' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID
1408- );
1406+ ];
1407+
1408+ // downloadable files
1409+ if (!empty ($ rowData ['downloadable_links_file ' ])) {
1410+ $ downloadableLinkData ['file ' ] = $ rowData ['downloadable_links_file ' ];
1411+ $ downloadableLinkData ['link_type ' ] = 'file ' ;
1412+ // downloadable urls
1413+ } elseif (!empty ($ rowData ['downloadable_links_url ' ])) {
1414+ $ downloadableLinkData ['url ' ] = $ rowData ['downloadable_links_url ' ];
1415+ $ downloadableLinkData ['link_type ' ] = 'url ' ;
1416+ }
14091417
14101418 $ downloadableData [$ rowSku ][] = $ downloadableLinkData ;
14111419 }
@@ -1561,6 +1569,7 @@ protected function _saveStockItem()
15611569
15621570 /** @var $stockItem Mage_CatalogInventory_Model_Stock_Item */
15631571 $ stockItem = Mage::getModel ('cataloginventory/stock_item ' );
1572+ $ stockItem ->setStockId ($ row ['stock_id ' ]);
15641573 $ stockItem ->loadByProduct ($ row ['product_id ' ]);
15651574 $ existStockData = $ stockItem ->getData ();
15661575
@@ -2047,19 +2056,29 @@ protected function _saveDownloadableLinks(array $downloadableData)
20472056 }
20482057
20492058 foreach ($ downloadableLink as $ insertValue ) {
2059+
2060+ $ linkType = $ insertValue ['link_type ' ];
2061+ $ fieldToSelect = 'link_ ' . $ linkType ;
2062+
20502063 $ alreadyImported = $ this ->_connection ->fetchOne ($ this ->_connection ->select ()
2051- ->from ($ downloadableLinkTableName , array (' link_file ' ))
2064+ ->from ($ downloadableLinkTableName , array ($ fieldToSelect ))
20522065 ->where ('product_id IN (?) ' , $ productId )
2053- ->where (' link_file = (?)' , $ insertValue [' file ' ]));
2066+ ->where (" $ fieldToSelect = (?) " , $ insertValue [$ linkType ]));
20542067
2055- if (!in_array ($ insertValue [' file ' ], $ insertedDownloadableLinks ) && !$ alreadyImported ) {
2068+ if (!in_array ($ insertValue [$ linkType ], $ insertedDownloadableLinks ) && !$ alreadyImported ) {
20562069 $ valueArr = array (
20572070 'product_id ' => $ productId ,
2058- 'link_file ' => $ insertValue ['file ' ],
2059- 'link_type ' => 'file ' ,
20602071 'number_of_downloads ' => $ insertValue ['number_of_downloads ' ],
20612072 );
20622073
2074+ if (array_key_exists ('file ' , $ insertValue )) {
2075+ $ valueArr ['link_file ' ] = $ insertValue ['file ' ];
2076+ $ valueArr ['link_type ' ] = 'file ' ;
2077+ } elseif (array_key_exists ('url ' , $ insertValue )) {
2078+ $ valueArr ['link_url ' ] = $ insertValue ['url ' ];
2079+ $ valueArr ['link_type ' ] = 'url ' ;
2080+ }
2081+
20632082 $ this ->_connection
20642083 ->insertOnDuplicate ($ downloadableLinkTableName , $ valueArr , array ('product_id ' ));
20652084
@@ -2074,10 +2093,12 @@ protected function _saveDownloadableLinks(array $downloadableData)
20742093 $ this ->_connection
20752094 ->insertOnDuplicate ($ downloadableLinkTitleTableName , $ valueArr , array ('link_id ' ));
20762095
2077- $ this ->moveDownloadableFile ($ insertValue ['file ' ]);
2078- $ insertedDownloadableLinks [] = $ insertValue ['file ' ];
2079-
2080-
2096+ if ($ linkType == 'file ' ) {
2097+ $ this ->moveDownloadableFile ($ insertValue [$ fieldToSelect ]);
2098+ }
2099+ if (array_key_exists ($ fieldToSelect , $ insertValue )) {
2100+ $ insertedDownloadableLinks [] = $ insertValue [$ fieldToSelect ];
2101+ }
20812102 }
20822103 }
20832104 }
0 commit comments