Skip to content

Commit 38702a6

Browse files
authored
Merge pull request #435 from pixelhed/add-downloadable-urls
Add downloadable urls
2 parents 439bdbc + e333b68 commit 38702a6

4 files changed

Lines changed: 51 additions & 21 deletions

File tree

README.markdown

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@ Wrapper for Magento ImportExport functionality which imports data from arrays
77

88
Facts
99
-----
10-
- version: 0.7.0
10+
- version: 0.8.2
1111
- extension key: AvS_FastSimpleImport
12-
- extension on Magento Connect: n/a
13-
- Magento Connect 1.0 extension key: n/a
14-
- Magento Connect 2.0 extension key: n/a
15-
- Composer name: avstudnitz/fast-simple-import (included in http://packages.firegento.com/)
12+
- Composer name: avstudnitz/fast-simple-import (included in http://packages.firegento.com/ and Packagist)
1613
- [Extension on GitHub](https://github.com/avstudnitz/AvS_FastSimpleImport)
1714
- [Direct download link](https://github.com/avstudnitz/AvS_FastSimpleImport/tarball/master)
1815
- [Documentation](http://avstudnitz.github.io/AvS_FastSimpleImport/)
@@ -73,6 +70,10 @@ Paul Hachmang
7370
http://www.h-o.nl/
7471
[@paales](https://twitter.com/paales)
7572

73+
Simon Sprankel
74+
http://simonsprankel.de/
75+
[@SimonSprankel](https://twitter.com/SimonSprankel)
76+
7677

7778
License
7879
-------

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"type": "magento-module",
44
"description": "Wrapper for Magento ImportExport functionality, which imports products and customers from arrays",
55
"homepage": "https://github.com/avstudnitz/AvS_FastSimpleImport",
6+
"license": [
7+
"OSL-3.0"
8+
],
69
"suggest": {
710
"magento-hackathon/magento-composer-installer": "*"
811
}

src/app/code/community/AvS/FastSimpleImport/Model/Import/Entity/Product.php

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/app/code/community/AvS/FastSimpleImport/etc/config.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
<import_entity_product>AvS_FastSimpleImport_Model_Import_Entity_Product</import_entity_product>
2525
</rewrite>
2626
</importexport>
27+
<enterprise_importexport>
28+
<rewrite>
29+
<import_entity_product>AvS_FastSimpleImport_Model_Import_Entity_Product</import_entity_product>
30+
</rewrite>
31+
</enterprise_importexport>
2732
</models>
2833

2934
<helpers>

0 commit comments

Comments
 (0)