Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortening currency list in Configuration->General (this replaces PR #19946) #20397

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions app/code/Magento/Config/Model/Config/Source/Locale/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,28 @@ class Currency implements \Magento\Framework\Option\ArrayInterface
* @var \Magento\Framework\Locale\ListsInterface
*/
protected $_localeLists;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_config;

/**
* @var Currency
*/
protected $_installedCurrencies;


/**
* @param \Magento\Framework\Locale\ListsInterface $localeLists
*/
public function __construct(\Magento\Framework\Locale\ListsInterface $localeLists)
public function __construct(
\Magento\Framework\Locale\ListsInterface $localeLists,
\Magento\Framework\App\Config\ScopeConfigInterface $config
)
{
$this->_localeLists = $localeLists;
$this->_config = $config;
}

/**
Expand All @@ -41,7 +56,36 @@ public function toOptionArray()
if (!$this->_options) {
$this->_options = $this->_localeLists->getOptionCurrencies();
}
$options = $this->_options;
$options = [];
$selected = $this->_getInstalledCurrencies();

foreach ($this->_options as $option) {
if (!in_array($option['value'], $selected)) {
continue;
}
$options[] = $option;
}
return $options;
}

/**
* Retrieve Installed Currencies
*
* @return string[]
*/
protected function _getInstalledCurrencies()
{
if (!$this->_installedCurrencies)
{
$this->_installedCurrencies = explode(
',',
$this->_config->getValue(
'system/currency/installed',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
)
);
}
return $this->_installedCurrencies;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<attribute name="class" value="page-product-downloadable"/>
<referenceContainer name="product.info.main">
<block class="Magento\Downloadable\Block\Catalog\Product\Samples" name="product.info.downloadable.samples" as="samples" template="Magento_Downloadable::catalog/product/samples.phtml" after="product.price.tier" />
</referenceContainer>
Expand All @@ -26,21 +25,8 @@
</block>
</block>
</referenceBlock>
<referenceContainer name="product.info.options.wrapper.bottom">
<block class="Magento\Catalog\Pricing\Render" name="product.price.final.copy" before="-">
<arguments>
<argument name="price_render" xsi:type="string">product.price.render.default</argument>
<argument name="price_type_code" xsi:type="string">final_price</argument>
<argument name="display_msrp_help_message" xsi:type="string">1</argument>
<argument name="zone" xsi:type="string">item_view</argument>
<argument name="id_suffix" xsi:type="string">copy-</argument>
</arguments>
</block>
</referenceContainer>
<referenceBlock name="head.components">
<block class="Magento\Framework\View\Element\Js\Components" name="downloadable_page_head_components" template="Magento_Downloadable::js/components.phtml"/>
</referenceBlock>
<move element="product.info" destination="content" after="product.info.media" />
<move element="product.info.social" destination="product.info.options.wrapper.bottom" after="-" />
</referenceBlock>
</body>
</page>
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,67 @@
<?php $_links = $block->getLinks(); ?>
<?php $_linksLength = 0; ?>
<?php $_isRequired = $block->getLinkSelectionRequired(); ?>
<legend class="legend links-title"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></legend><br>
<div class="field downloads<?php if ($_isRequired) echo ' required' ?><?php if (!$_linksPurchasedSeparately) echo ' downloads-no-separately' ?>">
<label class="label"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></label>
<div class="control" id="downloadable-links-list"
data-mage-init='{"downloadable":{
"linkElement":"input:checkbox[value]",
"allElements":"#links_all",
"config":<?= /* @escapeNotVerified */ $block->getJsonConfig() ?>}
}'
data-container-for="downloadable-links">
<?php foreach ($_links as $_link): ?>
<?php $_linksLength++;?>
<div class="field choice" data-role="link">
<?php if ($_linksPurchasedSeparately): ?>
<input type="checkbox"
<?php if ($_isRequired): ?>data-validate="{'validate-one-checkbox-required-by-name':'downloadable-links-list'}" <?php endif; ?>
name="links[]"
id="links_<?= /* @escapeNotVerified */ $_link->getId() ?>"
value="<?= /* @escapeNotVerified */ $_link->getId() ?>" <?= /* @escapeNotVerified */ $block->getLinkCheckedValue($_link) ?> />
<?php endif; ?>
<label class="label" for="links_<?= /* @escapeNotVerified */ $_link->getId() ?>">
<span><?= $block->escapeHtml($_link->getTitle()) ?></span>
<?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
<a class="sample link"
href="<?= $block->escapeUrl($block->getLinkSampleUrl($_link)) ?>" <?= $block->getIsOpenInNewWindow() ? 'target="_blank"' : '' ?>>
<?= /* @escapeNotVerified */ __('sample') ?>
</a>
<?php endif; ?>
<?php if ($_linksPurchasedSeparately): ?>
<?= /* @escapeNotVerified */ $block->getLinkPrice($_link) ?>
<?php endif; ?>
</label>
</div>
<?php endforeach; ?>
<?php if ($_linksPurchasedSeparately && $_linksLength > 1): ?>
<div class="field choice downloads-all">
<input type="checkbox"
data-notchecked="<?= /* @escapeNotVerified */ __('Select all') ?>"
data-checked="<?= /* @escapeNotVerified */ __('Unselect all') ?>"
id="links_all" />
<label class="label" for="links_all"><span><?= /* @escapeNotVerified */ __('Select all') ?></span></label>
</div>
<?php endif; ?>
</div>
<?php if ($_isRequired): ?>
<span id="links-advice-container"></span>
<?php endif;?>
</div>
<?php
// Show links on frontend only if links are purchased separately
// or only those links with samples. Otherwise there is no point to show link names
$samples = false;
foreach ($_links as $_link){
if ($_link->getSampleFile() || $_link->getSampleUrl()) {
$samples = true;
break;
}
}
?>
<?php if ($samples === true || $_linksPurchasedSeparately): ?>
<?php /* <legend class="legend links-title"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></legend><br> */ ?>
<div class="field downloads<?php if ($_isRequired) echo ' required' ?><?php if (!$_linksPurchasedSeparately) echo ' downloads-no-separately' ?>">
<label class="label"><span><?= $block->escapeHtml($block->getLinksTitle()) ?></span></label>
<div class="control" id="downloadable-links-list"
data-mage-init='{"downloadable":{
"linkElement":"input:checkbox[value]",
"allElements":"#links_all",
"config":<?= /* @escapeNotVerified */ $block->getJsonConfig() ?>}
}'
data-container-for="downloadable-links">
<?php foreach ($_links as $_link): ?>
<?php if (($_link->getSampleFile() || $_link->getSampleUrl()) || $_linksPurchasedSeparately): ?>
<?php $_linksLength++;?>
<div class="field choice" data-role="link">
<?php if ($_linksPurchasedSeparately): ?>
<input type="checkbox"
<?php if ($_isRequired): ?>data-validate="{'validate-one-checkbox-required-by-name':'downloadable-links-list'}" <?php endif; ?>
name="links[]"
id="links_<?= /* @escapeNotVerified */ $_link->getId() ?>"
value="<?= /* @escapeNotVerified */ $_link->getId() ?>" <?= /* @escapeNotVerified */ $block->getLinkCheckedValue($_link) ?> />
<?php endif; ?>
<label class="label" for="links_<?= /* @escapeNotVerified */ $_link->getId() ?>">
<span><?= $block->escapeHtml($_link->getTitle()) ?></span>
<?php if ($_link->getSampleFile() || $_link->getSampleUrl()): ?>
<a class="sample link"
href="<?= $block->escapeUrl($block->getLinkSampleUrl($_link)) ?>" <?= $block->getIsOpenInNewWindow() ? 'target="_blank"' : '' ?>>
<?= /* @escapeNotVerified */ __('sample') ?>
</a>
<?php endif; ?>
<?php if ($_linksPurchasedSeparately): ?>
<?= /* @escapeNotVerified */ $block->getLinkPrice($_link) ?>
<?php endif; ?>
</label>
</div>
<?php endif; ?>
<?php endforeach; ?>
<?php if ($_linksPurchasedSeparately && $_linksLength > 1): ?>
<div class="field choice downloads-all">
<input type="checkbox"
data-notchecked="<?= /* @escapeNotVerified */ __('Select all') ?>"
data-checked="<?= /* @escapeNotVerified */ __('Unselect all') ?>"
id="links_all" />
<label class="label" for="links_all"><span><?= /* @escapeNotVerified */ __('Select all') ?></span></label>
</div>
<?php endif; ?>
</div>
<?php if ($_isRequired): ?>
<span id="links-advice-container"></span>
<?php endif;?>
</div>
<?php endif; ?>
<?php endif; ?>