2016-04-07 11 views
0

Ich erstelle eine neue Zahlungsmethode. Mit dieser neuen Zahlungsmethode kauft der Kunde das Produkt nur, wenn es auf eine gestellte Frage korrekt antwortet. Wie kann ich sicherstellen, dass der Kunde eine Antwort auswählt? Zusätzlich, außer als Antwort des Kunden, um später zu überprüfen, ob einer korrekt ist?Wie wird der Radiobutton ausgewählt?

app/design/frontend/base/default/template/custompaymentmethod/form/custompaymentmethod.phtml: Es ist eine Template-Datei verwendet, um eine individuelle Zahlungsformular für unsere eigene Zahlungsmethode anzuzeigen.

<?php 
$question = Mage::getModel('emme_question/question')->getCollection()->getLastItem(); 
$answers = $question->getSelectedAnswersCollection(); 
?> 
<div id="custompaymentmethod-question"> 
    <h4><?php echo $this->escapeHtml($question->getValue()); ?></h4> 
    <ul> 
    <?php foreach ($answers as $answer): ?> 
    <li> 
    <label><?php echo $this->escapeHtml($answer->getValue()) ?></label> 
    <input type="radio" name="my_custom_answer" value="<?php echo $answer->getId() ?>" required> 
    </li> 
    <?php endforeach ?> 
</div> 
<script> 
jQuery(function ($) { 
    $('#co-payment-form').on('change.mm', function() { 
    var is_question_active = ! $('#p_method_custompaymentmethod').is(':checked'); 
    $('#custompaymentmethod-question input').attr('disabled', is_question_active); 
    }) 
}) 
</script> 

app/code/local/Envato/Custompaymentmethod/Model/Paymentmethod.php: Es ist ein Modell-Datei verwendet, zu validieren und die benutzerdefinierte Zahlungs Felder Informationen zu speichern.

<?php 
// app/code/local/Envato/Custompaymentmethod/Model/Paymentmethod.php 
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract { 
    protected $_code = 'custompaymentmethod'; 
    protected $_formBlockType = 'custompaymentmethod/form_custompaymentmethod'; 
    protected $_infoBlockType = 'custompaymentmethod/info_custompaymentmethod'; 

    public function getOrderPlaceRedirectUrl() 
    { 
    return Mage::getUrl('custompaymentmethod/payment/redirect', array('_secure' => false)); 
    } 
} 

Sorry für mein schlechtes Englisch

Antwort

0

I gelöst

<?php 
// app/code/local/Envato/Custompaymentmethod/Model/Paymentmethod.php 
class Envato_Custompaymentmethod_Model_Paymentmethod extends Mage_Payment_Model_Method_Abstract { 
    protected $_code = 'custompaymentmethod'; 
    protected $_formBlockType = 'custompaymentmethod/form_custompaymentmethod'; 
    protected $_infoBlockType = 'custompaymentmethod/info_custompaymentmethod'; 

public function validate() 
{ 
    foreach (Mage::getModel('emme_question/question')->load(1)->getSelectedAnswersCollection() as $answer) 
    { 
    if ($answer->getIsCorrect()) 
    { 
     if ($answer->getId() == $_POST['my_custom_answer']) 
     { 
      Mage::getSingleton('core/session')->addSuccess('Risposta esatta'); 
     } else 
      { 
        Mage::throwException('Risposta sbagliata!'); 
      } 
    } 
    } 
} 

    public function getOrderPlaceRedirectUrl() 
    { 
    return Mage::getUrl('custompaymentmethod/payment/redirect', array('_secure' => false)); 
    } 
} 
Verwandte Themen