/**
  * Check whether payment method can be used
  *
  * TODO: payment method instance is not supposed to know about quote
  *
  * @param Mage_Sales_Model_Quote|null $quote
  *
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     $checkResult = new StdClass();
     $isActive = (bool) (int) $this->getConfigData('active', $quote ? $quote->getStoreId() : null);
     $checkResult->isAvailable = $isActive;
     $checkResult->isDeniedInConfig = !$isActive;
     // for future use in observers
     Mage::dispatchEvent('payment_method_is_active', array('result' => $checkResult, 'method_instance' => $this, 'quote' => $quote));
     // disable method if it cannot implement recurring profiles management and there are recurring items in quote
     if ($checkResult->isAvailable) {
         $implementsRecurring = $this->canManageRecurringProfiles();
         // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last
         if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) {
             $checkResult->isAvailable = false;
         }
     }
     return $checkResult->isAvailable;
 }
Exemplo n.º 2
0
 /**
  * Check whether payment method is applicable to quote
  * Purposed to allow use in controllers some logic that was implemented in blocks only before
  *
  * @param Mage_Sales_Model_Quote $quote
  * @param int|null $checksBitMask
  * @return bool
  */
 public function isApplicableToQuote($quote, $checksBitMask)
 {
     if ($checksBitMask & self::CHECK_USE_FOR_COUNTRY) {
         if (!$this->canUseForCountry($quote->getBillingAddress()->getCountry())) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_USE_FOR_CURRENCY) {
         if (!$this->canUseForCurrency($quote->getStore()->getBaseCurrencyCode())) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_USE_CHECKOUT) {
         if (!$this->canUseCheckout()) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_USE_FOR_MULTISHIPPING) {
         if (!$this->canUseForMultishipping()) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_USE_INTERNAL) {
         if (!$this->canUseInternal()) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_ORDER_TOTAL_MIN_MAX) {
         $total = $quote->getBaseGrandTotal();
         $minTotal = $this->getConfigData('min_order_total');
         $maxTotal = $this->getConfigData('max_order_total');
         if (!empty($minTotal) && $total < $minTotal || !empty($maxTotal) && $total > $maxTotal) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_RECURRING_PROFILES) {
         if (!$this->canManageRecurringProfiles() && $quote->hasRecurringItems()) {
             return false;
         }
     }
     if ($checksBitMask & self::CHECK_ZERO_TOTAL) {
         $total = $quote->getBaseSubtotal() + $quote->getShippingAddress()->getBaseShippingAmount();
         if ($total < 0.0001 && $this->getCode() != 'free' && !($this->canManageRecurringProfiles() && $quote->hasRecurringItems())) {
             return false;
         }
     }
     return true;
 }
Exemplo n.º 3
0
 /**
  * Check whether payment method can be used
  *
  * TODO: payment method instance is not supposed to know about quote
  *
  * @param Mage_Sales_Model_Quote|null $quote
  *
  * @return bool
  */
 public function isAvailable($quote = null)
 {
     $checkResult = new StdClass();
     $isActive = (bool) (int) $this->getConfigData('active', $quote ? $quote->getStoreId() : null);
     $shippingMethodRaw = $quote->getShippingAddress()->getShippingMethod();
     $product = $this->_getHelper()->getDPDServiceCode($shippingMethodRaw);
     if (!$isActive || !$quote || !$this->_getHelper()->isShippingMethodDpd($shippingMethodRaw) || !in_array($product, explode(',', $this->getConfigData('specificproducto', $quote->getStoreId()))) || is_null($this->getSurchage())) {
         $isActive = false;
     }
     $checkResult->isAvailable = $isActive;
     $checkResult->isDeniedInConfig = !$isActive;
     // for future use in observers
     Mage::dispatchEvent('payment_method_is_active', array('result' => $checkResult, 'method_instance' => $this, 'quote' => $quote));
     // disable method if it cannot implement recurring profiles management and there are recurring items in quote
     if ($checkResult->isAvailable) {
         $implementsRecurring = $this->canManageRecurringProfiles();
         // the $quote->hasRecurringItems() causes big performance impact, thus it has to be called last
         if ($quote && !$implementsRecurring && $quote->hasRecurringItems()) {
             $checkResult->isAvailable = false;
         }
     }
     return $checkResult->isAvailable;
 }