Skip to content

Commit 3ab943d

Browse files
author
Michail Slabko
committed
MAGETWO-43788: [GITHUB] Weight units are hardcoded to LBS #1702
1 parent aaf37c1 commit 3ab943d

File tree

7 files changed

+56
-10
lines changed

7 files changed

+56
-10
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Helper/Form/Weight.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class Weight extends \Magento\Framework\Data\Form\Element\Text
2626
*/
2727
protected $localeFormat;
2828

29+
/** @var \Magento\Directory\Helper\Data */
30+
protected $directoryHelper;
31+
2932
/**
3033
* @param \Magento\Framework\Data\Form\Element\Factory $factoryElement
3134
* @param \Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection
@@ -38,8 +41,10 @@ public function __construct(
3841
\Magento\Framework\Data\Form\Element\CollectionFactory $factoryCollection,
3942
\Magento\Framework\Escaper $escaper,
4043
\Magento\Framework\Locale\Format $localeFormat,
44+
\Magento\Directory\Helper\Data $directoryHelper,
4145
array $data = []
4246
) {
47+
$this->directoryHelper = $directoryHelper;
4348
$this->localeFormat = $localeFormat;
4449
$this->weightSwitcher = $factoryElement->create('radios');
4550
$this->weightSwitcher->setValue(
@@ -85,7 +90,7 @@ public function getElementHtml()
8590
'<label class="admin__addon-suffix" for="' .
8691
$this->getHtmlId() .
8792
'"><span>' .
88-
__('lbs') .
93+
$this->directoryHelper->getWeightUnit() .
8994
'</span></label>' .
9095
'</div>' .
9196
'</div>';

app/code/Magento/Directory/Helper/Data.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
*/
1010
namespace Magento\Directory\Helper;
1111

12+
use Magento\Store\Model\ScopeInterface;
13+
1214
class Data extends \Magento\Framework\App\Helper\AbstractHelper
1315
{
1416
/**
@@ -40,6 +42,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
4042
*/
4143
const XML_PATH_TOP_COUNTRIES = 'general/country/destinations';
4244

45+
/**
46+
* Path to config value that contains weight unit
47+
*/
48+
const XML_PATH_WEIGHT_UNIT = 'general/locale/weight_unit';
49+
4350
/**
4451
* Country collection
4552
*
@@ -214,7 +221,7 @@ public function getCountriesWithOptionalZip($asJson = false)
214221
$value = trim(
215222
$this->scopeConfig->getValue(
216223
self::OPTIONAL_ZIP_COUNTRIES_CONFIG_PATH,
217-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
224+
ScopeInterface::SCOPE_STORE
218225
)
219226
);
220227
$this->_optZipCountries = preg_split('/\,/', $value, 0, PREG_SPLIT_NO_EMPTY);
@@ -248,7 +255,7 @@ public function getCountriesWithStatesRequired($asJson = false)
248255
$value = trim(
249256
$this->scopeConfig->getValue(
250257
self::XML_PATH_STATES_REQUIRED,
251-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
258+
ScopeInterface::SCOPE_STORE
252259
)
253260
);
254261
$countryList = preg_split('/\,/', $value, 0, PREG_SPLIT_NO_EMPTY);
@@ -267,7 +274,7 @@ public function isShowNonRequiredState()
267274
{
268275
return (bool)$this->scopeConfig->getValue(
269276
self::XML_PATH_DISPLAY_ALL_STATES,
270-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
277+
ScopeInterface::SCOPE_STORE
271278
);
272279
}
273280

@@ -306,7 +313,7 @@ public function getDefaultCountry($store = null)
306313
{
307314
return $this->scopeConfig->getValue(
308315
self::XML_PATH_DEFAULT_COUNTRY,
309-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
316+
ScopeInterface::SCOPE_STORE,
310317
$store
311318
);
312319
}
@@ -352,8 +359,18 @@ public function getTopCountryCodes()
352359
{
353360
$configValue = (string)$this->scopeConfig->getValue(
354361
self::XML_PATH_TOP_COUNTRIES,
355-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
362+
ScopeInterface::SCOPE_STORE
356363
);
357364
return !empty($configValue) ? explode(',', $configValue) : [];
358365
}
366+
367+
/**
368+
* Retrieve weight unit
369+
*
370+
* @return string
371+
*/
372+
public function getWeightUnit()
373+
{
374+
return $this->scopeConfig->getValue(self::XML_PATH_WEIGHT_UNIT, ScopeInterface::SCOPE_STORE);
375+
}
359376
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Directory\Model\Config\Source;
7+
8+
class WeightUnit implements \Magento\Framework\Option\ArrayInterface
9+
{
10+
/**
11+
* {@inheritdoc}
12+
*/
13+
public function toOptionArray()
14+
{
15+
return [['value' => 'lbs', 'label' => __('lbs')], ['value' => 'kgs', 'label' => __('kgs')]];
16+
}
17+
}

app/code/Magento/Directory/etc/adminhtml/system.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
104104
</field>
105105
</group>
106+
<group id="locale">
107+
<field id="weight_unit" translate="label" type="select" sortOrder="7" showInDefault="1" showInWebsite="1" showInStore="1">
108+
<label>Weight Unit</label>
109+
<source_model>Magento\Directory\Model\Config\Source\WeightUnit</source_model>
110+
</field>
111+
</group>
106112
</section>
107113
</system>
108114
</config>

app/code/Magento/Directory/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<language>en</language>
4545
<code>en_US</code>
4646
<timezone>America/Los_Angeles</timezone>
47+
<weight_unit>lbs</weight_unit>
4748
</locale>
4849
</general>
4950
</default>

app/code/Magento/Store/Model/Service/StoreConfigManager.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class StoreConfigManager implements \Magento\Store\Api\StoreConfigManagerInterfa
3434
'setBaseCurrencyCode' => 'currency/options/base',
3535
'setDefaultDisplayCurrencyCode' => 'currency/options/default',
3636
'setTimezone' => 'general/locale/timezone',
37+
'setWeightUnit' => \Magento\Directory\Helper\Data::XML_PATH_WEIGHT_UNIT
3738
];
3839

