Commit cd0bbfc7 by dhn

国家置顶

parent c7cc5664
......@@ -363,6 +363,14 @@
</depends>
</field>
</group>
<group id="top_country" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Top Country</label>
<field id="top_countrys" translate="label" type="text" sortOrder="10" showInDefault="1">
<label>置顶国家</label>
<comment>国家简码为2个大写字母,多个用英文逗号隔开.</comment>
</field>
</group>
</section>
<section id="admin" translate="label" type="text" sortOrder="20" showInDefault="1">
<label>Admin</label>
......
<?php
namespace Magento\Directory\Model\ResourceModel\Country;
class CollectionNew
{
protected $scopeConfig;
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
{
$this->scopeConfig = $scopeConfig;
}
public function afterToOptionArray(\Magento\Directory\Model\ResourceModel\Country\Collection $subject, $result) {
if (!is_array($result) || empty($result)) {
return $result;
}
$topCountry = $this->scopeConfig->getValue('system/top_country/top_countrys');
if (!$topCountry) {
return $result;
}
if (!$result[0]['value']) {
unset($result[0]);
}
$topCountry = explode(',', $topCountry);
$indexs = array_flip($topCountry);
$top = [];
$top[0] = ['value' => '', 'label' => ''];
foreach ($result as $row) {
if (in_array($row['value'], $topCountry)) {
$idx = $indexs[$row['value']] + 1;
$top[$idx] = $row;
}
}
ksort($top);
$top[] = ['value' => '-', 'label' => '---'];
$result = array_merge($top, $result);
return $result;
}
}
\ No newline at end of file
......@@ -39,6 +39,9 @@
</argument>
</arguments>
</type>
<type name="Magento\Directory\Model\ResourceModel\Country\Collection">
<plugin name="new_country_collection" type="Magento\Directory\Model\ResourceModel\Country\CollectionNew"/>
</type>
<preference for="Magento\Directory\Model\Country\Postcode\ConfigInterface" type="Magento\Directory\Model\Country\Postcode\Config" />
<preference for="Magento\Directory\Model\Country\Postcode\ValidatorInterface" type="Magento\Directory\Model\Country\Postcode\Validator" />
<preference for="Magento\Directory\Api\CurrencyInformationAcquirerInterface" type="Magento\Directory\Model\CurrencyInformationAcquirer" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment