0

I'm using a custom module which already hides a payment method based off the quote grand total and a variable defined in the backend. But I need to also do another check, which will see if the product in the session quote contains a certain attribute and then show/hide the payment method.

This is what the file that determines this currently looks like:

class Pay4Later extends \Magento\Payment\Model\Method\AbstractMethod {

/**
 * Payment code
 *
 * @var string
 */
protected $_code = 'pay4later';

/**
 * Availability option
 *
 * @var bool
 */
protected $_isOffline = true;

protected $_isInitializeNeeded = true;

public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null){
    $required_cart = round(($this->getConfigData('min_loan')/90)*100);
    if($quote && $quote->getBaseGrandTotal() > $required_cart) {
        return true;
    } else { 
        return false; 
    }
}

public function getConfigPaymentAction()
{
    return ($this->getConfigData('order_status') == 'pending_payment')? null : parent::getConfigPaymentAction();
} }

I've tried to dump the $quote variable, but nothing happens.

1 Answer 1

1

You have quote, so you can easily get the product. Try the following way:

if ($quote) {
    foreach ($quote->getAllItems() as $item) {
        $product = $item->getProduct();
        error_log($product->getSku());
    }
}

Note: use your custom attribute instead of sku

1
  • Wow... I feel silly. I've been struggling for ages to dump $quote on the page. Didn't think about using error_log! That worked straight away... thanks a lot.
    – Quagerty
    Commented Jul 18, 2019 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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