3940
/**
@@ -91,9 +92,6 @@ protected function getStoreConfig($store)
9192
$storeConfig->$methodName($configValue);
9293
}
9394

94-
//Hard code the weight unit for now
95-
$storeConfig->setWeightUnit('lbs');
96-
9795
$storeConfig->setBaseUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, false));
9896
$storeConfig->setSecureBaseUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB, true));
9997
$storeConfig->setBaseLinkUrl($store->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK, false));

app/code/Magento/Store/Test/Unit/Model/Service/StoreConfigManagerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ public function testGetStoreConfigs()
121121
$timeZone = 'America/Los_Angeles';
122122
$baseCurrencyCode = 'USD';
123123
$defaultDisplayCurrencyCode = 'GBP';
124+
$weightUnit = 'lbs';
124125

125126
$storeMocks = [];
126127
$storeConfigs = [
@@ -161,6 +162,7 @@ public function testGetStoreConfigs()
161162
['currency/options/base', ScopeInterface::SCOPE_STORES, $code, $baseCurrencyCode],
162163
['currency/options/default', ScopeInterface::SCOPE_STORES, $code, $defaultDisplayCurrencyCode],
163164
['general/locale/timezone', ScopeInterface::SCOPE_STORES, $code, $timeZone],
165+
[\Magento\Directory\Helper\Data::XML_PATH_WEIGHT_UNIT, ScopeInterface::SCOPE_STORES, $code, $weightUnit]
164166
];
165167
$this->scopeConfigMock->expects($this->any())
166168
->method('getValue')
@@ -171,7 +173,7 @@ public function testGetStoreConfigs()
171173
$this->assertEquals(1, count($result));
172174
$this->assertEquals($id, $result[0]->getId());
173175
$this->assertEquals($code, $result[0]->getCode());
174-
$this->assertEquals('lbs', $result[0]->getWeightUnit());
176+
$this->assertEquals($weightUnit, $result[0]->getWeightUnit());
175177
$this->assertEquals($baseUrl, $result[0]->getBaseUrl());
176178
$this->assertEquals($secureBaseUrl, $result[0]->getSecureBaseUrl());
177179
$this->assertEquals($baseLinkUrl, $result[0]->getBaseLinkUrl());

0 commit comments

Comments
 (0)