0

I want to auto change the assigned group to business, if a customer enters the field "Company name" in the checkout.

I want to hide a payment method, if a customer enters the field "Company name" in the checkout.

This so that a payment method is not possible for business customers.

How can I achieve that?

Payment form:

<?php $this->setBlockData()?>
<?php $_code = $this->getMethodCode(); ?>
<?php $_helper = $this->helper('afterpay');?>
<?php $isEnterprise = (bool) Mage::getConfig()->getModuleConfig("Enterprise_Enterprise")->version;?>

<div id="payment-errors" class="validation-advice" style="display:none;"></div>

<fieldset class="form-list">
    <ul id="payment_form_<?php echo $_code; ?>" style="display:none;">
        <li>
            <?php if($this->country == 'dede') : ?>
            <div class="field">
                <label for="<?php echo $_code; ?>_gender" class = "required"><em>*</em><?php echo $_helper->__('Gender:'); ?></label>
                <div class="input-box" id="">
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="M" id="<?php echo $_code?>_gender_m" checked="checked">
                    <label style="float:none" for="<?php echo $_code?>_gender_m"><?php echo $_helper->__('Male'); ?></label>
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="V" id="<?php echo $_code?>_gender_v">
                    <label style="float:none" for="<?php echo $_code?>_gender_v"><?php echo $_helper->__('Female'); ?></label>
                </div>
            </div>
            <?php else: ?>
            <div class="field">
                <label for="<?php echo $_code; ?>_gender" class = "required"><em>*</em><?php echo $_helper->__('Gender:'); ?></label>
                <div class="input-box" id="">
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="M" id="<?php echo $_code?>_gender_m" checked="checked">
                    <label style="float:none" for="<?php echo $_code?>_gender_m"><?php echo $_helper->__('Male'); ?></label>
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="V" id="<?php echo $_code?>_gender_v">
                    <label style="float:none" for="<?php echo $_code?>_gender_v"><?php echo $_helper->__('Female'); ?></label>
                </div>
            </div>
            <?php endif; ?>
        <?php if ($isEnterprise): ?>
            </li>
            <li>
        <?php endif;?>
        <?php if (!$this->isB2B()): ?>
            <div class="field">
                <?php 
                echo $this->getLayout()->createBlock('afterpay/customer_widget_dob')
                                       ->setFieldIdFormat($_code . ':billing:%s')
                                       ->setFieldNameFormat('payment[' . $_code . '][%s]')
                                       ->setIsRequired(true)
                                       ->setPaymentMethodCode($_code)
                                       ->toHtml() 
                ?>
             </div>
            </li>
            <?php if ($this->showBankaccount()): ?>
            <li> 
                <div class="field">
                    <label for="<?php echo $_code; ?>_bankaccount" class="required"><em>*</em><?php echo $_helper->__('Bank account number:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_bankaccount" name="payment[<?php echo $_code; ?>][bankaccount]" style="">
                    </div>
                </div>
            </li>
            <?php endif; ?>
        <?php endif; ?>
        <?php if ($this->isB2B()): ?>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_companyname" class="required"><em>*</em><?php echo $_helper->__('Company name:'); ?></label>
                    <div class="input-box">
                        <input type="text" value="<?php echo $this->getCompany(); ?>" class="required-entry" id="<?php echo $_code; ?>_companyname" name="payment[<?php echo $_code; ?>][companyname]">
                    </div>
                </div>
                <div class="field">
                    <label for="<?php echo $_code; ?>_department" class=""><?php echo $_helper->__('Department:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "" id="<?php echo $_code; ?>_department" name="payment[<?php echo $_code; ?>][department]">
                    </div>
                </div>
            </li>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_coc" class="required"><em>*</em><?php echo $_helper->__('Coc number:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_coc" name="payment[<?php echo $_code; ?>][coc]">
                    </div>
                </div>
                <div class="field">
                    <label for="<?php echo $_code; ?>_vat" class="required"><em>*</em><?php echo $_helper->__('Vatnumber:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_vat" name="payment[<?php echo $_code; ?>][vat]">
                    </div>
                </div>
            </li>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_costcenter"><?php echo $_helper->__('Costcenter'); ?></label>
                    <div class="input-box">
                        <input type="text" id="<?php echo $_code; ?>_costcenter" name="payment[<?php echo $_code; ?>][costcenter]">
                    </div>
                </div>
            </li> 
        <?php endif; ?>
        <button type="button" class="button" onclick="payment.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>
        <?php if (!$this->isAdvisoryprocess() && $this->country != 'dede'): ?>
        <li class="accept-afterpay">
            <input type="checkbox" class="required-entry" id="<?php echo $_code; ?>_termsAndConditions" name="payment[<?php echo $_code; ?>][conditions]"  style="float:left;">
            <label for="<?php echo $_code; ?>_termsAndConditions" class="required" style="padding-left:5px; float:left;">
                <em>*</em>
                <?php echo $_helper->__(
                    'Ik ga akkoord met de %sbetalingsvoorwaarden%s van AfterPay',
                    $this->paymentConditionsUrl,
                    $this->anchorClose
                );?>
            </label>
        </li>
        <?php elseif ($this->isAdvisoryprocess() && $this->country != 'dede'): ?>
        <li class="accept-afterpay">
            <input type="checkbox" class="required-entry" id="<?php echo $_code; ?>_termsAndConditions" name="payment[<?php echo $_code; ?>][conditions]"  style="float:left;">
            <label for="<?php echo $_code; ?>_termsAndConditions" class="required" style="padding-left:5px; float:left;">
                <em>*</em>
                <?php echo $_helper->__(
                    'Ik ga akkoord met de %sbetalingsvoorwaarden%s van Mijnbetaalplan',
                    $this->paymentConditionsUrl,
                    $this->anchorClose
                );?>
            </label>
        </li>
        <?php endif; ?>
    </ul>
</fieldset>
  • need to hide all payment methods? – Abdul Jan 22 '16 at 10:03
  • can share your payment method code & name? – Abdul Jan 22 '16 at 10:12
0

You can create an observer for the event payment_method_is_active.
Something like this:

public function checkPaymentMethodActive($observer)
{
    $methodInstance = $observer->getEvent()->getMethodInstance();
    if ($methodInstance->getCode() == 'your payment method code here') {
        $billingAddress = $this->getEvent()->getQuote()->getBillingAddress();
        if ($billingAddress->getCompany()) {
             $result = $this->getEvent()->getResult();  
             $result->isAvailable = false;
        }
    }
    return $this;
}
| improve this answer | |
  • Thanks, where do I need tho place that code? – JGeer Jan 26 '16 at 8:20
  • you can see here some explanations on how to create an observer: wiki.magento.com/display/m1wiki/… .If that's not enough, you can search the web for a way to create an observer. – Marius Jan 26 '16 at 9:19
0

Replace your code to bellow code:

<?php $this->setBlockData()?>
<?php $_code = $this->getMethodCode(); ?>
<?php $_helper = $this->helper('afterpay');?>
<?php $isEnterprise = (bool) Mage::getConfig()->getModuleConfig("Enterprise_Enterprise")->version;?>
<?php $quote = Mage::getSingleton('checkout/session')->getQuote();?>
<?php $address = $quote->getBillingAddress();?>

<div id="payment-errors" class="validation-advice" style="display:none;"></div>
<?php if($address->getCompany()):?>
<?php else :?>
<fieldset class="form-list">
    <ul id="payment_form_<?php echo $_code; ?>" style="display:none;">
        <li>
            <?php if($this->country == 'dede') : ?>
            <div class="field">
                <label for="<?php echo $_code; ?>_gender" class = "required"><em>*</em><?php echo $_helper->__('Gender:'); ?></label>
                <div class="input-box" id="">
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="M" id="<?php echo $_code?>_gender_m" checked="checked">
                    <label style="float:none" for="<?php echo $_code?>_gender_m"><?php echo $_helper->__('Male'); ?></label>
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="V" id="<?php echo $_code?>_gender_v">
                    <label style="float:none" for="<?php echo $_code?>_gender_v"><?php echo $_helper->__('Female'); ?></label>
                </div>
            </div>
            <?php else: ?>
            <div class="field">
                <label for="<?php echo $_code; ?>_gender" class = "required"><em>*</em><?php echo $_helper->__('Gender:'); ?></label>
                <div class="input-box" id="">
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="M" id="<?php echo $_code?>_gender_m" checked="checked">
                    <label style="float:none" for="<?php echo $_code?>_gender_m"><?php echo $_helper->__('Male'); ?></label>
                    <input type="radio" name="payment[<?php echo $_code; ?>][gender]" value="V" id="<?php echo $_code?>_gender_v">
                    <label style="float:none" for="<?php echo $_code?>_gender_v"><?php echo $_helper->__('Female'); ?></label>
                </div>
            </div>
            <?php endif; ?>
        <?php if ($isEnterprise): ?>
            </li>
            <li>
        <?php endif;?>
        <?php if (!$this->isB2B()): ?>
            <div class="field">
                <?php 
                echo $this->getLayout()->createBlock('afterpay/customer_widget_dob')
                                       ->setFieldIdFormat($_code . ':billing:%s')
                                       ->setFieldNameFormat('payment[' . $_code . '][%s]')
                                       ->setIsRequired(true)
                                       ->setPaymentMethodCode($_code)
                                       ->toHtml() 
                ?>
             </div>
            </li>
            <?php if ($this->showBankaccount()): ?>
            <li> 
                <div class="field">
                    <label for="<?php echo $_code; ?>_bankaccount" class="required"><em>*</em><?php echo $_helper->__('Bank account number:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_bankaccount" name="payment[<?php echo $_code; ?>][bankaccount]" style="">
                    </div>
                </div>
            </li>
            <?php endif; ?>
        <?php endif; ?>
        <?php if ($this->isB2B()): ?>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_companyname" class="required"><em>*</em><?php echo $_helper->__('Company name:'); ?></label>
                    <div class="input-box">
                        <input type="text" value="<?php echo $this->getCompany(); ?>" class="required-entry" id="<?php echo $_code; ?>_companyname" name="payment[<?php echo $_code; ?>][companyname]">
                    </div>
                </div>
                <div class="field">
                    <label for="<?php echo $_code; ?>_department" class=""><?php echo $_helper->__('Department:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "" id="<?php echo $_code; ?>_department" name="payment[<?php echo $_code; ?>][department]">
                    </div>
                </div>
            </li>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_coc" class="required"><em>*</em><?php echo $_helper->__('Coc number:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_coc" name="payment[<?php echo $_code; ?>][coc]">
                    </div>
                </div>
                <div class="field">
                    <label for="<?php echo $_code; ?>_vat" class="required"><em>*</em><?php echo $_helper->__('Vatnumber:'); ?></label>
                    <div class="input-box">
                        <input type="text" class = "required-entry" id="<?php echo $_code; ?>_vat" name="payment[<?php echo $_code; ?>][vat]">
                    </div>
                </div>
            </li>
            <li>
                <div class="field">
                    <label for="<?php echo $_code; ?>_costcenter"><?php echo $_helper->__('Costcenter'); ?></label>
                    <div class="input-box">
                        <input type="text" id="<?php echo $_code; ?>_costcenter" name="payment[<?php echo $_code; ?>][costcenter]">
                    </div>
                </div>
            </li> 
        <?php endif; ?>
        <button type="button" class="button" onclick="payment.save()"><span><span><?php echo $this->__('Continue') ?></span></span></button>
        <?php if (!$this->isAdvisoryprocess() && $this->country != 'dede'): ?>
        <li class="accept-afterpay">
            <input type="checkbox" class="required-entry" id="<?php echo $_code; ?>_termsAndConditions" name="payment[<?php echo $_code; ?>][conditions]"  style="float:left;">
            <label for="<?php echo $_code; ?>_termsAndConditions" class="required" style="padding-left:5px; float:left;">
                <em>*</em>
                <?php echo $_helper->__(
                    'Ik ga akkoord met de %sbetalingsvoorwaarden%s van AfterPay',
                    $this->paymentConditionsUrl,
                    $this->anchorClose
                );?>
            </label>
        </li>
        <?php elseif ($this->isAdvisoryprocess() && $this->country != 'dede'): ?>
        <li class="accept-afterpay">
            <input type="checkbox" class="required-entry" id="<?php echo $_code; ?>_termsAndConditions" name="payment[<?php echo $_code; ?>][conditions]"  style="float:left;">
            <label for="<?php echo $_code; ?>_termsAndConditions" class="required" style="padding-left:5px; float:left;">
                <em>*</em>
                <?php echo $_helper->__(
                    'Ik ga akkoord met de %sbetalingsvoorwaarden%s van Mijnbetaalplan',
                    $this->paymentConditionsUrl,
                    $this->anchorClose
                );?>
            </label>
        </li>
        <?php endif; ?>
    </ul>
</fieldset>
<?php endif;?>
| improve this answer | |
  • Thanks! I tried that code, but that does not work. I use the method with codename portfolio_a. That payment method does have its own template file with <fieldset>. Is there a way to hide all the html inside that template file, when the company adress got value? – JGeer Jan 26 '16 at 8:20
  • can you share your template file code??? – Abdul Jan 27 '16 at 4:43
  • I updated my question, with the right code. The payment code is portfolio_a. – JGeer Jan 28 '16 at 12:30
  • Updated my ans pls check now :) – Abdul Jan 28 '16 at 12:58
  • Thanks! But I made a mistake. In that case the payment method is still displayed, but i can not click on it. So I need the modify the payment/methods.phtml file. My payment code is portfolio_a. How do I need to edit the methods.pthml file? – JGeer Jan 28 '16 at 16:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.