마 젠토 2 : 결제시 거리 필드에 자리 표시 자 텍스트를 추가하는 방법은 무엇입니까?


10

백엔드에서 거리 주소를 3 줄로 설정했습니다.

각 필드에 다른 자리 표시자를 넣고 싶습니다.

  • 거리
  • 건물 / 아파트
  • 지역

이런 방식으로 사용자는보다 체계적인 방식으로 데이터를 입력 할 수 있습니다.

비슷한 질문이 여기에 있습니다.

마 젠토 2-레이아웃 xml / ui 인수를 사용하여 결제 양식의 주소에 영향을 미치는 방법

그러나 답은 거리 주소 필드에 자리 표시자를 포함하는 솔루션을 제공하지 않습니다 .

내가 달성하고자하는 것은 각 주소 필드마다 다른 자리 표시자를 설정하는 것 입니다 .

내 코드 :

app / code / Jsp / Placeholder / etc / module.xml :

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Jsp_Placeholder" setup_version="2.0.0" />
</config>

app / code / Jsp / Placeholder / registration.php :

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE,
  'Jsp_Placeholder',
  __DIR__
);

app / code / Jsp / Placeholder / etc / di.xml :

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <type name="Magento\Checkout\Block\Checkout\AttributeMerger">
    <plugin name="shippingAddress" type="Jsp\Placeholder\Plugin\Checkout\Block\Checkout\AttributeMerger\Plugin"/>
  </type>
</config>

app / code / Jsp / Placeholder / Plugin / Checkout / Block / Checkout / AttributeMerger / Plugin.php :

<?php
namespace Jsp\Placeholder\Plugin\Checkout\Block\Checkout\AttributeMerger;
class Plugin {
  public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject, $result)
  {
    if (array_key_exists('street', $result)) {
      $result['street']['children'][0]['placeholder'] = __('Calle y número exterior');
      $result['street']['children'][1]['placeholder'] = __('Interior / Edificio / Depto.');
      $result['street']['children'][2]['placeholder'] = __('Colonia');
    }
    return $result;
  }
}

이 모듈을 추가 한 후 다음 단계를 수행하십시오. 1. 모듈 활성화 : sudo bin / magento 모듈 : 활성화 Jsp_Placeholder 2. 업그레이드 설정 : sudo bin / magento 설정 : 업그레이드 3. 컴파일 설정 : sudo bin / magento 설정 : di : compile 당신은이 모든 것을 했습니까?
— Ashish Jagnani

이 코드는 magento 2의 기본 결제 주소 양식과 완벽하게 작동합니다.
— Ashish Jagnani

답변:


14

다음 파일을 사용자 정의 모듈에 추가하십시오.

app / code / Vendor / ModuleName / etc / module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
  <module name="Vendor_ModuleName" setup_version="2.0.0" />
</config>

app / code / Vendor / ModuleName / registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
  \Magento\Framework\Component\ComponentRegistrar::MODULE,
  'Vendor_ModuleName',
  __DIR__
);

app / code / Vendor / ModuleName / etc / di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  <type name="Magento\Checkout\Block\Checkout\AttributeMerger">
    <plugin name="shippingAddress" type="Vendor\ModuleName\Plugin\Checkout\Block\Checkout\AttributeMerger\Plugin"/>
  </type>
</config>

공급 업체 \ 모듈 이름 \ Plugin \ Checkout \ Block \ Checkout \ AttributeMerger \ Plugin.php

<?php
namespace Vendor\ModuleName\Plugin\Checkout\Block\Checkout\AttributeMerger;

class Plugin
{
  public function afterMerge(\Magento\Checkout\Block\Checkout\AttributeMerger $subject, $result)
  {
    if (array_key_exists('street', $result)) {
      $result['street']['children'][0]['placeholder'] = __('Flat No/House No/Building No');
      $result['street']['children'][1]['placeholder'] = __('Street Address');
      $result['street']['children'][2]['placeholder'] = __('Landmark');
    }

    return $result;
  }
}

di.xml파일을 어디에 추가해야 합니까? 맞춤 모듈이 없습니다
— Luis Garcia

업데이트 된 답변을 확인하십시오.
— Ashish Jagnani

감사합니다. 안내에 따라 모듈을 만들었지 만 자리 표시자는 아직 표시되지 않습니다. 모듈이 활성화되고 캐시를 정리하고 setup : upgrade를 실행합니다. 무엇이 잘못 될 수 있는지 알고 있습니까?
— Luis Garcia

시도한 것에 대한 질문에 모듈의 모든 파일에 대한 정확한 코드를 작성하십시오.
— Ashish Jagnani

방금 시도한 코드로 질문을 업데이트했습니다.
— Luis Garcia
당사 사이트를 사용함과 동시에 당사의 쿠키 정책과 개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.