The Best Creative Minds – Zynovo

Magento is our forte!

Zynovo is a full-service digital commerce agency, focused on end-to-end implementations of the most flexible enterprise-class commerce platform to help online merchants fulfill their business and e-commerce goals in a way that is both economical and efficient. We provide strategic planning, design, development and post-launch maintenance.

Mon – Fri: 09:00 am – 06:00 pm
Contact +1 (818) 743-2444
Follow

Payment Error with Custom Options on Magento 2

Payment Error with Custom Options on Magento 2 version before v.2.1.10.

 

When a customer checkout a product with custom option via Authorize.net or PayPal, the customer will have an error “An error occurred on the server. Please try to place the order again.”. When you receive such an error, there are a lot of things it can trigger that kind of issue. However, in our case, we found out that the customer has custom option in the cart and need to fix in Magento core for the issue.

 

Go to vendor/magento/module-catalog/Model/Product.php and look for getOptionById method and replace the codes with below:

 

public function getOptionById($optionId)

{

  $result = null;

  if (is_array($this->getOptions())) {

      /** @var \Magento\Catalog\Model\Product\Option $option */

      foreach ($this->getOptions() as $option) {

          if ($option->getId() == $optionId) {

              $result = $option;

              break;

          }

      }

  }

 

  return $result;

}

Reference: https://github.com/magento/magento2/commit/163efaee2382b1cc2255f2a9d007eb0a362c7569