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

Improve for multisite #105

Merged
merged 11 commits into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 33 additions & 0 deletions JapaneseAddress/Block/Checkout/BillingAddressComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
namespace CommunityEngineering\JapaneseAddress\Block\Checkout;

use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Directory\Helper\Data as DirectoryHelper;

/**
* Billing address component template can not be configured through layout XML as generated by PHP.
Expand All @@ -16,11 +19,31 @@
*/
class BillingAddressComponent implements LayoutProcessorInterface
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;

/**
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
* BillingAddressComponent constructor.
*
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}

/**
* @inheritDoc
*/
public function process($jsLayout)
{
$locale = $this->getStoreLocale();
if($locale != 'ja_JP') {
lenaorobei marked this conversation as resolved.
Show resolved Hide resolved
return $jsLayout;
}
if (!isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step'])) {
return $jsLayout;
}
Expand Down Expand Up @@ -68,4 +91,14 @@ private function walkChildren(array $component): array
}
return $component;
}

/**
* Retrieve current store locale from system configuration.
*
* @return mixed
*/
private function getStoreLocale()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add PHPDoc block here.

{
return $this->scopeConfig->getValue(DirectoryHelper::XML_PATH_DEFAULT_LOCALE, ScopeInterface::SCOPE_STORE);
}
}
3 changes: 2 additions & 1 deletion JapaneseAddress/Model/Config/CountryInputConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace CommunityEngineering\JapaneseAddress\Model\Config;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Configuration for country field displaying.
Expand All @@ -34,7 +35,7 @@ public function __construct(ScopeConfigInterface $config)
*/
public function isVisibleAtStorefront(): bool
{
$configValue = $this->config->getValue('customer/address/country_show');
$configValue = $this->config->getValue('customer/address/country_show', ScopeInterface::SCOPE_STORE);
return (bool)$configValue;
}
}
3 changes: 2 additions & 1 deletion JapaneseAddress/Model/Config/CustomerRegistrationConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace CommunityEngineering\JapaneseAddress\Model\Config;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Address usage configuration for customer registration.
Expand All @@ -34,7 +35,7 @@ public function __construct(ScopeConfigInterface $config)
*/
public function isAddressRequired(): bool
{
$configValue = $this->config->getValue('customer/create_account/request_address');
$configValue = $this->config->getValue('customer/create_account/request_address', ScopeInterface::SCOPE_STORE);
return (bool)$configValue;
}
}
2 changes: 1 addition & 1 deletion JapaneseAddress/Plugin/Sales/Model/Order/Address/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function afterGetName(
}

