1

Facing a strange issue when applying patch with composer install (I have added correct patch file path in composer.json).

When running "composer install" it is throwing error "Could not apply patch! Skipping."

But when applying patch using git apply then it is working fine without any error.

Don't know what is the issue. If you have face such issue then please let me know the solution.

My patch file is below:-

Index: It solved error on cart page when admin disabled a product which is inside cart
==========================================================================================
diff --git a/vendor/affirm/magento2/Plugin/RestrictPaymentMethods.php b/vendor/affirm/magento2/Plugin/RestrictPaymentMethods.php
--- a/vendor/affirm/magento2/Plugin/RestrictPaymentMethods.php
+++ b/vendor/affirm/magento2/Plugin/RestrictPaymentMethods.php
@@ -17,21 +17,25 @@
     public function afterGetActiveList(\Magento\Payment\Model\PaymentMethodList $subject, $result)
     {
         $methods = $result;
-
-        $om = \Magento\Framework\App\ObjectManager::getInstance();
-        $checkoutsession = $om->get('Magento\Checkout\Model\Session');
-        $quote = $checkoutsession->getQuote();
+        try {
+            $om = \Magento\Framework\App\ObjectManager::getInstance();
+            $checkoutsession = $om->get('Magento\Checkout\Model\Session');
+            $quote = $checkoutsession->getQuote();

-        $address = $quote->getShippingAddress();
-        foreach ($methods as $k => $method) {
-            foreach ($this->getRules($address) as $rule) {
-                if ($rule->restrict($method)) {
-                    if ($rule->validate($address)) {
-                        unset($methods[$k]);
+            $address = $quote->getShippingAddress();
+            foreach ($methods as $k => $method) {
+                foreach ($this->getRules($address) as $rule) {
+                    if ($rule->restrict($method)) {
+                        if ($rule->validate($address)) {
+                            unset($methods[$k]);
+                        }
                     }
                 }
             }
         }
+        catch (\Exception $e){
+
+        }

         return $methods;

1 Answer 1

1

create patch file:

copy file:

  • cp {current file} {modified file}

after modification in file of modified file check difference:

  • diff {current file} {modified file}

create patch:

  • diff -u {current file} {modified file} > {patch file name .patch}

patch < {patch file name .patch}

if ask for path set file path of ({current file})

Example

vendor/magento/module-customer/Controller/Account/CreatePost.php


cp vendor/magento/module-customer/Controller/Account/CreatePost.php CreatePostModify.php

diff -u vendor/magento/module-customer/Controller/Account/CreatePost.php CreatePostModify.php > m2-hotfixes/create_post_modify_error_log.patch

patch < m2-hotfixes/create_post_modify_error_log.patch

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.