Magento 1.9.3.2 код купона активен удалить наложенный платеж


Я хотел бы удалить cash on delivery способ оплаты, когда активен код купона.

Я создаю TEST50 код купона в Shopping Cart Price Rule для discount 50%.

Когда TEST50 активен cash on delivery удалить на странице оформления заказа. Если TEST50 неактивен, показать cash on delivery.

Author: Ramesh S, 2017-08-22

3 answers

У меня есть решение, перейдите к /app/code/local/Mage/Payment/Model/Method/Cashondelivery.php

После этой строки

public function getInstructions()
{
    return trim($this->getConfigData('instructions'));
}

Добавить новый function

/* code added for cash on delivery hide for when coupon active*/
    public function isAvailable($quote = null)
    {
        if ($quote) 
        {
            $coupon = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
            if($coupon ==true) //or use your coupon code here
            {
                $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();

                if (!in_array($coupon)) {
                    return false;
                }
            }
        }

        return parent::isAvailable($quote);
    }
   /* code added for cash on delivery hide for when coupon active*/
 2
Author: Ramesh S, 2017-08-22 10:15:23

Лучше, чем переопределять класс модели, мы можем использовать Событие и Наблюдателя для этой цели.

Мы можем использовать платеж_метод_ис_активен

public function HideCODforCouponCode($observer) {
    $event           = $observer->getEvent();
    $methodInstance = $event->getMethodInstance();
    $store_id = Mage::app()->getStore()->getStoreId();     
     $result          = $event->getResult();  
    $cashOnDeliveryenable = Mage::getStoreConfig('payment/phoenix_cashondelivery/active' , $store_id);
    $coupon = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();

    if (($methodInstance->getCode()  != 'phoenix_cashondelivery')   || ($cashOnDeliveryenable == 0)) {
        return $this; //if it's not the payment method your a looking for do nothing
    }    

    if ($coupon == "TEST50") && ($methodInstance->getCode()  == 'phoenix_cashondelivery')) {
        $result->isAvailable = false;
    }
}
 2
Author: Rahul, 2017-08-22 10:50:08

Внутри вашего пользовательского модуля config.xml в разделе добавьте следующий код.

<events>
<payment_method_is_active>
              <observers>
                  <paymentfilter_payment_method_is_active>
                      <type>singleton</type>
                      <class>overrides/observer</class>
                      <method>HideCODforCouponCode</method>
                  </paymentfilter_payment_method_is_active>
              </observers>
        </payment_method_is_active>
      </events>

Напишите общую функцию внутри Observer.php вашего пользовательского модуля. Для получения дополнительной информации, пожалуйста, проверьте URL https://stackoverflow.com/questions/11195682/implementing-an-event-observer-in-magento

 2
Author: Rahul, 2017-08-22 11:41:29