$namekana = trim(sprintf('%s %s', $extensions->getLastnamekana(), $extensions->getFirstnamekana()));
if (!empty($namekana)) {
if ($namekana !== '') {
$name = sprintf('%s (%s)', $name, $namekana);
}

Expand Down
2 changes: 1 addition & 1 deletion JapaneseAddress/Plugin/Sales/Model/Order/CustomerName.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function afterGetCustomerName(
$extensions->getCustomerLastnamekana(),
$extensions->getCustomerFirstnamekana()
);
if (!empty($customerNamekana)) {
if (!empty(trim($customerNamekana))) {
$customerName = sprintf('%s (%s)', $customerName, $customerNamekana);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

<!-- ko template: 'CommunityEngineering_JapaneseAddress/checkout/billing-address/details' --><!-- /ko -->
<fieldset class="fieldset" data-bind="visible: !isAddressDetailsVisible()">
<!-- ko template: 'Magento_Checkout/billing-address/list' --><!-- /ko -->
<!-- ko template: 'Magento_Checkout/billing-address/form' --><!-- /ko -->
<each args="getRegion('billing-address-list')" render="" />
<div class="actions-toolbar">
<div class="primary">
<button class="action action-update" type="button" data-bind="click: updateAddress">
Expand Down
7 changes: 4 additions & 3 deletions JapaneseName/Model/Config/KanaFieldsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace CommunityEngineering\JapaneseName\Model\Config;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

/**
* Configuration of kana usage.
Expand All @@ -34,7 +35,7 @@ public function __construct(ScopeConfigInterface $config)
*/
public function areEnabled(): bool
{
$configValue = $this->config->getValue('customer/address/use_kana');
$configValue = $this->config->getValue('customer/address/use_kana', ScopeInterface::SCOPE_STORE);
return (bool)$configValue;
}

Expand All @@ -49,7 +50,7 @@ public function areRequired(): bool
return false;
}

$configValue = $this->config->getValue('customer/address/require_kana');
$configValue = $this->config->getValue('customer/address/require_kana', ScopeInterface::SCOPE_STORE);
return (bool)$configValue;
}

Expand All @@ -60,7 +61,7 @@ public function areRequired(): bool
*/
public function getKanaType(): int
{
$configValue = $this->config->getValue('customer/address/kana_type');
$configValue = $this->config->getValue('customer/address/kana_type', ScopeInterface::SCOPE_STORE);
if (!in_array($configValue, [
Source\Kana::TYPE_HIRAGANA,
Source\Kana::TYPE_KATAKANA,
Expand Down
18 changes: 17 additions & 1 deletion JapaneseName/Plugin/Customer/Block/Widget/Name.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,28 @@
namespace CommunityEngineering\JapaneseName\Plugin\Customer\Block\Widget;

use Magento\Customer\Block\Widget\Name as Subject;
use CommunityEngineering\JapaneseName\Model\Config\KanaFieldsConfig;

/**
* Use name widget that corresponds to Japanese traditions and contains kana fields.
*/
class Name
{
/**
* @var KanaFieldsConfig
*/
private $kanaFieldsConfig;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add PHPDoc block here.


/**
* Name constructor.
* @param KanaFieldsConfig $kanaFieldsConfig
*/
public function __construct(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add PHPDoc block here.

KanaFieldsConfig $kanaFieldsConfig
) {
$this->kanaFieldsConfig = $kanaFieldsConfig;
}

/**
* Substitute default template.
*
Expand All @@ -24,7 +40,7 @@ class Name
*/
public function beforeSetTemplate(Subject $subject, string $template)
{
if ($template === 'Magento_Customer::widget/name.phtml') {
if ($template === 'Magento_Customer::widget/name.phtml' && $this->kanaFieldsConfig->areEnabled()) {
return ['CommunityEngineering_JapaneseName::customer/widget/name.phtml'];
}
return [$template];
Expand Down
3 changes: 3 additions & 0 deletions JapaneseName/i18n/ja_JP.csv
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
"Last Name Kana","フリガナ(姓)"
"Billing Firstname Kana","支払人の名 (フリガナ)"
"Billing Lastname Kana","支払人の姓 (フリガナ)"
"Please use full width kana only in this field.","全角かなで入力してください。"
"Please use full width Katakana only in this field.","全角カタカナで入力してください。"
"Please use Hiragana only in this field.","全角ひらがなで入力してください。"
6 changes: 3 additions & 3 deletions JapaneseName/view/frontend/web/js/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ define([
handler: function (value) {
return /^([\u3040-\u309F|\u30FB-\u30FC])*$/.test(value);
},
errorMessage: 'Please use Hiragana only in this field.'
errorMessage: $.mage.__('Please use Hiragana only in this field.')
},
{
id: 'validate-katakana',
Expand All @@ -41,7 +41,7 @@ define([
handler: function (value) {
return /^([\u30A1-\u30FC])*$/.test(value);
},
errorMessage: 'Please use full width Katakana only in this field.'
errorMessage: $.mage.__('Please use full width Katakana only in this field.')
},
{
id: 'validate-kana',
Expand All @@ -55,7 +55,7 @@ define([
handler: function (value) {
return /^([\u3040-\u309F|\u30FB-\u30FC|\u30A1-\u30FC])*$/.test(value);
},
errorMessage: 'Please use full width kana only in this field.'
errorMessage: $.mage.__('Please use full width kana only in this field.')
}
];

Expand Down