답변:
안녕 당신은 billing.phtml에 아래 코드를 추가하여 이것을 추가 할 수 있습니다
<input type="checkbox" name="is_subscribed"
title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" checked="checked" class="checkbox" />
이벤트를 사용하여 checkout_submit_all_after
고객을 뉴스 레터 구독
<global>
<events>
<checkout_submit_all_after> <!-- identifier of the event we want to catch -->
<observers>
<checkout_submit_all_after_handler> <!-- identifier of the event handler -->
<type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
<class>magento52274/observer</class> <!-- observers class alias -->
<method>AssignNewletter</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</checkout_submit_all_after_handler>
</observers>
</checkout_submit_all_after>
</events>
</global>
관찰자 코드는 다음과 같습니다.
public function AssignNewletter($observer) {
$event = $observer->getEvent();
$order = $event->getOrder();
$Quote =$event->getQuote();
if (in_array($Quote()->getCheckoutMethod(), array('register','customer'))):
if (Mage::app()->getFrontController()->getRequest()->getParam('is_subscribed')){
$status = Mage::getModel('newsletter/subscriber')->subscribe($Quote->getBillingAddress()->getCustomerEmail());
}
endif;
}
1 단계 : config.xml을 작성 app/code/local/Stackexchange/Magento52274/etc/
하고 코드는
<?xml version="1.0"?>
<config>
<modules>
<Stackexchange_Magento52274>
<version>1.0.0</version>
</Stackexchange_Magento52274>
</modules>
<global>
<models>
<magento52274>
<class>Stackexchange_Magento52274_Model</class>
</magento52274>
</models>
<events>
<checkout_submit_all_after> <!-- identifier of the event we want to catch -->
<observers>
<checkout_submit_all_after_handler> <!-- identifier of the event handler -->
<type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
<class>magento52274/observer</class> <!-- observers class alias -->
<method>AssignNewletter</method> <!-- observer's method to be called -->
</checkout_submit_all_after_handler>
</observers>
</checkout_submit_all_after>
</events>
</global>
</config>
2 단계는 : 생성 Observer.php
에 app/code/local/Stackexchange/Magento52274/Model/
코드입니다
<?php
class Stackexchange_Magento52274_Model_Observer
{
public function AssignNewletter(Varien_Event_Observer $observer)
{
$event = $observer->getEvent();
$order = $event->getOrder();
$Quote =$event->getQuote();
if (in_array($Quote()->getCheckoutMethod(), array('register','customer'))):
if Mage::app()->getFrontController()->getParam('is_subscribed', false)){
$status = Mage::getModel('newsletter/subscriber')->subscribe($Quote->getBillingAddress()->getEmail());
}
endif;
}
}
3 단계 : 모듈 생성 app/etc/modules/Stackexchange_Magento52274.xml
및 코드
<?xml version="1.0"?>
<config>
<modules>
<Stackexchange_Magento52274>
<active>true</active>
<codePool>local</codePool>
<version>1.0.0</version>
</Stackexchange_Magento52274>
</modules>
</config>
4 단계 : 또한 뉴스 레터 필드를 추가해야합니다 billing.phtml
.
<input type="checkbox" name="is_subscribed"
title="<?php echo $this->__('Sign Up for Newsletter') ?>" value="1" checked="checked" class="checkbox" />
checkout_submit_all_after
옵저버의 청구 양식 필드에 액세스 할 수 없습니다 . 이 구현을 살펴보십시오 : magento.stackexchange.com/questions/219460/…