-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
price list CSV import/export (#3713)
- Loading branch information
Showing
33 changed files
with
1,074 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Ajax from '../../common/utils/Ajax'; | ||
import Register from '../../common/utils/Register'; | ||
|
||
export default class ImportPriceList { | ||
|
||
constructor ($container) { | ||
const $selectListField = $container.filterAllNodes('.js-import-price-list-select-list'); | ||
$selectListField.on('change', (event) => this.onSelectPriceList(event)); | ||
|
||
if ($selectListField.val() !== '') { | ||
const $domainIdField = $('.js-import-price-list-domain-id').parents('.form-line'); | ||
$domainIdField.hide(); | ||
} | ||
} | ||
|
||
onSelectPriceList (event) { | ||
const priceListId = event.target.value; | ||
const $domainIdField = $('.js-import-price-list-domain-id').parents('.form-line'); | ||
|
||
if (priceListId === '') { | ||
$domainIdField.show(); | ||
$('.js-import-price-list-name').val(''); | ||
$('.js-import-price-list-valid-from').val(''); | ||
$('.js-import-price-list-valid-to').val(''); | ||
|
||
return; | ||
} | ||
|
||
$domainIdField.hide(); | ||
|
||
let loadMetadataUrl = $(event.target).data('load-metadata-url'); | ||
loadMetadataUrl = loadMetadataUrl.replace(/\/0\b/, `/${priceListId}`); | ||
|
||
Ajax.ajax({ | ||
url: loadMetadataUrl, | ||
method: 'POST', | ||
success: function (data) { | ||
$('.js-import-price-list-name').val(data.name); | ||
$('.js-import-price-list-valid-from').val(data.validFrom); | ||
$('.js-import-price-list-valid-to').val(data.validTo); | ||
} | ||
}); | ||
} | ||
|
||
static init ($container) { | ||
// eslint-disable-next-line no-new | ||
new ImportPriceList($container); | ||
} | ||
} | ||
|
||
(new Register()).registerCallback(ImportPriceList.init, 'ImportPriceList.init'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,7 +79,7 @@ | |
} | ||
|
||
&--actions { | ||
width: 90px; | ||
width: 130px; | ||
padding-left: 17px; | ||
padding-right: 17px; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Shopsys\FrameworkBundle\Component\HttpFoundation; | ||
|
||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Serializer\Encoder\CsvEncoder; | ||
|
||
class CsvResponse extends Response | ||
{ | ||
/** | ||
* @param array $data | ||
* @param string $fileName | ||
* @param array|null $csvHeaders | ||
*/ | ||
public function __construct(array $data, string $fileName, ?array $csvHeaders = null) | ||
{ | ||
$csvEncoder = new CsvEncoder(); | ||
$context = []; | ||
|
||
if ($csvHeaders === null) { | ||
$context = [CsvEncoder::HEADERS_KEY => $csvHeaders]; | ||
} | ||
|
||
$content = $csvEncoder->encode($data, CsvEncoder::FORMAT, $context); | ||
|
||
parent::__construct($content); | ||
|
||
$this->headers->set('Content-Type', 'text/csv'); | ||
$this->headers->set('Content-Disposition', 'attachment; filename="' . $fileName . '"'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.