woocommerce / woocommerce-gateway-paypal-express-checkout

58 stars 65 forks source link

Avoid fatal error when a line item instance doesn’t have a `get_sku()` method #872

Closed jorgeatorres closed 3 years ago

jorgeatorres commented 3 years ago

Issue: #826


Description

This PR prevents a fatal error that might occur when trying to pay using PayPal Checkout for an order containing line items that are not WC_Product instances or that don't have the get_sku() method available.

The only difference from #856, is that this PR doesn't make any assumptions of what the SKU could or should be.

Steps to test:

  1. Create a product.
  2. Create an order (on the backend) containing said product.
  3. Copy the "Customer payment page" link. Screen Shot 2021-06-01 at 16 55 25
  4. Delete the product created in step 1 and empty the trash.
  5. Use the link from step 2 to pay for the order using PayPal Checkout.
    1. On trunk, you'll see a fatal error:

      Uncaught Error: Call to a member function get_sku() on bool in /wp-content/plugins/woocommerce-gateway-paypal-express-checkout/includes/class-wc-gateway-ppec-client.php:842

    2. On this branch (issue/826) the order is processed correctly.

Changelog entry

Enter a summary of all changes on this Pull Request. This will appear in the changelog if accepted. Prevent fatal error when paying for an order containing products that are not in the catalog.

Closes #826.

jorgeatorres commented 3 years ago

@achyuthajoy: assigning to you as PR reviewer 😼 .