This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Plugin\Captcha;
use Magento\Captcha\Helper\Data;
use Magento\Captcha\Model\CaptchaInterface;
use Magento\Captcha\Model\DefaultModel;
class ImproveForgotPasswordCaptchaPlugin
{
private const FORM_ID = 'user_forgotpassword';
/**
* Improve readability only for the storefront forgot-password CAPTCHA.
*
* @param Data $subject
* @param CaptchaInterface $captcha
* @param mixed $formId
* @return CaptchaInterface
*/
public function afterGetCaptcha(
Data $subject,
CaptchaInterface $captcha,
$formId
): CaptchaInterface {
if ($formId === self::FORM_ID && $captcha instanceof DefaultModel) {
$captcha->setWidth(240)
->setHeight(64)
->setFontSize(26)
->setDotNoiseLevel(12)
->setLineNoiseLevel(0);
}
return $captcha;
}
}
@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace Esun\Customer\Plugin\Checkout\Block\Checkout;
use Magento\Checkout\Block\Checkout\LayoutProcessor;
/**
* Keep checkout address fields aligned with Customer > Add New Address.
*/
class LayoutProcessorPlugin
{
private const SORT_ORDERS = [
'firstname' => 10,
'lastname' => 20,
'company' => 25,
'telephone' => 30,
'street' => 40,
'country_id' => 50,
'region_id' => 60,
'region' => 60,
'city' => 70,
'postcode' => 80,
];
/**
* Apply the customer address-book field sequence to shipping and billing.
*/
public function afterProcess(LayoutProcessor $subject, array $jsLayout): array
{
$this->updateAddressFieldsets($jsLayout);
return $jsLayout;
}
/**
* Find every generated checkout address fieldset, including per-payment billing forms.
*/
private function updateAddressFieldsets(array &$node): void
{
if (isset($node['children']) && is_array($node['children'])) {
$fields = &$node['children'];
if ($this->isAddressFieldset($fields)) {
foreach (self::SORT_ORDERS as $code => $sortOrder) {
if (isset($fields[$code]) && is_array($fields[$code])) {
$fields[$code]['sortOrder'] = $sortOrder;
}
}
// The customer address form keeps Company in the EAV payload but
// does not display it. Checkout should behave the same way.
if (isset($fields['company']) && is_array($fields['company'])) {
$fields['company']['visible'] = false;
}
// The address-book form exposes State/Province for countries
// such as the United States. Amasty's checkout metadata leaves
// the select hidden, so explicitly restore the same field.
if (isset($fields['region_id']) && is_array($fields['region_id'])) {
$fields['region_id']['visible'] = true;
}
}
}
foreach ($node as &$child) {
if (is_array($child)) {
$this->updateAddressFieldsets($child);
}
}
unset($child);
}
private function isAddressFieldset(array $fields): bool
{
return isset(
$fields['firstname'],
$fields['lastname'],
$fields['street'],
$fields['country_id'],
$fields['postcode'],
$fields['telephone']
);
}
}